terra-draw 1.0.0-beta.4 → 1.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.modern.js +1 -1
- package/dist/terra-draw.modern.js.map +1 -1
- package/dist/terra-draw.module.js +1 -1
- package/dist/terra-draw.module.js.map +1 -1
- package/dist/terra-draw.umd.js +1 -1
- package/dist/terra-draw.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/terra-draw.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var o=i.call(t,"string");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function e(e,i){for(var o=0;o<i.length;o++){var n=i[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,t(n.key),n)}}function i(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),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 o in i)Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t},o.apply(this,arguments)}function n(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function s(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var a=function(t,e){var i=e.x-t.x,o=e.y-t.y;return Math.sqrt(o*o+i*i)},l=function(t){var e=this,i=t.name,o=t.callback,n=t.unregister,r=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=i,this.register=function(){e.registered||(e.registered=!0,r(o))},this.unregister=function(){e.register&&(e.registered=!1,n(o))},this.callback=o},c=/*#__PURE__*/function(){function t(t){this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState="not-dragging",this._currentModeCallbacks=void 0,this._minPixelDragDistance="number"==typeof t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9}var e=t.prototype;return e.getButton=function(t){return-1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"},e.getMapElementXYPosition=function(t){var e=this.getMapEventElement().getBoundingClientRect();return{containerX:t.clientX-e.left,containerY:t.clientY-e.top}},e.getDrawEventFromEvent=function(t){var e=this.getLngLatFromEvent(t);if(!e)return null;var i=e.lng,o=e.lat,n=this.getMapElementXYPosition(t),r=n.containerX,a=n.containerY,l=this.getButton(t),c=Array.from(this._heldKeys);return{lng:s(i,this._coordinatePrecision),lat:s(o,this._coordinatePrecision),containerX:r,containerY:a,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 l({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 l({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var i=t.getDrawEventFromEvent(e);if(i)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(i),t._lastDrawEvent=i;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var o={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},n={x:i.containerX,y:i.containerY},r=t._currentModeCallbacks.getState(),s=a(o,n);if("drawing"===r?s<t._minPixelDragDistanceDrawing:"selecting"===r?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;t._dragState="dragging",t._currentModeCallbacks.onDragStart(i,function(e){t.setDraggability.bind(t)(e)})}else"dragging"===t._dragState&&t._currentModeCallbacks.onDrag(i,function(e){t.setDraggability.bind(t)(e)})}},register:function(e){t.getMapEventElement().addEventListener("pointermove",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointermove",e)}}),new l({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 l({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 l({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 l({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}n(e,t);var o=e.prototype;return o.circlePath=function(t,e,i){var o=2*i;return"M "+t+" "+e+" m -"+i+", 0 a "+i+","+i+" 0 1,0 "+o+",0 a "+i+","+i+" 0 1,0 -"+o+",0"},o.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)})},o.unregister=function(){var e,i,o;t.prototype.unregister.call(this),null==(e=this._clickEventListener)||e.remove(),null==(i=this._mouseMoveEventListener)||i.remove(),null==(o=this._overlay)||o.setMap(null),this._overlay=void 0},o.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(),o=e.getSouthWest(),n=new this._lib.LatLngBounds(o,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&&n.contains(d)?{lng:d.lng(),lat:d.lat()}:null},o.getMapEventElement=function(){return this._map.getDiv().querySelector('div[style*="z-index: 3;"]')},o.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 o=i.fromLatLngToContainerPixel(new this._lib.LatLng(e,t));if(null===o)throw new Error("cannot project coordinates");return{x:o.x,y:o.y}},o.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 o=i.fromContainerPixelToLatLng(new this._lib.Point(t,e));if(null===o)throw new Error("cannot unproject coordinates");return{lng:o.lng(),lat:o.lat()}},o.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 o=document.createElement("style");o.innerHTML=".terra-draw-google-maps { cursor: "+t+" !important; }",document.getElementsByTagName("head")[0].appendChild(o),this._cursorStyleSheet=o}}this._cursor=t}},o.setDoubleClickToZoom=function(t){this._map.setOptions(t?{disableDoubleClickZoom:!1}:{disableDoubleClickZoom:!0})},o.setDraggability=function(t){this._map.setOptions({draggable:t})},o.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 o=t.geometry.coordinates;e.setGeometry(new i._lib.Data.Point(new i._lib.LatLng(o[1],o[0])));break;case"LineString":for(var n=t.geometry.coordinates,r=[],s=0;s<n.length;s++){var a=n[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=[],g=0;g<c[u].length;g++){var p=new i._lib.LatLng(c[u][g][1],c[u][g][0]);h.push(p)}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 o={type:"FeatureCollection",features:[].concat(t.created)};this._map.data.addGeoJson(o),this._map.data.setStyle(function(t){var o=t.getProperty("mode"),n=t.getGeometry();if(!n)throw new Error("Google Maps geometry not found");var r=n.getType(),s={};t.forEachProperty(function(t,e){s[e]=t});var a=e[o]({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")})},o.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)},o.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())},o.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i(e,[{key:"_layers",get:function(){var t;return Boolean((null==(t=this.renderedFeatureIds)?void 0:t.size)>0)}}]),e}(c),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}n(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,o){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 n=(0,t[i.properties.mode])(i),r=String(n.zIndex);return e._panes[r]||(e._panes[r]=e.createPaneStyleSheet(r,n.zIndex)),e._lib.circleMarker(o,{radius:n.pointWidth,stroke:n.pointOutlineWidth||!1,color:n.pointOutlineColor,weight:n.pointOutlineWidth,fillOpacity:.8,fillColor:n.pointColor,pane:r,interactive:!1})},style:function(i){if(!i||!i.properties)return{};var o=i,n=(0,t[o.properties.mode])(o),r=String(n.zIndex);return e._panes[r]||(e._panes[r]=e.createPaneStyleSheet(r,n.zIndex)),"LineString"===o.geometry.type?{interactive:!1,color:n.lineStringColor,weight:n.lineStringWidth,pane:r}:"Polygon"===o.geometry.type?{interactive:!1,fillOpacity:n.polygonFillOpacity,fillColor:n.polygonFillColor,weight:n.polygonOutlineWidth,stroke:!0,color:n.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){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}(c),h=/*#__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}n(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 o=[].concat(t.created,t.updated,t.unchanged),n=[],r=[],s=[],a=0;a<o.length;a++){var l=o[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,n.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,g=h||i.changedIds.linestrings,p=h||i.changedIds.polygons;(h||i.changedIds.points)&&(u=i._setGeoJSONLayerData("Point",n)),g&&i._setGeoJSONLayerData("LineString",r),p&&i._setGeoJSONLayerData("Polygon",s),u&&i._map.moveLayer(u)}else{var f=i._addGeoJSONLayer("Point",n);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){t.prototype.register.call(this,e),this._currentModeCallbacks&&this._currentModeCallbacks.onReady&&this._currentModeCallbacks.onReady()},e}(c),g=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mapboxglAdapter=void 0,i.mapboxglAdapter=new h(e),i}n(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}(c);const p={radians:6370997/(2*Math.PI),degrees:2*Math.PI*6370997/360,ft:.3048,m:1,"us-ft":1200/3937};var f=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_||p[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 y=6378137,v=Math.PI*y,m=[-v,-v,v,v],C=[-180,-85,180,85],P=y*Math.log(Math.tan(Math.PI/2));class _ extends f{constructor(t){super({code:t,units:"m",extent:m,global:!0,worldExtent:C,getPointResolution:function(t,e){return t/Math.cosh(e[1]/y)}})}}const x=[new _("EPSG:3857"),new _("EPSG:102100"),new _("EPSG:102113"),new _("EPSG:900913"),new _("http://www.opengis.net/def/crs/EPSG/0/3857"),new _("http://www.opengis.net/gml/srs/epsg.xml#3857")],M=[-180,-90,180,90],S=6378137*Math.PI/180;class b extends f{constructor(t,e){super({code:t,units:"degrees",extent:M,axisOrientation:e,global:!0,metersPerUnit:S,worldExtent:M})}}const w=[new b("CRS:84"),new b("EPSG:4326","neu"),new b("urn:ogc:def:crs:OGC:1.3:CRS84"),new b("urn:ogc:def:crs:OGC:2:84"),new b("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),new b("http://www.opengis.net/gml/srs/epsg.xml#4326","neu"),new b("http://www.opengis.net/def/crs/EPSG/0/4326","neu")];let E={},I={};function D(t,e,i){const o=t.getCode(),n=e.getCode();o in I||(I[o]={}),I[o][n]=i}function F(t,e){if(void 0!==e)for(let i=0,o=t.length;i<o;++i)e[i]=t[i];else e=t.slice();return e}function k(t,e){if(void 0!==e&&t!==e){for(let i=0,o=t.length;i<o;++i)e[i]=t[i];t=e}return t}function O(t){!function(t,e){E[t]=e}(t.getCode(),t),D(t,t,F)}function j(t){return"string"==typeof t?E[e=t]||E[e.replace(/urn:(x-)?ogc:def:crs:EPSG:(.*:)?(\w+)$/,"EPSG:$3")]||null:t||null;var e}function L(t){!function(t){t.forEach(O)}(t),t.forEach(function(e){t.forEach(function(t){e!==t&&D(e,t,F)})})}function W(t,e,i){const o=function(t,e){return function(t,e){let i=function(t,e){let i;return t in I&&e in I[t]&&(i=I[t][e]),i}(t.getCode(),e.getCode());return i||(i=k),i}(j(t),j(e))}(e,i);return o(t,void 0,t.length)}var B,G,N;L(x),L(w),B=x,G=function(t,e,i){const o=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(o));for(let n=0;n<o;n+=i){e[n]=v*t[n]/180;let i=y*Math.log(Math.tan(Math.PI*(+t[n+1]+90)/360));i>P?i=P:i<-P&&(i=-P),e[n+1]=i}return e},N=function(t,e,i){const o=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(o));for(let n=0;n<o;n+=i)e[n]=180*t[n]/v,e[n+1]=360*Math.atan(Math.exp(t[n+1]/y))/Math.PI-90;return e},w.forEach(function(t){B.forEach(function(e){D(t,e,G),D(e,t,N)})});var V,A=/*#__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=void 0,i._vectorSource=void 0,i._geoJSONReader=void 0,i._map=e.map,i._lib=e.lib,i._geoJSONReader=new i._lib.GeoJSON,i._projection=function(){var t;return null!=(t=i._lib.getUserProjection())?t:new f({code:"EPSG:3857"})},i._container=i._map.getViewport(),i._container.setAttribute("tabindex","0");var o=new i._lib.VectorSource({features:[]});i._vectorSource=o;var n=new i._lib.VectorLayer({source:o,style:function(t){return i.getStyles(t,i.stylingFunction())}});return i._map.addLayer(n),i}n(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,o=t.getGeometry();if(o)return{Point:function(t){var o=t.getProperties(),n=e[o.mode]({type:"Feature",geometry:{type:"Point",coordinates:[]},properties:o});return new i._lib.Style({image:new i._lib.Circle({radius:n.pointWidth,fill:new i._lib.Fill({color:n.pointColor}),stroke:new i._lib.Stroke({color:n.pointOutlineColor,width:n.pointOutlineWidth})})})},LineString:function(t){var o=t.getProperties(),n=e[o.mode]({type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:o});return new i._lib.Style({stroke:new i._lib.Stroke({color:n.lineStringColor,width:n.lineStringWidth})})},Polygon:function(t){var o=t.getProperties(),n=e[o.mode]({type:"Feature",geometry:{type:"Polygon",coordinates:[]},properties:o}),r=i.hexToRGB(n.polygonFillColor),s=r.r,a=r.g,l=r.b;return new i._lib.Style({stroke:new i._lib.Stroke({color:n.polygonOutlineColor,width:n.polygonOutlineWidth}),fill:new i._lib.Fill({color:"rgba("+s+","+a+","+l+","+n.polygonFillOpacity+")"})})}}[o.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.getLngLatFromEvent=function(t){var e=this.getMapElementXYPosition(t),i=e.containerX,o=e.containerY;try{return this.unproject(i,o)}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,o=this._map.getPixelFromCoordinate(W([t,e],"EPSG:4326",void 0!==(i=this._projection())?i:"EPSG:3857"));return{x:o[0],y:o[1]}},i.unproject=function(t,e){var i=function(t,e){const i=W(t,void 0!==e?e:"EPSG:3857","EPSG:4326"),o=i[0];return(o<-180||o>180)&&(i[0]=function(t,e){const i=t%360;return 360*i<0?i+360:i}(o+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){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}(c),T=/*#__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}n(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}),o=this._mapView.toScreen(i);return{x:o.x,y:o.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,o=t.geometry,n=o.coordinates,r=o.type,s=e[t.properties.mode](t),a=void 0,l=void 0;switch(r){case"Point":l=new this._lib.Point({latitude:n[1],longitude:n[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:[n]}),a=new this._lib.SimpleLineSymbol({color:this.getColorFromHex(s.lineStringColor),width:s.lineStringWidth+"px"});break;case"Polygon":l=new this._lib.Polygon({rings:n}),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}(c);!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(V||(V={}));var R,U="selected",X="midPoint",z="closingPoint";function Y(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function K(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"}(R||(R={}));var H=/*#__PURE__*/function(){var t=e.prototype;function e(t){this._state=void 0,this._styles=void 0,this.behaviors=[],this.validate=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.onStyleChange=void 0,this.store=void 0,this.setDoubleClickToZoom=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.projection=void 0,this.type=R.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){if("unregistered"===this._state)throw new Error("Mode must be registered");var e=function(t,e){var i;if(Y(t))if(null==t.id)i="Feature has no id";else if("string"!=typeof t.id&&"number"!=typeof t.id)i="Feature must be string or number as per GeoJSON spec";else if(e(t.id))if(Y(t.geometry))if(Y(t.properties))if("string"==typeof t.geometry.type&&["Polygon","LineString","Point"].includes(t.geometry.type))if(Array.isArray(t.geometry.coordinates)){if(!t.properties.mode||"string"!=typeof t.properties.mode)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:V.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},i(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}(),J=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,o=new Array(i),n=0;n<i;n++)o[n]=arguments[n];return(e=t.call.apply(t,[this].concat(o))||this).type=R.Select,e}return n(e,t),e}(H);function Z(t,e){var i=function(t){return t*Math.PI/180},o=i(t[1]),n=i(t[0]),r=i(e[1]),s=r-o,a=i(e[0])-n,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(o)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}var q=6371008.8;function $(t){return t%360*Math.PI/180}function Q(t){return t/(q/1e3)}function tt(t){return t%(2*Math.PI)*180/Math.PI}var et=57.29577951308232,it=.017453292519943295,ot=6378137,nt=function(t,e){return{x:0===t?0:t*it*ot,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*it/2))*ot}},rt=function(t,e){return{lng:0===t?0:et*(t/ot),lat:0===e?0:(2*Math.atan(Math.exp(e/ot))-Math.PI/2)*et}};function st(t,e,i){var o=$(t[0]),n=$(t[1]),r=$(i),s=Q(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[tt(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),tt(a)]}function at(t){for(var e=t.center,i=t.radiusKilometers,o=t.coordinatePrecision,n=t.steps?t.steps:64,r=[],a=0;a<n;a++){var l=st(e,i,-360*a/n);r.push([s(l[0],o),s(l[1],o)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function lt(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 o=[],n=0;n<e.length;n++)for(var r=0;r<e[n].length-1;r++)for(var s=0;s<e.length;s++)for(var a=0;a<e[s].length-1;a++)c(n,r,s,a);return o.length>0;function l(t){return t<0-i.epsilon||t>1+i.epsilon}function c(t,i,n,r){var s,a=e[t][i],c=e[t][i+1],d=e[n][r],u=e[n][r+1],h=function(t,e,i,o){if(ct(t,i)||ct(t,o)||ct(e,i)||ct(o,i))return null;var n=t[0],r=t[1],s=e[0],a=e[1],l=i[0],c=i[1],d=o[0],u=o[1],h=(n-s)*(c-u)-(r-a)*(l-d);return 0===h?null:[((n*a-r*s)*(l-d)-(n-s)*(l*u-c*d))/h,((n*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(),o.push(h)))}}function ct(t,e){return t[0]===e[0]&&t[1]===e[1]}function dt(t,e){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(o=t[0])>=-180&&o<=180&&(i=t[1])>=-90&&i<=90&&ut(t[0])<=e&&ut(t[1])<=e;var i,o}function ut(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}function ht(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 dt(t,e)})&&(i=t.geometry.coordinates[0][0])[0]===(o=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]&&i[1]===o[1];var i,o}function gt(t,e){return ht(t,e)&&!lt(t)}var pt=/*#__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 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}n(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:V.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=at({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=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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&>(e,this.coordinatePrecision)},i.updateCircle=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e,i=Z(this.center,[t.lng,t.lat]);if("web-mercator"===this.projection){var o=function(t,e){var i=1e3*Z(t,e);if(0===i)return 1;var o=nt(t[0],t[1]),n=o.x,r=o.y,s=nt(e[0],e[1]),a=s.y;return Math.sqrt(Math.pow(s.x-n,2)+Math.pow(a-r,2))/i}(this.center,[t.lng,t.lat]);e=function(t){for(var e=t.center,i=t.coordinatePrecision,o=t.steps?t.steps:64,n=1e3*t.radiusKilometers,r=nt(e[0],e[1]),a=r.x,l=r.y,c=[],d=0;d<o;d++){var u=360*d/o*Math.PI/180,h=n*Math.cos(u),g=n*Math.sin(u),p=rt(a+h,l+g),f=p.lat;c.push([s(p.lng,i),s(f,i)])}return c.push(c[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[c]},properties:{}}}({center:this.center,radiusKilometers:i*o,coordinatePrecision:this.coordinatePrecision})}else{if("globe"!==this.projection)throw new Error("Invalid projection");e=at({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:V.Provisional}))return;this.store.updateGeometry([{id:this.currentCircleId,geometry:e.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:i}])}},e}(H),ft=/*#__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?o({},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 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}n(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:V.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],o=this.project(i[0],i[1]),n=a({x:o.x,y:o.y},{x:t.containerX,y:t.containerY}),r=e.coordinates[0][0],s=this.project(r[0],r[1]);if(a({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(!(n<this.minDistance)){e.coordinates[0].pop();var l={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:l,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:V.Provisional}))return;this.store.updateGeometry([{id:this.currentId,geometry:l}])}}},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=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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ht(e,this.coordinatePrecision)},e}(H),yt=function(t){var e=t.store,i=t.mode,o=t.project,n=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision,a=t.projection;this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.store=e,this.mode=i,this.project=o,this.unproject=n,this.pointerDistance=r,this.coordinatePrecision=s,this.projection=a};function vt(t){var e=t.unproject,i=t.point,o=t.pointerDistance/2,n=i.x,r=i.y;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[e(n-o,r-o),e(n+o,r-o),e(n+o,r+o),e(n-o,r+o),e(n-o,r-o)].map(function(t){return[t.lng,t.lat]})]}}}var mt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.create=function(t){return vt({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(yt),Ct=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.measure=function(t,e){var i=this.project(e[0],e[1]);return a({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(yt),Pt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n.clickBoundingBox=void 0,n.getSnappableCoordinateFirstClick=function(t){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode)})},n.getSnappableCoordinate=function(t,e){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode&&t.id!==e)})},n.config=e,n.pixelDistance=i,n.clickBoundingBox=o,n}return n(e,t),e.prototype.getSnappable=function(t,e){var i=this,o=this.clickBoundingBox.create(t),n=this.store.search(o,e),r={coord:void 0,minDist:Infinity};return n.forEach(function(e){var o;if("Polygon"===e.geometry.type)o=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;o=e.geometry.coordinates}o.forEach(function(e){var o=i.pixelDistance.measure(t,e);o<r.minDist&&o<i.pointerDistance&&(r.coord=e,r.minDist=o)})}),r.coord},e}(yt);function _t(t,e,i){var o=$(t[0]),n=$(t[1]),r=$(i),s=Q(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[tt(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),tt(a)]}function xt(t,e,i){var o=t.x,n=t.y,r=$(i);return{x:o+e*Math.cos(r),y:n+e*Math.sin(r)}}function Mt(t,e){var i=$(t[0]),o=$(e[0]),n=$(t[1]),r=$(e[1]),s=Math.sin(o-i)*Math.cos(r),a=Math.cos(n)*Math.sin(r)-Math.sin(n)*Math.cos(r)*Math.cos(o-i);return tt(Math.atan2(s,a))}function St(t,e){var i=Math.atan2(e.y-t.y,e.x-t.x);return(i*=180/Math.PI)>180?i-=360:i<-180&&(i+=360),i}function bt(t){return(t+360)%360}function wt(t,e,i){for(var o,n,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(!(o=e-l))return s.push(t[c]),s;n=Mt(t[c],t[c-1])-180,r=_t(t[c],o,n),s.push(r)}if(l>=i)return(o=i-l)?(n=Mt(t[c],t[c-1])-180,r=_t(t[c],o,n),s.push(r),s):(s.push(t[c]),s);if(l>=e&&s.push(t[c]),c===t.length-1)return s;l+=Z(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 Et(t){return t*(Math.PI/180)}function It(t){return t*(180/Math.PI)}var Dt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.config=e,i}n(e,t);var i=e.prototype;return i.generateInsertionCoordinates=function(t,e,i){for(var o=[t,e],n=0,r=0;r<o.length-1;r++)n+=Z(o[0],o[1]);if(n<=i)return o;var s=n/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);for(var a=[],l=0;l<s;l++){var c=wt(o,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 o=Z(t,e),n=function(t,e,i){var o=[],n=Et(t[1]),r=Et(t[0]),s=Et(e[1]),a=Et(e[0]);i+=1;var l=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-n)/2),2)+Math.cos(n)*Math.cos(s)*Math.pow(Math.sin((a-r)/2),2)));if(0===l||isNaN(l))return o;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),g=u*Math.cos(n)*Math.cos(r)+h*Math.cos(s)*Math.cos(a),p=u*Math.cos(n)*Math.sin(r)+h*Math.cos(s)*Math.sin(a),f=u*Math.sin(n)+h*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)||o.push([It(v),It(y)])}}return o.slice(1,-1)}(t,e,Math.floor(o/i));return this.limitCoordinates(n)},i.limitCoordinates=function(t){var e=this;return t.map(function(t){return[s(t[0],e.config.coordinatePrecision),s(t[1],e.config.coordinatePrecision)]})},e}(yt);function Ft(t,e){return t[0]===e[0]&&t[1]===e[1]}var kt=/*#__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?o({},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 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}n(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,V.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 o={type:"LineString",coordinates:t};if(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}))return;var n=[{id:this.currentId,geometry:o}];this.closingPointId&&e&&n.push({id:this.closingPointId,geometry:{type:"Point",coordinates:e}}),"commit"===i&&(this.lastCommitedCoordinates=o.coordinates),this.store.updateGeometry(n)}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommitedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=Z(t,e)/(this.insertCoordinates.value+1),o=[];return"globe"===this.projection?o=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(o=this.insertPoint.generateInsertionCoordinates(t,e,i)),o},i.createLine=function(t){var e=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:{mode:this.mode}}])[0];this.lastCommitedCoordinates=[t,t],this.currentId=e,this.currentCoordinate++,this.setDrawing()},i.firstUpdateToLine=function(t){if(this.currentId){var e=this.store.getGeometryCopy(this.currentId).coordinates,i=this.store.create([{geometry:{type:"Point",coordinates:[].concat(t)},properties:{mode:this.mode}}]);this.closingPointId=i[0],this.setCursor(this.cursors.close);var o=[].concat(e,[t]);this.updateGeometries(o,void 0,V.Commit),this.currentCoordinate++}},i.updateToLine=function(t,e){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,o=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:i[i.length-2],n=this.project(o[0],o[1]);if(a({x:n.x,y:n.y},{x:e.x,y:e.y})<this.pointerDistance)this.close();else{this.setCursor(this.cursors.close);var r=[].concat(i,[t]);this.updateGeometries(r,i[i.length-1],V.Commit),this.currentCoordinate++}}},i.registerBehaviors=function(t){this.snapping=new Pt(t,new Ct(t),new mt(t)),this.insertPoint=new Dt(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 o=e[e.length-1],n=this.project(o[0],o[1]);a({x:n.x,y:n.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}var r=[].concat(e,[i]);if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){var s=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],l=i;if(!Ft(s,l)){var c=this.generateInsertCoordinates(s,l);r=[].concat(this.lastCommitedCoordinates.slice(0,-1),c,[i])}}this.updateGeometries(r,void 0,V.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,e=this.closingPointId;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!==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&&"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}(H);function Ot(t,e){return"Point"===t.geometry.type&&dt(t.geometry.coordinates,e)}var jt=/*#__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}n(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:V.Finish})){var o=this.store.create([{geometry:e,properties:i}]);this.onFinish(o[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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&Ot(e,this.coordinatePrecision)},e}(H),Lt=/*#__PURE__*/function(t){function e(e,i){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o._startEndPoints=[],o.config=e,o.pixelDistance=i,o}n(e,t);var o=e.prototype;return o.create=function(t,e){var i,o;if(this.ids.length)throw new Error("Opening and closing points already created");if(t.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:(i={mode:e},i[z]=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(o={mode:e},o[z]=!0,o)}])},o.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])},o.update=function(t){if(2!==this.ids.length)throw new Error("No closing points to update");this.store.updateGeometry([{id:this.ids[0],geometry:{type:"Point",coordinates:t[0]}},{id:this.ids[1],geometry:{type:"Point",coordinates:t[t.length-3]}}])},o.isClosingPoint=function(t){var e=this.store.getGeometryCopy(this.ids[0]),i=this.store.getGeometryCopy(this.ids[1]),o=this.pixelDistance.measure(t,e.coordinates),n=this.pixelDistance.measure(t,i.coordinates);return{isClosing:o<this.pointerDistance,isPreviousClosing:n<this.pointerDistance}},i(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}]),e}(yt),Wt=/*#__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?o({},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 r={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?o({},r,e.keyEvents):r}return i}n(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]]),V.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 Ct(t),this.snapping=new Pt(t,this.pixelDistance,new mt(t)),this.closingPoints=new Lt(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,o=this.store.getGeometryCopy(this.currentId).coordinates[0];if(i&&(t.lng=i[0],t.lat=i[1]),1===this.currentCoordinate){var n=1/Math.pow(10,this.coordinatePrecision-1),r=Math.max(1e-6,n);e=[o[0],[t.lng,t.lat],[t.lng,t.lat-r],o[0]]}else if(2===this.currentCoordinate)e=[o[0],o[1],[t.lng,t.lat],o[0]];else{var s=this.closingPoints.isClosingPoint(t);s.isPreviousClosing||s.isClosing?(this.setCursor(this.cursors.close),e=[].concat(o.slice(0,-2),[o[0],o[0]])):e=[].concat(o.slice(0,-2),[[t.lng,t.lat],o[0]])}this.updatePolygonGeometry(e,V.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 o=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;o&&(t.lng=o[0],t.lat=o[1]);var n=this.store.getGeometryCopy(this.currentId);if(Ft([t.lng,t.lat],n.coordinates[0][0]))return;if(!this.updatePolygonGeometry([n.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],n.coordinates[0][0]],V.Commit))return;this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){var r=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;r&&(t.lng=r[0],t.lat=r[1]);var s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(Ft([t.lng,t.lat],s[1]))return;if(!this.updatePolygonGeometry([s[0],s[1],[t.lng,t.lat],[t.lng,t.lat],s[0]],V.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]),Ft([t.lng,t.lat],l[this.currentCoordinate-1]))return;var d=(void 0===(u=[[].concat(l.slice(0,-1),[[t.lng,t.lat],l[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],V.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;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=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)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&&ht(e,this.coordinatePrecision)},e}(H),Bt=/*#__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}n(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],o={type:"Polygon",coordinates:[[i,[t.lng,i[1]],[t.lng,t.lat],[i[0],t.lat],i]]};if(this.validate&&!this.validate({id:this.currentRectangleId,geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}))return;this.store.updateGeometry([{id:this.currentRectangleId,geometry:o}])}},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,V.Finish),this.close()},i.onMouseMove=function(t){this.updateRectangle(t,V.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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&>(e,this.coordinatePrecision)},e}(H),Gt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,{styles:e.styles})||this).type=R.Render,i.mode="render",i.mode=e.modeName,i}n(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)&&(Ot(e,this.coordinatePrecision)||ht(e,this.coordinatePrecision)||function(t,e){return"LineString"===t.geometry.type&&t.geometry.coordinates.length>=2&&t.geometry.coordinates.every(function(t){return dt(t,e)})}(e,this.coordinatePrecision))},e}(H);function Nt(t,e){var i=t,o=e,n=$(i[1]),r=$(o[1]),s=$(o[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),l=(tt(Math.atan2(s,a))+360)%360;return l>180?-(360-l):l}function Vt(t,e,i){var o=e;e<0&&(o=-Math.abs(o));var n=o/q,r=t[0]*Math.PI/180,s=$(t[1]),a=$(i),l=n*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+n*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 At(t,e,i,o,n){var r=o(t[0],t[1]),a=o(e[0],e[1]),l=n((r.x+a.x)/2,(r.y+a.y)/2),c=l.lat;return[s(l.lng,i),s(c,i)]}function Tt(t,e,i){var o=Vt(t,1e3*Z(t,e)/2,Nt(t,e));return[s(o[0],i),s(o[1],i)]}function Rt(t){for(var e=t.featureCoords,i=t.precision,o=t.unproject,n=t.project,r=t.projection,s=[],a=0;a<e.length-1;a++){var l=void 0;if("web-mercator"===r)l=At(e[a],e[a+1],i,n,o);else{if("globe"!==r)throw new Error("Invalid projection");l=Tt(e[a],e[a+1],i)}s.push(l)}return s}var Ut=/*#__PURE__*/function(t){function e(e,i){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPointBehavior=void 0,o._midPoints=[],o.config=e,o.selectionPointBehavior=i,o}n(e,t);var o=e.prototype;return o.insert=function(t,e){var i=this.store.getGeometryCopy(t),o=this.store.getPropertiesCopy(t),n=o.midPointFeatureId,r=o.midPointSegment,s=this.store.getGeometryCopy(n),a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.splice(r+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[a]:a,this.store.updateGeometry([{id:n,geometry:s}]),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(a,n,e),this.selectionPointBehavior.create(a,s.type,n)},o.create=function(t,e,i){var o=this;if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i,o,n,r){return Rt({featureCoords:t,precision:i,project:o,unproject:n,projection:r}).map(function(t,i){return{geometry:{type:"Point",coordinates:t},properties:e(i)}})}(t,function(t){var i;return(i={mode:o.mode})[X]=!0,i.midPointSegment=t,i.midPointFeatureId=e,i},i,this.config.project,this.config.unproject,this.projection))},o.delete=function(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])},o.getUpdated=function(t){var e=this;if(0!==this._midPoints.length)return Rt({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}}})},i(e,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}]),e}(yt),Xt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._selectionPoints=[],i}n(e,t);var o=e.prototype;return o.create=function(t,e,i){var o=this;this._selectionPoints=this.store.create(function(t,e,i){for(var o=[],n="Polygon"===e?t.length-1:t.length,r=0;r<n;r++)o.push({geometry:{type:"Point",coordinates:t[r]},properties:i(r)});return o}(t,e,function(t){return{mode:o.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t}}))},o.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._selectionPoints=[])},o.getUpdated=function(t){if(0!==this._selectionPoints.length)return this._selectionPoints.map(function(e,i){return{id:e,geometry:{type:"Point",coordinates:t[i]}}})},o.getOneUpdated=function(t,e){if(void 0!==this._selectionPoints[t])return{id:this._selectionPoints[t],geometry:{type:"Point",coordinates:e}}},i(e,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}]),e}(yt);function zt(t,e){for(var i,o,n,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++)(o=l[c])[1]>(i=t)[1]!=(n=l[u])[1]>i[1]&&i[0]<(n[0]-o[0])*(i[1]-o[1])/(n[1]-o[1])+o[0]&&(r=!r);return r}var Yt=function(t,e,i){var o=function(t){return t*t},n=function(t,e){return o(t.x-e.x)+o(t.y-e.y)};return Math.sqrt(function(t,e,i){var o=n(e,i);if(0===o)return n(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/o;return r=Math.max(0,Math.min(1,r)),n(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},Kt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.createClickBoundingBox=void 0,n.pixelDistance=void 0,n.config=e,n.createClickBoundingBox=i,n.pixelDistance=o,n}return n(e,t),e.prototype.find=function(t,e){for(var i=void 0,o=Infinity,n=void 0,r=Infinity,s=void 0,a=Infinity,l=void 0,c=this.createClickBoundingBox.create(t),d=this.store.search(c),u=0;u<d.length;u++){var h=d[u],g=h.geometry;if("Point"===g.type){if(h.properties.selectionPoint||!e&&h.properties[X])continue;var p=this.pixelDistance.measure(t,g.coordinates);h.properties[X]&&p<this.pointerDistance&&p<a?(a=p,s=h):!h.properties[X]&&p<this.pointerDistance&&p<o&&(o=p,i=h)}else if("LineString"===g.type){if(i)continue;for(var f=0;f<g.coordinates.length-1;f++){var y=g.coordinates[f],v=g.coordinates[f+1],m=Yt({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,n=h)}}else if("Polygon"===g.type){if(i||n)continue;zt([t.lng,t.lat],g.coordinates)&&(l=h)}}return{clickedFeature:i||n||l,clickedMidPoint:s}},e}(yt),Ht=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.featuresAtMouseEvent=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedFeatureId=null,r.dragPosition=void 0,r.config=e,r.featuresAtMouseEvent=i,r.selectionPoints=o,r.midPoints=n,r}n(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),o=[t.lng,t.lat];if("Polygon"===i.type||"LineString"===i.type){var n,r;if(r="Polygon"===i.type?(n=i.coordinates[0]).length-1:(n=i.coordinates).length,!this.dragPosition)return!1;for(var a=0;a<r;a++){var l=n[a],c=[this.dragPosition[0]-o[0],this.dragPosition[1]-o[1]],d=s(l[0]-c[0],this.config.coordinatePrecision),u=s(l[1]-c[1],this.config.coordinatePrecision);if(d>180||d<-180||u>90||u<-90)return!1;n[a]=[d,u]}"Polygon"===i.type&&(n[n.length-1]=[n[0][0],n[0][1]]);var h=this.selectionPoints.getUpdated(n)||[],g=this.midPoints.getUpdated(n)||[];if(e&&!e({type:"Feature",id:this.draggedFeatureId,geometry:i,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:V.Provisional}))return!1;this.store.updateGeometry([{id:this.draggedFeatureId,geometry:i}].concat(h,g)),this.dragPosition=[t.lng,t.lat]}else"Point"===i.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:"Point",coordinates:o}}]),this.dragPosition=[t.lng,t.lat])}},e}(yt),Jt=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedCoordinate={id:null,index:-1},r.config=e,r.pixelDistance=i,r.selectionPoints=o,r.midPoints=n,r}n(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(var n=0;n<i.length;n++){var r=this.pixelDistance.measure(t,i[n]);if(r<this.pointerDistance&&r<o.dist){var s="Polygon"===e.type&&(n===i.length-1||0===n);o.dist=r,o.index=s?0:n,o.isFirstOrLastPolygonCoord=s}}return o},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var o=this.draggedCoordinate.index,n=this.store.getGeometryCopy(this.draggedCoordinate.id),r="LineString"===n.type?n.coordinates:n.coordinates[0],s=[t.lng,t.lat];if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if("Polygon"!==n.type||o!==r.length-1&&0!==o)r[o]=s;else{var a=r.length-1;r[0]=s,r[a]=s}var l=this.selectionPoints.getOneUpdated(o,s),c=l?[l]:[],d=this.midPoints.getUpdated(r)||[];return!("Point"!==n.type&&!e&<({type:"Feature",geometry:n,properties:{}})||i&&!i({type:"Feature",id:this.draggedCoordinate.id,geometry:n,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:V.Provisional})||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:n}].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}(yt);function Zt(t){var e=0,i=0,o=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],o++},!0),[e/o,i/o]}function qt(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=q,o=e[1]*Math.PI/180,n=t[1]*Math.PI/180,r=n-o,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),l=Math.abs(a)>1e-11?r/a:Math.cos(o);return Math.sqrt(r*r+l*l*s*s)*i}function $t(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=nt(t[0],t[1]);return[e.x,e.y]});return"Polygon"===t.geometry.type?function(t){for(var e=0,i=0,o=0,n=t.length,r=0;r<n-1;r++){var s=t[r],a=s[0],l=s[1],c=t[r+1],d=c[0],u=c[1],h=a*u-d*l;e+=h,i+=(a+d)*h,o+=(l+u)*h}return{x:i/=6*(e/=2),y:o/=6*e}}(e):function(t){for(var e=t.length,i=0,o=0,n=0;n<e;n++){var r=t[n];i+=r[0],o+=r[1]}return{x:i/e,y:o/e}}(e)}var Qt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPoints=void 0,n.midPoints=void 0,n.lastBearing=void 0,n.config=e,n.selectionPoints=i,n.midPoints=o,n}n(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0},i.rotate=function(t,e,i){var o=this,n=this.store.getGeometryCopy(e);if("Polygon"===n.type||"LineString"===n.type){var r,a=[t.lng,t.lat],l={type:"Feature",geometry:n,properties:{}};if("web-mercator"===this.config.projection){if(r=St($t(l),nt(t.lng,t.lat)),!this.lastBearing)return void(this.lastBearing=r);!function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,o=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return nt(t[0],t[1])}),n=o.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});n.x/=o.length,n.y/=o.length;var r=o.map(function(t){return{x:n.x+(t.x-n.x)*Math.cos(i)-(t.y-n.y)*Math.sin(i),y:n.y+(t.x-n.x)*Math.sin(i)+(t.y-n.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[rt(e,i).lng,rt(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(l,-(this.lastBearing-r))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(r=Nt(Zt({type:"Feature",geometry:n,properties:{}}),a),!this.lastBearing)return void(this.lastBearing=r+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=Zt(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var o=Nt(i,t)+e,n=qt(i,t),r=Vt(i,n,o);t[0]=r[0],t[1]=r[1]})}(l,-(this.lastBearing-(r+180)))}var c="Polygon"===n.type?n.coordinates[0]:n.coordinates;c.forEach(function(t){t[0]=s(t[0],o.coordinatePrecision),t[1]=s(t[1],o.coordinatePrecision)});var d=this.midPoints.getUpdated(c)||[],u=this.selectionPoints.getUpdated(c)||[];if(i&&!i({id:e,type:"Feature",geometry:n,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:V.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:n}].concat(u,d)),"web-mercator"===this.projection?this.lastBearing=r:"globe"===this.projection&&(this.lastBearing=r+180)}},e}(yt),te=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPoints=void 0,n.midPoints=void 0,n.lastDistance=void 0,n.config=e,n.selectionPoints=i,n.midPoints=o,n}n(e,t);var i=e.prototype;return i.reset=function(){this.lastDistance=void 0},i.scale=function(t,e,i){var o=this,n=this.store.getGeometryCopy(e);if("Polygon"===n.type||"LineString"===n.type){var r,l=[t.lng,t.lat],c={type:"Feature",geometry:n,properties:{}},d=$t(c);if("web-mercator"===this.config.projection){var u=nt(t.lng,t.lat);r=a(d,u)}else{if("globe"!==this.config.projection)throw new Error("Invalid projection");r=Z(Zt({type:"Feature",geometry:n,properties:{}}),l)}if(this.lastDistance){var h=1-(this.lastDistance-r)/r;if("web-mercator"===this.config.projection){var g=rt(d.x,d.y);!function(t,e,i){if(1===e)return t;var o=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return nt(t[0],t[1])}),n=nt(i[0],i[1]),r=o.map(function(t){return{x:n.x+(t.x-n.x)*e,y:n.y+(t.y-n.y)*e}}).map(function(t){var e=t.x,i=t.y;return[rt(e,i).lng,rt(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(c,h,[g.lng,g.lat])}else"globe"===this.config.projection&&function(t,e,i,o){void 0===o&&(o="xy"),1===e||("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=qt(i,t),r=Nt(i,t),s=Vt(i,n*e,r);"x"!==o&&"xy"!==o||(t[0]=s[0]),"y"!==o&&"xy"!==o||(t[1]=s[1])})}(c,h,Zt(c));var p="Polygon"===n.type?n.coordinates[0]:n.coordinates;p.forEach(function(t){t[0]=s(t[0],o.coordinatePrecision),t[1]=s(t[1],o.coordinatePrecision)});var f=this.midPoints.getUpdated(p)||[],y=this.selectionPoints.getUpdated(p)||[];if(i&&!i({id:e,type:"Feature",geometry:n,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:V.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:n}].concat(y,f)),this.lastDistance=r}else this.lastDistance=r}},e}(yt),ee=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.minimumScale=1e-4,r.draggedCoordinate={id:null,index:-1},r.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},r.config=e,r.pixelDistance=i,r.selectionPoints=o,r.midPoints=n,r}n(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(var n=0;n<i.length;n++){var r=this.pixelDistance.measure(t,i[n]);if(r<this.pointerDistance&&r<o.dist){var s="Polygon"===e.type&&(n===i.length-1||0===n);o.dist=r,o.index=s?0:n,o.isFirstOrLastPolygonCoord=s}}return o},i.isValidDragWebMercator=function(t,e,i){switch(t){case 0:if(e<=0||i>=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0},i.getSelectedFeatureDataWebMercator=function(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;var t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;var e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}},i.centerWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=$t(e.feature);if(!r)return null;var s=nt(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=nt(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:r}),o},i.centerFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=$t(e.feature);if(!r)return null;var s=nt(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=nt(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:r}),o},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,o=t.webMercatorCursor,n=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-o.x,e.y-o.y))return null;var r=a(e,o)/a(e,i);return r<0&&(r=this.minimumScale),this.performWebMercatorScale(n,e.x,e.y,r,r),n},i.oppositeFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=nt(n[0],n[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},d=nt(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:l,updatedCoords:o,webMercatorCursor:d,webMercatorSelected:r,webMercatorOrigin:c}),o},i.oppositeWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=nt(n[0],n[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},d=nt(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:l,updatedCoords:o,webMercatorCursor:d,webMercatorSelected:r,webMercatorOrigin:c}),o},i.scaleWebMercator=function(t){var e=t.closestBBoxIndex,i=t.webMercatorOrigin,o=t.webMercatorSelected,n=t.webMercatorCursor,r=t.updatedCoords,s=i.x-n.x,a=i.y-n.y;if(!this.isValidDragWebMercator(e,s,a))return null;var l=1;0!==s&&1!==e&&5!==e&&(l=1-(i.x-o.x-s)/s);var c=1;return 0!==a&&3!==e&&7!==e&&(c=1-(i.y-o.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,o=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&o},i.performWebMercatorScale=function(t,e,i,o,n){t.forEach(function(t){var r=nt(t[0],t[1]),s=rt(e+(r.x-e)*o,i+(r.y-i)*n),a=s.lat;t[0]=s.lng,t[1]=a})},i.getBBoxWebMercator=function(t){var e=[Infinity,Infinity,-Infinity,-Infinity];(t=t.map(function(t){var e=nt(t[0],t[1]);return[e.x,e.y]})).forEach(function(t){var i=t[0],o=t[1];i<e[0]&&(e[0]=i),o<e[1]&&(e[1]=o),i>e[2]&&(e[2]=i),o>e[3]&&(e[3]=o)});var i=e[0],o=e[1],n=e[2],r=e[3];return[[i,r],[(i+n)/2,r],[n,r],[n,r+(o-r)/2],[n,o],[(i+n)/2,o],[i,o],[i,r+(o-r)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,o=Infinity,n=0;n<t.length;n++){var r=a({x:e.x,y:e.y},{x:t[n][0],y:t[n][1]});r<o&&(i=n,o=r)}if(void 0===i)throw new Error("No closest coordinate found");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var o=this.getFeature(this.draggedCoordinate.id);if(!o)return!1;var n=null;if("center"===e?n=this.centerWebMercatorDrag(t):"opposite"===e?n=this.oppositeWebMercatorDrag(t):"center-fixed"===e?n=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(n=this.oppositeFixedWebMercatorDrag(t)),!n)return!1;for(var r=0;r<n.length;r++){var a=n[r];if(a[0]=s(a[0],this.coordinatePrecision),a[1]=s(a[1],this.coordinatePrecision),!dt(a,this.coordinatePrecision))return!1}var l=this.midPoints.getUpdated(n)||[],c=this.selectionPoints.getUpdated(n)||[],d={type:o.geometry.type,coordinates:"Polygon"===o.geometry.type?[n]:n};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:V.Provisional})||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:d}].concat(c,l)),0))},e}(yt),ie=/*#__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}n(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 Ct(t),this.clickBoundingBox=new mt(t),this.featuresAtMouseEvent=new Kt(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new Xt(t),this.midPoints=new Ut(t,this.selectionPoints),this.rotateFeature=new Qt(t,this.selectionPoints,this.midPoints),this.scaleFeature=new te(t,this.selectionPoints,this.midPoints),this.dragFeature=new Ht(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new Jt(t,this.pixelDistance,this.selectionPoints,this.midPoints),this.dragCoordinateResizeFeature=new ee(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:U,value:!1}});this.store.updateProperty(e),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()},i.deleteSelected=function(){this.store.delete(this.selected),this.selected=[]},i.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,o=Infinity;if(this.selectionPoints.ids.forEach(function(n){var r=e.store.getGeometryCopy(n),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<o&&(o=s,i=e.store.getPropertiesCopy(n))}),i){var n=i.selectionPointFeatureId,r=i.index,s=this.store.getPropertiesCopy(n),a=this.flags[s.mode],l=this.validations[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var c,d=this.store.getGeometryCopy(n);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:n,type:"Feature",geometry:d,properties:s},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:V.Commit}))return;this.store.delete([].concat(this.midPoints.ids,this.selectionPoints.ids)),this.store.updateGeometry([{id:n,geometry:d}]),this.selectionPoints.create(c,d.type,n),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(c,n,this.coordinatePrecision)}}}}},i.select=function(t,e){if(void 0===e&&(e=!0),this.selected[0]!==t){var i=this.store.getPropertiesCopy(t),o=this.flags[i.mode];if(o&&o.feature){var n=this.selected[0];if(n){if(n===t)return;this.deselect()}e&&this.setCursor(this.cursors.pointerOver),this.selected=[t],this.store.updateProperty([{id:t,property:"selected",value:!0}]),this.onSelect(t);var r=this.store.getGeometryCopy(t),s=r.type,a=r.coordinates;if("LineString"===s||"Polygon"===s){var l="LineString"===s?a:a[0];l&&o&&o.feature.coordinates&&(this.selectionPoints.create(l,s,t),o.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,o=e.clickedMidPoint;if(this.selected.length&&o)this.midPoints.insert(o.id,this.coordinatePrecision);else if(i&&i.id)this.select(i.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect()},i.start=function(){this.setStarted(),this.setSelecting()},i.stop=function(){this.cleanUp(),this.setStarted(),this.setStopped()},i.onClick=function(t){"right"!==t.button?"left"===t.button&&this.onLeftClick(t):this.onRightClick(t)},i.canScale=function(t){return this.keyEvents.scale&&this.keyEvents.scale.every(function(e){return t.heldKeys.includes(e)})},i.canRotate=function(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(function(e){return t.heldKeys.includes(e)})},i.preventDefaultKeyEvent=function(t){var e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()},i.onKeyDown=function(t){this.preventDefaultKeyEvent(t)},i.onKeyUp=function(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;this.onDeselect(this.selected[0]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()},i.cleanUp=function(){this.selected.length&&this.deselect()},i.onDragStart=function(t,e){if(this.selected.length){var i=this.store.getPropertiesCopy(this.selected[0]),o=this.flags[i.mode];if(o&&o.feature&&(o.feature.draggable||o.feature.coordinates&&o.feature.coordinates.draggable||o.feature.coordinates&&o.feature.coordinates.resizable)){this.dragEventCount=0;var n=this.selected[0],r=this.dragCoordinate.getDraggableIndex(t,n);return o&&o.feature&&o.feature.coordinates&&(o.feature.coordinates.draggable||o.feature.coordinates.resizable)&&-1!==r?(this.setCursor(this.cursors.dragStart),o.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(n,r):this.dragCoordinate.startDragging(n,r),void e(!1)):o&&o.feature&&o.feature.draggable&&this.dragFeature.canDrag(t,n)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,n),void e(!1)):void 0}}},i.onDrag=function(t,e){var i=this.selected[0];if(i){var o=this.store.getPropertiesCopy(i),n=this.flags[o.mode],r=!0===(n&&n.feature&&n.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){var s=this.validations[o.mode];if(n&&n.feature&&n.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i,s);if(n&&n.feature&&n.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i,s);if(this.dragCoordinateResizeFeature.isDragging()&&n.feature&&n.feature.coordinates&&n.feature.coordinates.resizable){if("globe"===this.projection)throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,n.feature.coordinates.resizable,s)}this.dragCoordinate.isDragging()?this.dragCoordinate.drag(t,r,s):this.dragFeature.isDragging()?this.dragFeature.drag(t,s):e(!0)}}},i.onDragEnd=function(t,e){this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0)},i.onMouseMove=function(t){var e=this;if(this.selected.length){if(!this.dragFeature.isDragging()){var i=!1;this.midPoints.ids.forEach(function(o){if(!i){var n=e.store.getGeometryCopy(o);e.pixelDistance.measure(t,n.coordinates)<e.pointerDistance&&(i=!0)}});var o=!1;if(this.selectionPoints.ids.forEach(function(n){var r=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,r.coordinates)<e.pointerDistance&&(i=!1,o=!0)}),i)this.setCursor(this.cursors.insertMidpoint);else{var n=this.featuresAtMouseEvent.find(t,!0).clickedFeature;this.setCursor(this.selected.length>0&&(n&&n.id===this.selected[0]||o)?this.cursors.pointerOver:"unset")}}}else this.setCursor("unset")},i.styleFeature=function(t){var e=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[U]){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}(J),oe=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,o=new Array(i),n=0;n<i;n++)o[n]=arguments[n];return(e=t.call.apply(t,[this].concat(o))||this).type=R.Static,e.mode="static",e}n(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}(H);function ne(t,e,i,o,n){for(;o>i;){if(o-i>600){var r=o-i+1,s=e-i+1,a=Math.log(r),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(r-l)/r)*(s-r/2<0?-1:1);ne(t,e,Math.max(i,Math.floor(e-s*l/r+c)),Math.min(o,Math.floor(e+(r-s)*l/r+c)),n)}var d=t[e],u=i,h=o;for(re(t,i,e),n(t[o],d)>0&&re(t,i,o);u<h;){for(re(t,u,h),u++,h--;n(t[u],d)<0;)u++;for(;n(t[h],d)>0;)h--}0===n(t[i],d)?re(t,i,h):re(t,++h,o),h<=e&&(i=h+1),e<=h&&(o=h-1)}}function re(t,e,i){var o=t[e];t[e]=t[i],t[i]=o}function se(t,e){ae(t,0,t.children.length,e,t)}function ae(t,e,i,o,n){n||(n=fe([])),n.minX=Infinity,n.minY=Infinity,n.maxX=-Infinity,n.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];le(n,t.leaf?o(s):s)}return n}function le(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 ce(t,e){return t.minX-e.minX}function de(t,e){return t.minY-e.minY}function ue(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function he(t){return t.maxX-t.minX+(t.maxY-t.minY)}function ge(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function pe(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function fe(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function ye(t,e,i,o,n){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=o)){var s=e+Math.ceil((i-e)/o/2)*o;ne(t,s,e,i,n),r.push(e,s,s,i)}}var ve=/*#__PURE__*/function(){function t(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}var e=t.prototype;return e.search=function(t){var e=this.data,i=[];if(!pe(t,e))return i;for(var o=this.toBBox,n=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?o(s):s;pe(t,a)&&(e.leaf?i.push(s):ge(t,a)?this._all(s,i):n.push(s))}e=n.pop()}return i},e.collides=function(t){var e=this.data;if(pe(t,e))for(var i=[];e;){for(var o=0;o<e.children.length;o++){var n=e.children[o],r=e.leaf?this.toBBox(n):n;if(pe(t,r)){if(e.leaf||ge(t,r))return!0;i.push(n)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var o=this.data;this.data=i,i=o}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=fe([])},e.remove=function(t){for(var e,i,o=this.data,n=this.toBBox(t),r=[],s=[],a=!1;o||r.length;){if(o||(o=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),o.leaf){var l=o.children.indexOf(t);-1!==l&&(o.children.splice(l,1),r.push(o),this._condense(r))}a||o.leaf||!ge(o,n)?i?(e++,o=i.children[e],a=!1):o=null:(r.push(o),s.push(e),e=0,i=o,o=o.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,o){var n,r=i-e+1,s=this._maxEntries;if(r<=s)return se(n=fe(t.slice(e,i+1)),this.toBBox),n;o||(o=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,o-1))),(n=fe([])).leaf=!1,n.height=o;var a=Math.ceil(r/s),l=a*Math.ceil(Math.sqrt(s));ye(t,e,i,l,this.compareMinX);for(var c=e;c<=i;c+=l){var d=Math.min(c+l-1,i);ye(t,c,d,a,this.compareMinY);for(var u=c;u<=d;u+=a){var h=Math.min(u+a-1,d);n.children.push(this._build(t,u,h,o-1))}}return se(n,this.toBBox),n},e._chooseSubtree=function(t,e,i,o){for(;o.push(e),!e.leaf&&o.length-1!==i;){for(var n=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var l=e.children[a],c=ue(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,n=c<n?c:n,s=l):d===r&&c<n&&(n=c,s=l)}e=s||e.children[0]}var u,h;return e},e._insert=function(t,e,i){var o=i?t:this.toBBox(t),n=[],r=this._chooseSubtree(o,this.data,e,n);for(r.children.push(t),le(r,o);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(o,n,e)},e._split=function(t,e){var i=t[e],o=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,o);var r=this._chooseSplitIndex(i,n,o),s=fe(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,se(i,this.toBBox),se(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=fe([t,e]),this.data.height=t.height+1,this.data.leaf=!1,se(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var o,n,r,s,a,l,c,d=Infinity,u=Infinity,h=e;h<=i-e;h++){var g=ae(t,0,h,this.toBBox),p=ae(t,h,i,this.toBBox),f=(n=g,r=p,s=Math.max(n.minX,r.minX),a=Math.max(n.minY,r.minY),l=Math.min(n.maxX,r.maxX),c=Math.min(n.maxY,r.maxY),Math.max(0,l-s)*Math.max(0,c-a)),y=ue(g)+ue(p);f<d?(d=f,o=h,u=y<u?y:u):f===d&&y<u&&(u=y,o=h)}return o||i-e},e._chooseSplitAxis=function(t,e,i){var o=t.leaf?this.compareMinX:ce,n=t.leaf?this.compareMinY:de;this._allDistMargin(t,e,i,o)<this._allDistMargin(t,e,i,n)&&t.children.sort(o)},e._allDistMargin=function(t,e,i,o){t.children.sort(o);for(var n=this.toBBox,r=ae(t,0,e,n),s=ae(t,i-e,i,n),a=he(r)+he(s),l=e;l<i-e;l++){var c=t.children[l];le(r,t.leaf?n(c):c),a+=he(r)}for(var d=i-e-1;d>=e;d--){var u=t.children[d];le(s,t.leaf?n(u):u),a+=he(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var o=i;o>=0;o--)le(e[o],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():se(t[i],this.toBBox)},t}(),me=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new ve(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}var e=t.prototype;return e.setMaps=function(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)},e.toBBox=function(t){var e,i=[],o=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var n=0;n<e.length;n++)o.push(e[n][1]),i.push(e[n][0]);var r=Math.min.apply(Math,o),s=Math.max.apply(Math,o);return{minX:Math.min.apply(Math,i),minY:r,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],o=new Set;t.forEach(function(t){var n=e.toBBox(t);if(e.setMaps(t,n),o.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);o.add(String(t.id)),i.push(n)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),Ce={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}},Pe=/*#__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 me,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:Ce}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 o=this.clone(t);o.forEach(function(t){null==t.id&&(t.id=i.idStrategy.getId()),i.tracked&&(t.properties.createdAt?K(t.properties.createdAt):t.properties.createdAt=+new Date,t.properties.updatedAt?K(t.properties.updatedAt):t.properties.updatedAt=+new Date)});var n=[];o.forEach(function(t){var o=t.id;if(e&&!e(t))throw new Error("Feature "+o+" is not valid: "+JSON.stringify(t));if(i.has(o))throw new Error("Feature already exists with this id: "+o);i.store[o]=t,n.push(o)}),this.spatialIndex.load(o),this._onChange(n,"create")}},e.search=function(t,e){var i=this,o=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?o.filter(e):o)},e.registerOnChange=function(t){this._onChange=function(e,i){t(e,i)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t){var e=this,i=[];t.forEach(function(t){var o=t.id,n=t.property,r=t.value,s=e.store[o];if(!s)throw new Error("No feature with this ("+o+"), can not update geometry");i.push(o),s.properties[n]=r,e.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.updateGeometry=function(t){var e=this,i=[];t.forEach(function(t){var o=t.id,n=t.geometry;i.push(o);var r=e.store[o];if(!r)throw new Error("No feature with this ("+o+"), can not update geometry");r.geometry=e.clone(n),e.spatialIndex.update(r),e.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.create=function(t){var e=this,i=[];return t.forEach(function(t){var 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 _e(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(Se(e[0]));for(var o=1;o<e.length;o++)i-=Math.abs(Se(e[o]))}return i}var xe=q*q/2,Me=Math.PI/180;function Se(t){var e=t.length;if(e<=2)return 0;for(var i=0,o=0;o<e;)i+=(t[o+2>=e?(o+2)%e:o+2][0]*Me-t[o][0]*Me)*Math.sin(t[o+1===e?0:o+1][1]*Me),o++;return i*xe}function be(t,e,i){var o=St(t,e),n=St(e,i)-o;return n<0&&(n+=360),180-Math.abs(n-90-90)}var we=/*#__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}n(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,o,n,r,s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var l=1/Math.pow(10,this.coordinatePrecision-1),c=Math.max(1e-6,l);e=[s[0],[t.lng,t.lat],[t.lng,t.lat-c],s[0]]}else if(2===this.currentCoordinate){var d=s[0],u=s[1],h=At(d,u,this.coordinatePrecision,this.project,this.unproject),g=nt(d[0],d[1]),p=nt(h[0],h[1]),f=nt(u[0],u[1]),y=nt(t.lng,t.lat),v=a(y,g)<a(y,f),m=be(g,p,y),C=v?90-m:be(g,p,y)-90,P=a(p,y),_=Math.cos($(C))*P,x=St(g,f)+("right"==((r=((n=y).x-(o=f).x)*((i=g).y-o.y)-(n.y-o.y)*(i.x-o.x))>1e-10?"left":r<-1e-10?"right":"left")?-90:90),M=xt(g,_,x),S=xt(f,_,x),b=rt(M.x,M.y),w=rt(S.x,S.y);e=[s[0],s[1],[w.lng,w.lat],[b.lng,b.lat],s[0]]}e&&this.updatePolygonGeometry(this.currentId,e,V.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i})||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(Ft([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]],V.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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ht(e,this.coordinatePrecision)},e}(H);function Ee(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var Ie=/*#__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}n(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 o=1/Math.pow(10,this.coordinatePrecision-1),n=Math.max(1e-6,o);e=[i[0],[t.lng,t.lat],[t.lng,t.lat-n],i[0]]}else if(2===this.currentCoordinate){var r=i[0],l=i[1],c=[t.lng,t.lat],d=nt(r[0],r[1]),u=nt(l[0],l[1]),h=nt(c[0],c[1]);if(void 0===this.direction){var g=Ee(d,u,h);this.direction=g?"clockwise":"anticlockwise"}var p,f=a(d,u),y=St(d,u),v=St(d,h),m=this.arcPoints,C=[r],P=bt(y),_=bt(v);"anticlockwise"===this.direction?(p=_-P)<0&&(p+=360):(p=P-_)<0&&(p+=360);var x=("anticlockwise"===this.direction?1:-1)*p/m;C.push(l);for(var M=0;M<=m;M++){var S=xt(d,f,P+M*x),b=rt(S.x,S.y),w=b.lat,E=[s(b.lng,this.coordinatePrecision),s(w,this.coordinatePrecision)];E[0]!==C[C.length-1][0]&&E[1]!==C[C.length-1][1]&&C.push(E)}C.push(r),e=[].concat(C)}e&&this.updatePolygonGeometry(this.currentId,e,V.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i})||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(Ft([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]],V.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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ht(e,this.coordinatePrecision)},e}(H),De=/*#__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}n(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,o=e[0],n=[t.lng,t.lat],r=nt(o[0],o[1]),l=nt(n[0],n[1]),c=nt(i[0],i[1]),d=a(c,r);if(void 0===this.direction){var u=Ee(c,r,l);this.direction=u?"clockwise":"anticlockwise"}var h,g=St(c,r),p=St(c,l),f=this.arcPoints,y=[o],v=bt(g),m=bt(p);"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 _=xt(c,d,v+P*C),x=rt(_.x,_.y),M=x.lat,S=[s(x.lng,this.coordinatePrecision),s(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,V.Provisional)}else if(3===this.currentCoordinate){var b=this.store.getGeometryCopy(this.currentInitialArcId).coordinates;if(b.length<2)return;if(!this.direction)return;var w=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,E=b[0],I=b[b.length-1],D=nt(t.lng,t.lat),F=nt(E[0],E[1]),k=nt(I[0],I[1]),O=nt(w[0],w[1]),j=a(O,F);if(a(O,D)<j)return;var L=St(O,D),W=St(O,F),B=St(O,k),G=bt(W),N=bt(B),A=bt(L);if(this.notInSector({normalizedCursor:A,normalizedStart:G,normalizedEnd:N,direction:this.direction}))return;for(var T=this.getDeltaBearing(this.direction,G,N),R=this.arcPoints,U=("anticlockwise"===this.direction?1:-1)*T/R,X=a(O,D),z=[],Y=0;Y<=R;Y++){var K=xt(O,X,G+Y*U),H=rt(K.x,K.y),J=H.lat,Z=[s(H.lng,this.coordinatePrecision),s(J,this.coordinatePrecision)];Z[0]!==b[b.length-1][0]&&Z[1]!==b[b.length-1][1]&&z.unshift(Z)}if(b.push.apply(b,z),b.push(b[0]),this.currentId)this.updatePolygonGeometry(this.currentId,b,V.Provisional);else{var q=this.store.create([{geometry:{type:"Polygon",coordinates:[b]},properties:{mode:this.mode}}]);this.currentId=q[0]}}},i.updateLineStringGeometry=function(t,e,i){var o={type:"LineString",coordinates:e};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i})||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i})||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);this.currentStartingPointId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentStartingPointId){var i=this.store.create([{geometry:{type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},properties:{mode:this.mode}}]);this.currentInitialArcId=i[0],this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentStartingPointId&&this.store.delete([this.currentStartingPointId]),this.currentInitialArcId&&this.store.delete([this.currentInitialArcId]),this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=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):"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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ht(e,this.coordinatePrecision)},i.getDeltaBearing=function(t,e,i){var o;return"anticlockwise"===t?(o=i-e)<0&&(o+=360):(o=e-i)<0&&(o+=360),o},i.notInSector=function(t){var e=t.normalizedCursor,i=t.normalizedStart,o=t.normalizedEnd;return"clockwise"===t.direction?i<=o?e>=i&&e<=o:e>=i||e<=o:i>=o?e<=i&&e>=o:e<=i||e>=o},e}(H),Fe={TerraDrawBaseDrawMode:H,TerraDrawBaseAdapter:c};exports.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 oe;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===R.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 Pe({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var s=function(t){var i=[],o=e._store.copyAll().filter(function(e){return!t.includes(e.id)||(i.push(e),!1)});return{changed:i,unchanged:o}},a=function(t,i){e._enabled&&e._eventListeners.finish.forEach(function(e){e(t,i)})},l=function(t,i){if(e._enabled){e._eventListeners.change.forEach(function(e){e(t,i)});var o=s(t),n=o.changed,r=o.unchanged;"create"===i?e._adapter.render({created:n,deletedIds:[],unchanged:r,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:r,updated:n},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:r,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:r,updated:[]},e.getModeStyles())}},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]),o=i.changed;o&&e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:o},e.getModeStyles())}};Object.keys(this._modes).forEach(function(t){e._modes[t].register({mode:t,store:e._store,setCursor:e._adapter.setCursor.bind(e._adapter),project:e._adapter.project.bind(e._adapter),unproject:e._adapter.unproject.bind(e._adapter),setDoubleClickToZoom:e._adapter.setDoubleClickToZoom.bind(e._adapter),onChange: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[U]?t._modes[t._instanceSelectMode].styleFeature.bind(t._modes[t._instanceSelectMode])(e):t._modes[i].styleFeature.bind(t._modes[i])(e)}}),e},e.featuresAtLocation=function(t,e){var i=t.lng,o=t.lat,n=e&&void 0!==e.pointerDistance?e.pointerDistance:30,r=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,s=this._adapter.unproject.bind(this._adapter),l=this._adapter.project.bind(this._adapter),c=l(i,o),d=vt({unproject:s,point:c,pointerDistance:n});return this._store.search(d).filter(function(t){if(r&&(t.properties[X]||t.properties.selectionPoint))return!1;if("Point"===t.geometry.type){var e=t.geometry.coordinates,s=l(e[0],e[1]);return a(c,s)<n}if("LineString"===t.geometry.type){for(var d=t.geometry.coordinates,u=0;u<d.length-1;u++){var h=d[u],g=d[u+1];if(Yt(c,l(h[0],h[1]),l(g[0],g[1]))<n)return!0}return!1}return!!zt([i,o],t.geometry.coordinates)||void 0})},e.getSelectMode=function(){if(this.checkEnabled(),!this._instanceSelectMode)throw new Error("No select mode defined in instance");return this.getMode()!==this._instanceSelectMode&&this.setMode(this._instanceSelectMode),this._modes[this._instanceSelectMode]},e.setModeStyles=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e},e.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)},i(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}]),t}(),exports.TerraDrawAngledRectangleMode=we,exports.TerraDrawArcGISMapsSDKAdapter=T,exports.TerraDrawCircleMode=pt,exports.TerraDrawExtend=Fe,exports.TerraDrawFreehandMode=ft,exports.TerraDrawGoogleMapsAdapter=d,exports.TerraDrawLeafletAdapter=u,exports.TerraDrawLineStringMode=kt,exports.TerraDrawMapLibreGLAdapter=g,exports.TerraDrawMapboxGLAdapter=h,exports.TerraDrawOpenLayersAdapter=A,exports.TerraDrawPointMode=jt,exports.TerraDrawPolygonMode=Wt,exports.TerraDrawRectangleMode=Bt,exports.TerraDrawRenderMode=Gt,exports.TerraDrawSectorMode=Ie,exports.TerraDrawSelectMode=ie,exports.TerraDrawSensorMode=De,exports.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"===t.geometry.type&&_e(t.geometry)<e},exports.ValidateMinAreaSquareMeters=function(t,e){return"Polygon"===t.geometry.type&&_e(t.geometry)>e},exports.ValidateNotSelfIntersecting=function(t){return("Polygon"===t.geometry.type||"LineString"===t.geometry.type)&&!lt(t)};
|
|
1
|
+
function t(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var o=i.call(t,"string");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function e(e,i){for(var o=0;o<i.length;o++){var n=i[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,t(n.key),n)}}function i(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),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 o in i)Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t},o.apply(this,arguments)}function n(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function s(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var a=function(t,e){var i=e.x-t.x,o=e.y-t.y;return Math.sqrt(o*o+i*i)},l=function(t){var e=this,i=t.name,o=t.callback,n=t.unregister,r=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=i,this.register=function(){e.registered||(e.registered=!0,r(o))},this.unregister=function(){e.register&&(e.registered=!1,n(o))},this.callback=o},c=/*#__PURE__*/function(){function t(t){this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState="not-dragging",this._currentModeCallbacks=void 0,this._minPixelDragDistance="number"==typeof t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9}var e=t.prototype;return e.getButton=function(t){return-1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"},e.getMapElementXYPosition=function(t){var e=this.getMapEventElement().getBoundingClientRect();return{containerX:t.clientX-e.left,containerY:t.clientY-e.top}},e.getDrawEventFromEvent=function(t){var e=this.getLngLatFromEvent(t);if(!e)return null;var i=e.lng,o=e.lat,n=this.getMapElementXYPosition(t),r=n.containerX,a=n.containerY,l=this.getButton(t),c=Array.from(this._heldKeys);return{lng:s(i,this._coordinatePrecision),lat:s(o,this._coordinatePrecision),containerX:r,containerY:a,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 l({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 l({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var i=t.getDrawEventFromEvent(e);if(i)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(i),t._lastDrawEvent=i;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var o={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},n={x:i.containerX,y:i.containerY},r=t._currentModeCallbacks.getState(),s=a(o,n);if("drawing"===r?s<t._minPixelDragDistanceDrawing:"selecting"===r?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;t._dragState="dragging",t._currentModeCallbacks.onDragStart(i,function(e){t.setDraggability.bind(t)(e)})}else"dragging"===t._dragState&&t._currentModeCallbacks.onDrag(i,function(e){t.setDraggability.bind(t)(e)})}},register:function(e){t.getMapEventElement().addEventListener("pointermove",e)},unregister:function(e){t.getMapEventElement().removeEventListener("pointermove",e)}}),new l({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 l({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 l({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 l({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}n(e,t);var o=e.prototype;return o.circlePath=function(t,e,i){var o=2*i;return"M "+t+" "+e+" m -"+i+", 0 a "+i+","+i+" 0 1,0 "+o+",0 a "+i+","+i+" 0 1,0 -"+o+",0"},o.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)})},o.unregister=function(){var e,i,o;t.prototype.unregister.call(this),null==(e=this._clickEventListener)||e.remove(),null==(i=this._mouseMoveEventListener)||i.remove(),null==(o=this._overlay)||o.setMap(null),this._overlay=void 0},o.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(),o=e.getSouthWest(),n=new this._lib.LatLngBounds(o,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&&n.contains(d)?{lng:d.lng(),lat:d.lat()}:null},o.getMapEventElement=function(){return this._map.getDiv().querySelector('div[style*="z-index: 3;"]')},o.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 o=i.fromLatLngToContainerPixel(new this._lib.LatLng(e,t));if(null===o)throw new Error("cannot project coordinates");return{x:o.x,y:o.y}},o.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 o=i.fromContainerPixelToLatLng(new this._lib.Point(t,e));if(null===o)throw new Error("cannot unproject coordinates");return{lng:o.lng(),lat:o.lat()}},o.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 o=document.createElement("style");o.innerHTML=".terra-draw-google-maps { cursor: "+t+" !important; }",document.getElementsByTagName("head")[0].appendChild(o),this._cursorStyleSheet=o}}this._cursor=t}},o.setDoubleClickToZoom=function(t){this._map.setOptions(t?{disableDoubleClickZoom:!1}:{disableDoubleClickZoom:!0})},o.setDraggability=function(t){this._map.setOptions({draggable:t})},o.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 o=t.geometry.coordinates;e.setGeometry(new i._lib.Data.Point(new i._lib.LatLng(o[1],o[0])));break;case"LineString":for(var n=t.geometry.coordinates,r=[],s=0;s<n.length;s++){var a=n[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=[],g=0;g<c[u].length;g++){var p=new i._lib.LatLng(c[u][g][1],c[u][g][0]);h.push(p)}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 o={type:"FeatureCollection",features:[].concat(t.created)};this._map.data.addGeoJson(o),this._map.data.setStyle(function(t){var o=t.getProperty("mode"),n=t.getGeometry();if(!n)throw new Error("Google Maps geometry not found");var r=n.getType(),s={};t.forEachProperty(function(t,e){s[e]=t});var a=e[o]({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")})},o.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)},o.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this.clearLayers())},o.getCoordinatePrecision=function(){return t.prototype.getCoordinatePrecision.call(this)},i(e,[{key:"_layers",get:function(){var t;return Boolean((null==(t=this.renderedFeatureIds)?void 0:t.size)>0)}}]),e}(c),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}n(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,o){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 n=(0,t[i.properties.mode])(i),r=String(n.zIndex);return e._panes[r]||(e._panes[r]=e.createPaneStyleSheet(r,n.zIndex)),e._lib.circleMarker(o,{radius:n.pointWidth,stroke:n.pointOutlineWidth||!1,color:n.pointOutlineColor,weight:n.pointOutlineWidth,fillOpacity:.8,fillColor:n.pointColor,pane:r,interactive:!1})},style:function(i){if(!i||!i.properties)return{};var o=i,n=(0,t[o.properties.mode])(o),r=String(n.zIndex);return e._panes[r]||(e._panes[r]=e.createPaneStyleSheet(r,n.zIndex)),"LineString"===o.geometry.type?{interactive:!1,color:n.lineStringColor,weight:n.lineStringWidth,pane:r}:"Polygon"===o.geometry.type?{interactive:!1,fillOpacity:n.polygonFillOpacity,fillColor:n.polygonFillColor,weight:n.polygonOutlineWidth,stroke:!0,color:n.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){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}(c),h=/*#__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}n(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 o=[].concat(t.created,t.updated,t.unchanged),n=[],r=[],s=[],a=0;a<o.length;a++){var l=o[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,n.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,g=h||i.changedIds.linestrings,p=h||i.changedIds.polygons;(h||i.changedIds.points)&&(u=i._setGeoJSONLayerData("Point",n)),g&&i._setGeoJSONLayerData("LineString",r),p&&i._setGeoJSONLayerData("Polygon",s),u&&i._map.moveLayer(u)}else{var f=i._addGeoJSONLayer("Point",n);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){t.prototype.register.call(this,e),this._currentModeCallbacks&&this._currentModeCallbacks.onReady&&this._currentModeCallbacks.onReady()},e}(c),g=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mapboxglAdapter=void 0,i.mapboxglAdapter=new h(e),i}n(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}(c);const p={radians:6370997/(2*Math.PI),degrees:2*Math.PI*6370997/360,ft:.3048,m:1,"us-ft":1200/3937};var f=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_||p[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 y=6378137,v=Math.PI*y,m=[-v,-v,v,v],C=[-180,-85,180,85],P=y*Math.log(Math.tan(Math.PI/2));class _ extends f{constructor(t){super({code:t,units:"m",extent:m,global:!0,worldExtent:C,getPointResolution:function(t,e){return t/Math.cosh(e[1]/y)}})}}const x=[new _("EPSG:3857"),new _("EPSG:102100"),new _("EPSG:102113"),new _("EPSG:900913"),new _("http://www.opengis.net/def/crs/EPSG/0/3857"),new _("http://www.opengis.net/gml/srs/epsg.xml#3857")],M=[-180,-90,180,90],S=6378137*Math.PI/180;class b extends f{constructor(t,e){super({code:t,units:"degrees",extent:M,axisOrientation:e,global:!0,metersPerUnit:S,worldExtent:M})}}const w=[new b("CRS:84"),new b("EPSG:4326","neu"),new b("urn:ogc:def:crs:OGC:1.3:CRS84"),new b("urn:ogc:def:crs:OGC:2:84"),new b("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),new b("http://www.opengis.net/gml/srs/epsg.xml#4326","neu"),new b("http://www.opengis.net/def/crs/EPSG/0/4326","neu")];let E={},I={};function D(t,e,i){const o=t.getCode(),n=e.getCode();o in I||(I[o]={}),I[o][n]=i}function F(t,e){if(void 0!==e)for(let i=0,o=t.length;i<o;++i)e[i]=t[i];else e=t.slice();return e}function k(t,e){if(void 0!==e&&t!==e){for(let i=0,o=t.length;i<o;++i)e[i]=t[i];t=e}return t}function O(t){!function(t,e){E[t]=e}(t.getCode(),t),D(t,t,F)}function j(t){return"string"==typeof t?E[e=t]||E[e.replace(/urn:(x-)?ogc:def:crs:EPSG:(.*:)?(\w+)$/,"EPSG:$3")]||null:t||null;var e}function L(t){!function(t){t.forEach(O)}(t),t.forEach(function(e){t.forEach(function(t){e!==t&&D(e,t,F)})})}function W(t,e,i){const o=function(t,e){return function(t,e){let i=function(t,e){let i;return t in I&&e in I[t]&&(i=I[t][e]),i}(t.getCode(),e.getCode());return i||(i=k),i}(j(t),j(e))}(e,i);return o(t,void 0,t.length)}var B,G,N;L(x),L(w),B=x,G=function(t,e,i){const o=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(o));for(let n=0;n<o;n+=i){e[n]=v*t[n]/180;let i=y*Math.log(Math.tan(Math.PI*(+t[n+1]+90)/360));i>P?i=P:i<-P&&(i=-P),e[n+1]=i}return e},N=function(t,e,i){const o=t.length;i=i>1?i:2,void 0===e&&(e=i>2?t.slice():new Array(o));for(let n=0;n<o;n+=i)e[n]=180*t[n]/v,e[n+1]=360*Math.atan(Math.exp(t[n+1]/y))/Math.PI-90;return e},w.forEach(function(t){B.forEach(function(e){D(t,e,G),D(e,t,N)})});var V,A=/*#__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=void 0,i._vectorSource=void 0,i._geoJSONReader=void 0,i._map=e.map,i._lib=e.lib,i._geoJSONReader=new i._lib.GeoJSON,i._projection=function(){var t;return null!=(t=i._lib.getUserProjection())?t:new f({code:"EPSG:3857"})},i._container=i._map.getViewport(),i._container.setAttribute("tabindex","0");var o=new i._lib.VectorSource({features:[]});i._vectorSource=o;var n=new i._lib.VectorLayer({source:o,style:function(t){return i.getStyles(t,i.stylingFunction())}});return i._map.addLayer(n),i}n(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,o=t.getGeometry();if(o)return{Point:function(t){var o=t.getProperties(),n=e[o.mode]({type:"Feature",geometry:{type:"Point",coordinates:[]},properties:o});return new i._lib.Style({image:new i._lib.Circle({radius:n.pointWidth,fill:new i._lib.Fill({color:n.pointColor}),stroke:new i._lib.Stroke({color:n.pointOutlineColor,width:n.pointOutlineWidth})})})},LineString:function(t){var o=t.getProperties(),n=e[o.mode]({type:"Feature",geometry:{type:"LineString",coordinates:[]},properties:o});return new i._lib.Style({stroke:new i._lib.Stroke({color:n.lineStringColor,width:n.lineStringWidth})})},Polygon:function(t){var o=t.getProperties(),n=e[o.mode]({type:"Feature",geometry:{type:"Polygon",coordinates:[]},properties:o}),r=i.hexToRGB(n.polygonFillColor),s=r.r,a=r.g,l=r.b;return new i._lib.Style({stroke:new i._lib.Stroke({color:n.polygonOutlineColor,width:n.polygonOutlineWidth}),fill:new i._lib.Fill({color:"rgba("+s+","+a+","+l+","+n.polygonFillOpacity+")"})})}}[o.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.getLngLatFromEvent=function(t){var e=this.getMapElementXYPosition(t),i=e.containerX,o=e.containerY;try{return this.unproject(i,o)}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,o=this._map.getPixelFromCoordinate(W([t,e],"EPSG:4326",void 0!==(i=this._projection())?i:"EPSG:3857"));return{x:o[0],y:o[1]}},i.unproject=function(t,e){var i=function(t,e){const i=W(t,void 0!==e?e:"EPSG:3857","EPSG:4326"),o=i[0];return(o<-180||o>180)&&(i[0]=function(t,e){const i=t%360;return 360*i<0?i+360:i}(o+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){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}(c),T=/*#__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}n(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}),o=this._mapView.toScreen(i);return{x:o.x,y:o.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,o=t.geometry,n=o.coordinates,r=o.type,s=e[t.properties.mode](t),a=void 0,l=void 0;switch(r){case"Point":l=new this._lib.Point({latitude:n[1],longitude:n[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:[n]}),a=new this._lib.SimpleLineSymbol({color:this.getColorFromHex(s.lineStringColor),width:s.lineStringWidth+"px"});break;case"Polygon":l=new this._lib.Polygon({rings:n}),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}(c);!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(V||(V={}));var R,U="selected",X="midPoint",z="closingPoint";function Y(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function K(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"}(R||(R={}));var H=/*#__PURE__*/function(){var t=e.prototype;function e(t){this._state=void 0,this._styles=void 0,this.behaviors=[],this.validate=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.onStyleChange=void 0,this.store=void 0,this.setDoubleClickToZoom=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.projection=void 0,this.type=R.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){if("unregistered"===this._state)throw new Error("Mode must be registered");var e=function(t,e){var i;if(Y(t))if(null==t.id)i="Feature has no id";else if("string"!=typeof t.id&&"number"!=typeof t.id)i="Feature must be string or number as per GeoJSON spec";else if(e(t.id))if(Y(t.geometry))if(Y(t.properties))if("string"==typeof t.geometry.type&&["Polygon","LineString","Point"].includes(t.geometry.type))if(Array.isArray(t.geometry.coordinates)){if(!t.properties.mode||"string"!=typeof t.properties.mode)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:V.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},i(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}(),J=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,o=new Array(i),n=0;n<i;n++)o[n]=arguments[n];return(e=t.call.apply(t,[this].concat(o))||this).type=R.Select,e}return n(e,t),e}(H);function Z(t,e){var i=function(t){return t*Math.PI/180},o=i(t[1]),n=i(t[0]),r=i(e[1]),s=r-o,a=i(e[0])-n,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(o)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}var q=6371008.8;function $(t){return t%360*Math.PI/180}function Q(t){return t/(q/1e3)}function tt(t){return t%(2*Math.PI)*180/Math.PI}var et=57.29577951308232,it=.017453292519943295,ot=6378137,nt=function(t,e){return{x:0===t?0:t*it*ot,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*it/2))*ot}},rt=function(t,e){return{lng:0===t?0:et*(t/ot),lat:0===e?0:(2*Math.atan(Math.exp(e/ot))-Math.PI/2)*et}};function st(t,e,i){var o=$(t[0]),n=$(t[1]),r=$(i),s=Q(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[tt(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),tt(a)]}function at(t){for(var e=t.center,i=t.radiusKilometers,o=t.coordinatePrecision,n=t.steps?t.steps:64,r=[],a=0;a<n;a++){var l=st(e,i,-360*a/n);r.push([s(l[0],o),s(l[1],o)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function lt(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 o=[],n=0;n<e.length;n++)for(var r=0;r<e[n].length-1;r++)for(var s=0;s<e.length;s++)for(var a=0;a<e[s].length-1;a++)c(n,r,s,a);return o.length>0;function l(t){return t<0-i.epsilon||t>1+i.epsilon}function c(t,i,n,r){var s,a=e[t][i],c=e[t][i+1],d=e[n][r],u=e[n][r+1],h=function(t,e,i,o){if(ct(t,i)||ct(t,o)||ct(e,i)||ct(o,i))return null;var n=t[0],r=t[1],s=e[0],a=e[1],l=i[0],c=i[1],d=o[0],u=o[1],h=(n-s)*(c-u)-(r-a)*(l-d);return 0===h?null:[((n*a-r*s)*(l-d)-(n-s)*(l*u-c*d))/h,((n*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(),o.push(h)))}}function ct(t,e){return t[0]===e[0]&&t[1]===e[1]}function dt(t,e){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(o=t[0])>=-180&&o<=180&&(i=t[1])>=-90&&i<=90&&ut(t[0])<=e&&ut(t[1])<=e;var i,o}function ut(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}function ht(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 dt(t,e)})&&(i=t.geometry.coordinates[0][0])[0]===(o=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]&&i[1]===o[1];var i,o}function gt(t,e){return ht(t,e)&&!lt(t)}var pt=/*#__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 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}n(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:V.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=at({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=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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&>(e,this.coordinatePrecision)},i.updateCircle=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e,i=Z(this.center,[t.lng,t.lat]);if("web-mercator"===this.projection){var o=function(t,e){var i=1e3*Z(t,e);if(0===i)return 1;var o=nt(t[0],t[1]),n=o.x,r=o.y,s=nt(e[0],e[1]),a=s.y;return Math.sqrt(Math.pow(s.x-n,2)+Math.pow(a-r,2))/i}(this.center,[t.lng,t.lat]);e=function(t){for(var e=t.center,i=t.coordinatePrecision,o=t.steps?t.steps:64,n=1e3*t.radiusKilometers,r=nt(e[0],e[1]),a=r.x,l=r.y,c=[],d=0;d<o;d++){var u=360*d/o*Math.PI/180,h=n*Math.cos(u),g=n*Math.sin(u),p=rt(a+h,l+g),f=p.lat;c.push([s(p.lng,i),s(f,i)])}return c.push(c[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[c]},properties:{}}}({center:this.center,radiusKilometers:i*o,coordinatePrecision:this.coordinatePrecision})}else{if("globe"!==this.projection)throw new Error("Invalid projection");e=at({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:V.Provisional}))return;this.store.updateGeometry([{id:this.currentCircleId,geometry:e.geometry}]),this.store.updateProperty([{id:this.currentCircleId,property:"radiusKilometers",value:i}])}},e}(H),ft=/*#__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?o({},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 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}n(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:V.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],o=this.project(i[0],i[1]),n=a({x:o.x,y:o.y},{x:t.containerX,y:t.containerY}),r=e.coordinates[0][0],s=this.project(r[0],r[1]);if(a({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(!(n<this.minDistance)){e.coordinates[0].pop();var l={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:l,properties:{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:V.Provisional}))return;this.store.updateGeometry([{id:this.currentId,geometry:l}])}}},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=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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ht(e,this.coordinatePrecision)},e}(H),yt=function(t){var e=t.store,i=t.mode,o=t.project,n=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision,a=t.projection;this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.store=e,this.mode=i,this.project=o,this.unproject=n,this.pointerDistance=r,this.coordinatePrecision=s,this.projection=a};function vt(t){var e=t.unproject,i=t.point,o=t.pointerDistance/2,n=i.x,r=i.y;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[e(n-o,r-o),e(n+o,r-o),e(n+o,r+o),e(n-o,r+o),e(n-o,r-o)].map(function(t){return[t.lng,t.lat]})]}}}var mt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.create=function(t){return vt({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(yt),Ct=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.measure=function(t,e){var i=this.project(e[0],e[1]);return a({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(yt),Pt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n.clickBoundingBox=void 0,n.getSnappableCoordinateFirstClick=function(t){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode)})},n.getSnappableCoordinate=function(t,e){return n.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===n.mode&&t.id!==e)})},n.config=e,n.pixelDistance=i,n.clickBoundingBox=o,n}return n(e,t),e.prototype.getSnappable=function(t,e){var i=this,o=this.clickBoundingBox.create(t),n=this.store.search(o,e),r={coord:void 0,minDist:Infinity};return n.forEach(function(e){var o;if("Polygon"===e.geometry.type)o=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;o=e.geometry.coordinates}o.forEach(function(e){var o=i.pixelDistance.measure(t,e);o<r.minDist&&o<i.pointerDistance&&(r.coord=e,r.minDist=o)})}),r.coord},e}(yt);function _t(t,e,i){var o=$(t[0]),n=$(t[1]),r=$(i),s=Q(e),a=Math.asin(Math.sin(n)*Math.cos(s)+Math.cos(n)*Math.sin(s)*Math.cos(r));return[tt(o+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(n),Math.cos(s)-Math.sin(n)*Math.sin(a))),tt(a)]}function xt(t,e,i){var o=t.x,n=t.y,r=$(i);return{x:o+e*Math.cos(r),y:n+e*Math.sin(r)}}function Mt(t,e){var i=$(t[0]),o=$(e[0]),n=$(t[1]),r=$(e[1]),s=Math.sin(o-i)*Math.cos(r),a=Math.cos(n)*Math.sin(r)-Math.sin(n)*Math.cos(r)*Math.cos(o-i);return tt(Math.atan2(s,a))}function St(t,e){var i=Math.atan2(e.y-t.y,e.x-t.x);return(i*=180/Math.PI)>180?i-=360:i<-180&&(i+=360),i}function bt(t){return(t+360)%360}function wt(t,e,i){for(var o,n,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(!(o=e-l))return s.push(t[c]),s;n=Mt(t[c],t[c-1])-180,r=_t(t[c],o,n),s.push(r)}if(l>=i)return(o=i-l)?(n=Mt(t[c],t[c-1])-180,r=_t(t[c],o,n),s.push(r),s):(s.push(t[c]),s);if(l>=e&&s.push(t[c]),c===t.length-1)return s;l+=Z(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 Et(t){return t*(Math.PI/180)}function It(t){return t*(180/Math.PI)}var Dt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.config=e,i}n(e,t);var i=e.prototype;return i.generateInsertionCoordinates=function(t,e,i){for(var o=[t,e],n=0,r=0;r<o.length-1;r++)n+=Z(o[0],o[1]);if(n<=i)return o;var s=n/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);for(var a=[],l=0;l<s;l++){var c=wt(o,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 o=Z(t,e),n=function(t,e,i){var o=[],n=Et(t[1]),r=Et(t[0]),s=Et(e[1]),a=Et(e[0]);i+=1;var l=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-n)/2),2)+Math.cos(n)*Math.cos(s)*Math.pow(Math.sin((a-r)/2),2)));if(0===l||isNaN(l))return o;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),g=u*Math.cos(n)*Math.cos(r)+h*Math.cos(s)*Math.cos(a),p=u*Math.cos(n)*Math.sin(r)+h*Math.cos(s)*Math.sin(a),f=u*Math.sin(n)+h*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)||o.push([It(v),It(y)])}}return o.slice(1,-1)}(t,e,Math.floor(o/i));return this.limitCoordinates(n)},i.limitCoordinates=function(t){var e=this;return t.map(function(t){return[s(t[0],e.config.coordinatePrecision),s(t[1],e.config.coordinatePrecision)]})},e}(yt);function Ft(t,e){return t[0]===e[0]&&t[1]===e[1]}var kt=/*#__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?o({},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 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}n(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,V.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 o={type:"LineString",coordinates:t};if(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i}))return;var n=[{id:this.currentId,geometry:o}];this.closingPointId&&e&&n.push({id:this.closingPointId,geometry:{type:"Point",coordinates:e}}),"commit"===i&&(this.lastCommitedCoordinates=o.coordinates),this.store.updateGeometry(n)}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommitedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=Z(t,e)/(this.insertCoordinates.value+1),o=[];return"globe"===this.projection?o=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(o=this.insertPoint.generateInsertionCoordinates(t,e,i)),o},i.createLine=function(t){var e=this.store.create([{geometry:{type:"LineString",coordinates:[t,t]},properties:{mode:this.mode}}])[0];this.lastCommitedCoordinates=[t,t],this.currentId=e,this.currentCoordinate++,this.setDrawing()},i.firstUpdateToLine=function(t){if(this.currentId){var e=this.store.getGeometryCopy(this.currentId).coordinates,i=this.store.create([{geometry:{type:"Point",coordinates:[].concat(t)},properties:{mode:this.mode}}]);this.closingPointId=i[0],this.setCursor(this.cursors.close);var o=[].concat(e,[t]);this.updateGeometries(o,void 0,V.Commit),this.currentCoordinate++}},i.updateToLine=function(t,e){if(this.currentId){var i=this.store.getGeometryCopy(this.currentId).coordinates,o=this.lastCommitedCoordinates?this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1]:i[i.length-2],n=this.project(o[0],o[1]);if(a({x:n.x,y:n.y},{x:e.x,y:e.y})<this.pointerDistance)this.close();else{this.setCursor(this.cursors.close);var r=[].concat(i,[t]);this.updateGeometries(r,i[i.length-1],V.Commit),this.currentCoordinate++}}},i.registerBehaviors=function(t){this.snapping=new Pt(t,new Ct(t),new mt(t)),this.insertPoint=new Dt(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 o=e[e.length-1],n=this.project(o[0],o[1]);a({x:n.x,y:n.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor(this.cursors.close)}var r=[].concat(e,[i]);if(this.insertCoordinates&&this.currentId&&this.lastCommitedCoordinates){var s=this.lastCommitedCoordinates[this.lastCommitedCoordinates.length-1],l=i;if(!Ft(s,l)){var c=this.generateInsertCoordinates(s,l);r=[].concat(this.lastCommitedCoordinates.slice(0,-1),c,[i])}}this.updateGeometries(r,void 0,V.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,e=this.closingPointId;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!==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&&"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}(H);function Ot(t,e){return"Point"===t.geometry.type&&dt(t.geometry.coordinates,e)}var jt=/*#__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}n(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:V.Finish})){var o=this.store.create([{geometry:e,properties:i}]);this.onFinish(o[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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&Ot(e,this.coordinatePrecision)},e}(H),Lt=/*#__PURE__*/function(t){function e(e,i){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o._startEndPoints=[],o.config=e,o.pixelDistance=i,o}n(e,t);var o=e.prototype;return o.create=function(t,e){var i,o;if(this.ids.length)throw new Error("Opening and closing points already created");if(t.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:(i={mode:e},i[z]=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(o={mode:e},o[z]=!0,o)}])},o.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])},o.update=function(t){if(2!==this.ids.length)throw new Error("No closing points to update");this.store.updateGeometry([{id:this.ids[0],geometry:{type:"Point",coordinates:t[0]}},{id:this.ids[1],geometry:{type:"Point",coordinates:t[t.length-3]}}])},o.isClosingPoint=function(t){var e=this.store.getGeometryCopy(this.ids[0]),i=this.store.getGeometryCopy(this.ids[1]),o=this.pixelDistance.measure(t,e.coordinates),n=this.pixelDistance.measure(t,i.coordinates);return{isClosing:o<this.pointerDistance,isPreviousClosing:n<this.pointerDistance}},i(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}]),e}(yt),Wt=/*#__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?o({},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 r={cancel:"Escape",finish:"Enter"};i.keyEvents=e&&e.keyEvents?o({},r,e.keyEvents):r}return i}n(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]]),V.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 Ct(t),this.snapping=new Pt(t,this.pixelDistance,new mt(t)),this.closingPoints=new Lt(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,o=this.store.getGeometryCopy(this.currentId).coordinates[0];if(i&&(t.lng=i[0],t.lat=i[1]),1===this.currentCoordinate){var n=1/Math.pow(10,this.coordinatePrecision-1),r=Math.max(1e-6,n);e=[o[0],[t.lng,t.lat],[t.lng,t.lat-r],o[0]]}else if(2===this.currentCoordinate)e=[o[0],o[1],[t.lng,t.lat],o[0]];else{var s=this.closingPoints.isClosingPoint(t);s.isPreviousClosing||s.isClosing?(this.setCursor(this.cursors.close),e=[].concat(o.slice(0,-2),[o[0],o[0]])):e=[].concat(o.slice(0,-2),[[t.lng,t.lat],o[0]])}this.updatePolygonGeometry(e,V.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 o=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;o&&(t.lng=o[0],t.lat=o[1]);var n=this.store.getGeometryCopy(this.currentId);if(Ft([t.lng,t.lat],n.coordinates[0][0]))return;if(!this.updatePolygonGeometry([n.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],n.coordinates[0][0]],V.Commit))return;this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){var r=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;r&&(t.lng=r[0],t.lat=r[1]);var s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(Ft([t.lng,t.lat],s[1]))return;if(!this.updatePolygonGeometry([s[0],s[1],[t.lng,t.lat],[t.lng,t.lat],s[0]],V.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]),Ft([t.lng,t.lat],l[this.currentCoordinate-1]))return;var d=(void 0===(u=[[].concat(l.slice(0,-1),[[t.lng,t.lat],l[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],V.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;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=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)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&&ht(e,this.coordinatePrecision)},e}(H),Bt=/*#__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}n(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],o={type:"Polygon",coordinates:[[i,[t.lng,i[1]],[t.lng,t.lat],[i[0],t.lat],i]]};if(this.validate&&!this.validate({id:this.currentRectangleId,geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:e}))return;this.store.updateGeometry([{id:this.currentRectangleId,geometry:o}])}},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,V.Finish),this.close()},i.onMouseMove=function(t){this.updateRectangle(t,V.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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&>(e,this.coordinatePrecision)},e}(H),Gt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,{styles:e.styles})||this).type=R.Render,i.mode="render",i.mode=e.modeName,i}n(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)&&(Ot(e,this.coordinatePrecision)||ht(e,this.coordinatePrecision)||function(t,e){return"LineString"===t.geometry.type&&t.geometry.coordinates.length>=2&&t.geometry.coordinates.every(function(t){return dt(t,e)})}(e,this.coordinatePrecision))},e}(H);function Nt(t,e){var i=t,o=e,n=$(i[1]),r=$(o[1]),s=$(o[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),l=(tt(Math.atan2(s,a))+360)%360;return l>180?-(360-l):l}function Vt(t,e,i){var o=e;e<0&&(o=-Math.abs(o));var n=o/q,r=t[0]*Math.PI/180,s=$(t[1]),a=$(i),l=n*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+n*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 At(t,e,i,o,n){var r=o(t[0],t[1]),a=o(e[0],e[1]),l=n((r.x+a.x)/2,(r.y+a.y)/2),c=l.lat;return[s(l.lng,i),s(c,i)]}function Tt(t,e,i){var o=Vt(t,1e3*Z(t,e)/2,Nt(t,e));return[s(o[0],i),s(o[1],i)]}function Rt(t){for(var e=t.featureCoords,i=t.precision,o=t.unproject,n=t.project,r=t.projection,s=[],a=0;a<e.length-1;a++){var l=void 0;if("web-mercator"===r)l=At(e[a],e[a+1],i,n,o);else{if("globe"!==r)throw new Error("Invalid projection");l=Tt(e[a],e[a+1],i)}s.push(l)}return s}var Ut=/*#__PURE__*/function(t){function e(e,i){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPointBehavior=void 0,o._midPoints=[],o.config=e,o.selectionPointBehavior=i,o}n(e,t);var o=e.prototype;return o.insert=function(t,e){var i=this.store.getGeometryCopy(t),o=this.store.getPropertiesCopy(t),n=o.midPointFeatureId,r=o.midPointSegment,s=this.store.getGeometryCopy(n),a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.splice(r+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[a]:a,this.store.updateGeometry([{id:n,geometry:s}]),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(a,n,e),this.selectionPointBehavior.create(a,s.type,n)},o.create=function(t,e,i){var o=this;if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i,o,n,r){return Rt({featureCoords:t,precision:i,project:o,unproject:n,projection:r}).map(function(t,i){return{geometry:{type:"Point",coordinates:t},properties:e(i)}})}(t,function(t){var i;return(i={mode:o.mode})[X]=!0,i.midPointSegment=t,i.midPointFeatureId=e,i},i,this.config.project,this.config.unproject,this.projection))},o.delete=function(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])},o.getUpdated=function(t){var e=this;if(0!==this._midPoints.length)return Rt({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}}})},i(e,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}]),e}(yt),Xt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this)._selectionPoints=[],i}n(e,t);var o=e.prototype;return o.create=function(t,e,i){var o=this;this._selectionPoints=this.store.create(function(t,e,i){for(var o=[],n="Polygon"===e?t.length-1:t.length,r=0;r<n;r++)o.push({geometry:{type:"Point",coordinates:t[r]},properties:i(r)});return o}(t,e,function(t){return{mode:o.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t}}))},o.delete=function(){this.ids.length&&(this.store.delete(this.ids),this._selectionPoints=[])},o.getUpdated=function(t){if(0!==this._selectionPoints.length)return this._selectionPoints.map(function(e,i){return{id:e,geometry:{type:"Point",coordinates:t[i]}}})},o.getOneUpdated=function(t,e){if(void 0!==this._selectionPoints[t])return{id:this._selectionPoints[t],geometry:{type:"Point",coordinates:e}}},i(e,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}]),e}(yt);function zt(t,e){for(var i,o,n,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++)(o=l[c])[1]>(i=t)[1]!=(n=l[u])[1]>i[1]&&i[0]<(n[0]-o[0])*(i[1]-o[1])/(n[1]-o[1])+o[0]&&(r=!r);return r}var Yt=function(t,e,i){var o=function(t){return t*t},n=function(t,e){return o(t.x-e.x)+o(t.y-e.y)};return Math.sqrt(function(t,e,i){var o=n(e,i);if(0===o)return n(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/o;return r=Math.max(0,Math.min(1,r)),n(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},Kt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.createClickBoundingBox=void 0,n.pixelDistance=void 0,n.config=e,n.createClickBoundingBox=i,n.pixelDistance=o,n}return n(e,t),e.prototype.find=function(t,e){for(var i=void 0,o=Infinity,n=void 0,r=Infinity,s=void 0,a=Infinity,l=void 0,c=this.createClickBoundingBox.create(t),d=this.store.search(c),u=0;u<d.length;u++){var h=d[u],g=h.geometry;if("Point"===g.type){if(h.properties.selectionPoint||!e&&h.properties[X])continue;var p=this.pixelDistance.measure(t,g.coordinates);h.properties[X]&&p<this.pointerDistance&&p<a?(a=p,s=h):!h.properties[X]&&p<this.pointerDistance&&p<o&&(o=p,i=h)}else if("LineString"===g.type){if(i)continue;for(var f=0;f<g.coordinates.length-1;f++){var y=g.coordinates[f],v=g.coordinates[f+1],m=Yt({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,n=h)}}else if("Polygon"===g.type){if(i||n)continue;zt([t.lng,t.lat],g.coordinates)&&(l=h)}}return{clickedFeature:i||n||l,clickedMidPoint:s}},e}(yt),Ht=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.featuresAtMouseEvent=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedFeatureId=null,r.dragPosition=void 0,r.config=e,r.featuresAtMouseEvent=i,r.selectionPoints=o,r.midPoints=n,r}n(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),o=[t.lng,t.lat];if("Polygon"===i.type||"LineString"===i.type){var n,r;if(r="Polygon"===i.type?(n=i.coordinates[0]).length-1:(n=i.coordinates).length,!this.dragPosition)return!1;for(var a=0;a<r;a++){var l=n[a],c=[this.dragPosition[0]-o[0],this.dragPosition[1]-o[1]],d=s(l[0]-c[0],this.config.coordinatePrecision),u=s(l[1]-c[1],this.config.coordinatePrecision);if(d>180||d<-180||u>90||u<-90)return!1;n[a]=[d,u]}"Polygon"===i.type&&(n[n.length-1]=[n[0][0],n[0][1]]);var h=this.selectionPoints.getUpdated(n)||[],g=this.midPoints.getUpdated(n)||[];if(e&&!e({type:"Feature",id:this.draggedFeatureId,geometry:i,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:V.Provisional}))return!1;this.store.updateGeometry([{id:this.draggedFeatureId,geometry:i}].concat(h,g)),this.dragPosition=[t.lng,t.lat]}else"Point"===i.type&&(this.store.updateGeometry([{id:this.draggedFeatureId,geometry:{type:"Point",coordinates:o}}]),this.dragPosition=[t.lng,t.lat])}},e}(yt),Jt=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.draggedCoordinate={id:null,index:-1},r.config=e,r.pixelDistance=i,r.selectionPoints=o,r.midPoints=n,r}n(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(var n=0;n<i.length;n++){var r=this.pixelDistance.measure(t,i[n]);if(r<this.pointerDistance&&r<o.dist){var s="Polygon"===e.type&&(n===i.length-1||0===n);o.dist=r,o.index=s?0:n,o.isFirstOrLastPolygonCoord=s}}return o},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var o=this.draggedCoordinate.index,n=this.store.getGeometryCopy(this.draggedCoordinate.id),r="LineString"===n.type?n.coordinates:n.coordinates[0],s=[t.lng,t.lat];if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if("Polygon"!==n.type||o!==r.length-1&&0!==o)r[o]=s;else{var a=r.length-1;r[0]=s,r[a]=s}var l=this.selectionPoints.getOneUpdated(o,s),c=l?[l]:[],d=this.midPoints.getUpdated(r)||[];return!("Point"!==n.type&&!e&<({type:"Feature",geometry:n,properties:{}})||i&&!i({type:"Feature",id:this.draggedCoordinate.id,geometry:n,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:V.Provisional})||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:n}].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}(yt);function Zt(t){var e=0,i=0,o=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],o++},!0),[e/o,i/o]}function qt(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=q,o=e[1]*Math.PI/180,n=t[1]*Math.PI/180,r=n-o,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),l=Math.abs(a)>1e-11?r/a:Math.cos(o);return Math.sqrt(r*r+l*l*s*s)*i}function $t(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=nt(t[0],t[1]);return[e.x,e.y]});return"Polygon"===t.geometry.type?function(t){for(var e=0,i=0,o=0,n=t.length,r=0;r<n-1;r++){var s=t[r],a=s[0],l=s[1],c=t[r+1],d=c[0],u=c[1],h=a*u-d*l;e+=h,i+=(a+d)*h,o+=(l+u)*h}return{x:i/=6*(e/=2),y:o/=6*e}}(e):function(t){for(var e=t.length,i=0,o=0,n=0;n<e;n++){var r=t[n];i+=r[0],o+=r[1]}return{x:i/e,y:o/e}}(e)}var Qt=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPoints=void 0,n.midPoints=void 0,n.lastBearing=void 0,n.config=e,n.selectionPoints=i,n.midPoints=o,n}n(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0},i.rotate=function(t,e,i){var o=this,n=this.store.getGeometryCopy(e);if("Polygon"===n.type||"LineString"===n.type){var r,a=[t.lng,t.lat],l={type:"Feature",geometry:n,properties:{}};if("web-mercator"===this.config.projection){if(r=St($t(l),nt(t.lng,t.lat)),!this.lastBearing)return void(this.lastBearing=r);!function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,o=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return nt(t[0],t[1])}),n=o.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});n.x/=o.length,n.y/=o.length;var r=o.map(function(t){return{x:n.x+(t.x-n.x)*Math.cos(i)-(t.y-n.y)*Math.sin(i),y:n.y+(t.x-n.x)*Math.sin(i)+(t.y-n.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[rt(e,i).lng,rt(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(l,-(this.lastBearing-r))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(r=Nt(Zt({type:"Feature",geometry:n,properties:{}}),a),!this.lastBearing)return void(this.lastBearing=r+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=Zt(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var o=Nt(i,t)+e,n=qt(i,t),r=Vt(i,n,o);t[0]=r[0],t[1]=r[1]})}(l,-(this.lastBearing-(r+180)))}var c="Polygon"===n.type?n.coordinates[0]:n.coordinates;c.forEach(function(t){t[0]=s(t[0],o.coordinatePrecision),t[1]=s(t[1],o.coordinatePrecision)});var d=this.midPoints.getUpdated(c)||[],u=this.selectionPoints.getUpdated(c)||[];if(i&&!i({id:e,type:"Feature",geometry:n,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:V.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:n}].concat(u,d)),"web-mercator"===this.projection?this.lastBearing=r:"globe"===this.projection&&(this.lastBearing=r+180)}},e}(yt),te=/*#__PURE__*/function(t){function e(e,i,o){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPoints=void 0,n.midPoints=void 0,n.lastDistance=void 0,n.config=e,n.selectionPoints=i,n.midPoints=o,n}n(e,t);var i=e.prototype;return i.reset=function(){this.lastDistance=void 0},i.scale=function(t,e,i){var o=this,n=this.store.getGeometryCopy(e);if("Polygon"===n.type||"LineString"===n.type){var r,l=[t.lng,t.lat],c={type:"Feature",geometry:n,properties:{}},d=$t(c);if("web-mercator"===this.config.projection){var u=nt(t.lng,t.lat);r=a(d,u)}else{if("globe"!==this.config.projection)throw new Error("Invalid projection");r=Z(Zt({type:"Feature",geometry:n,properties:{}}),l)}if(this.lastDistance){var h=1-(this.lastDistance-r)/r;if("web-mercator"===this.config.projection){var g=rt(d.x,d.y);!function(t,e,i){if(1===e)return t;var o=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return nt(t[0],t[1])}),n=nt(i[0],i[1]),r=o.map(function(t){return{x:n.x+(t.x-n.x)*e,y:n.y+(t.y-n.y)*e}}).map(function(t){var e=t.x,i=t.y;return[rt(e,i).lng,rt(e,i).lat]});"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r}(c,h,[g.lng,g.lat])}else"globe"===this.config.projection&&function(t,e,i,o){void 0===o&&(o="xy"),1===e||("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=qt(i,t),r=Nt(i,t),s=Vt(i,n*e,r);"x"!==o&&"xy"!==o||(t[0]=s[0]),"y"!==o&&"xy"!==o||(t[1]=s[1])})}(c,h,Zt(c));var p="Polygon"===n.type?n.coordinates[0]:n.coordinates;p.forEach(function(t){t[0]=s(t[0],o.coordinatePrecision),t[1]=s(t[1],o.coordinatePrecision)});var f=this.midPoints.getUpdated(p)||[],y=this.selectionPoints.getUpdated(p)||[];if(i&&!i({id:e,type:"Feature",geometry:n,properties:{}},{project:this.config.project,unproject:this.config.unproject,coordinatePrecision:this.config.coordinatePrecision,updateType:V.Provisional}))return!1;this.store.updateGeometry([{id:e,geometry:n}].concat(y,f)),this.lastDistance=r}else this.lastDistance=r}},e}(yt),ee=/*#__PURE__*/function(t){function e(e,i,o,n){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.minimumScale=1e-4,r.draggedCoordinate={id:null,index:-1},r.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},r.config=e,r.pixelDistance=i,r.selectionPoints=o,r.midPoints=n,r}n(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return o;i=e.coordinates[0]}for(var n=0;n<i.length;n++){var r=this.pixelDistance.measure(t,i[n]);if(r<this.pointerDistance&&r<o.dist){var s="Polygon"===e.type&&(n===i.length-1||0===n);o.dist=r,o.index=s?0:n,o.isFirstOrLastPolygonCoord=s}}return o},i.isValidDragWebMercator=function(t,e,i){switch(t){case 0:if(e<=0||i>=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0},i.getSelectedFeatureDataWebMercator=function(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;var t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;var e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}},i.centerWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=$t(e.feature);if(!r)return null;var s=nt(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=nt(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:r}),o},i.centerFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=$t(e.feature);if(!r)return null;var s=nt(n[0],n[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,l=nt(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:o,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:r}),o},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,o=t.webMercatorCursor,n=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-o.x,e.y-o.y))return null;var r=a(e,o)/a(e,i);return r<0&&(r=this.minimumScale),this.performWebMercatorScale(n,e.x,e.y,r,r),n},i.oppositeFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=nt(n[0],n[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},d=nt(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:l,updatedCoords:o,webMercatorCursor:d,webMercatorSelected:r,webMercatorOrigin:c}),o},i.oppositeWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,o=e.updatedCoords,n=e.selectedCoordinate,r=nt(n[0],n[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,l=s.closestBBoxIndex,c={x:i[a][0],y:i[a][1]},d=nt(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:l,updatedCoords:o,webMercatorCursor:d,webMercatorSelected:r,webMercatorOrigin:c}),o},i.scaleWebMercator=function(t){var e=t.closestBBoxIndex,i=t.webMercatorOrigin,o=t.webMercatorSelected,n=t.webMercatorCursor,r=t.updatedCoords,s=i.x-n.x,a=i.y-n.y;if(!this.isValidDragWebMercator(e,s,a))return null;var l=1;0!==s&&1!==e&&5!==e&&(l=1-(i.x-o.x-s)/s);var c=1;return 0!==a&&3!==e&&7!==e&&(c=1-(i.y-o.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,o=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&o},i.performWebMercatorScale=function(t,e,i,o,n){t.forEach(function(t){var r=nt(t[0],t[1]),s=rt(e+(r.x-e)*o,i+(r.y-i)*n),a=s.lat;t[0]=s.lng,t[1]=a})},i.getBBoxWebMercator=function(t){var e=[Infinity,Infinity,-Infinity,-Infinity];(t=t.map(function(t){var e=nt(t[0],t[1]);return[e.x,e.y]})).forEach(function(t){var i=t[0],o=t[1];i<e[0]&&(e[0]=i),o<e[1]&&(e[1]=o),i>e[2]&&(e[2]=i),o>e[3]&&(e[3]=o)});var i=e[0],o=e[1],n=e[2],r=e[3];return[[i,r],[(i+n)/2,r],[n,r],[n,r+(o-r)/2],[n,o],[(i+n)/2,o],[i,o],[i,r+(o-r)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,o=Infinity,n=0;n<t.length;n++){var r=a({x:e.x,y:e.y},{x:t[n][0],y:t[n][1]});r<o&&(i=n,o=r)}if(void 0===i)throw new Error("No closest coordinate found");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},i.getDraggableIndex=function(t,e){var i=this.store.getGeometryCopy(e),o=this.getClosestCoordinate(t,i);return-1===o.index?-1:o.index},i.drag=function(t,e,i){if(!this.draggedCoordinate.id)return!1;var o=this.getFeature(this.draggedCoordinate.id);if(!o)return!1;var n=null;if("center"===e?n=this.centerWebMercatorDrag(t):"opposite"===e?n=this.oppositeWebMercatorDrag(t):"center-fixed"===e?n=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(n=this.oppositeFixedWebMercatorDrag(t)),!n)return!1;for(var r=0;r<n.length;r++){var a=n[r];if(a[0]=s(a[0],this.coordinatePrecision),a[1]=s(a[1],this.coordinatePrecision),!dt(a,this.coordinatePrecision))return!1}var l=this.midPoints.getUpdated(n)||[],c=this.selectionPoints.getUpdated(n)||[],d={type:o.geometry.type,coordinates:"Polygon"===o.geometry.type?[n]:n};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:V.Provisional})||(this.store.updateGeometry([{id:this.draggedCoordinate.id,geometry:d}].concat(c,l)),0))},e}(yt),ie=/*#__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}n(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 Ct(t),this.clickBoundingBox=new mt(t),this.featuresAtMouseEvent=new Kt(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new Xt(t),this.midPoints=new Ut(t,this.selectionPoints),this.rotateFeature=new Qt(t,this.selectionPoints,this.midPoints),this.scaleFeature=new te(t,this.selectionPoints,this.midPoints),this.dragFeature=new Ht(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new Jt(t,this.pixelDistance,this.selectionPoints,this.midPoints),this.dragCoordinateResizeFeature=new ee(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:U,value:!1}});this.store.updateProperty(e),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()},i.deleteSelected=function(){this.store.delete(this.selected),this.selected=[]},i.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,o=Infinity;if(this.selectionPoints.ids.forEach(function(n){var r=e.store.getGeometryCopy(n),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<o&&(o=s,i=e.store.getPropertiesCopy(n))}),i){var n=i.selectionPointFeatureId,r=i.index,s=this.store.getPropertiesCopy(n),a=this.flags[s.mode],l=this.validations[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var c,d=this.store.getGeometryCopy(n);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:n,type:"Feature",geometry:d,properties:s},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:V.Commit}))return;this.store.delete([].concat(this.midPoints.ids,this.selectionPoints.ids)),this.store.updateGeometry([{id:n,geometry:d}]),this.selectionPoints.create(c,d.type,n),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(c,n,this.coordinatePrecision)}}}}},i.select=function(t,e){if(void 0===e&&(e=!0),this.selected[0]!==t){var i=this.store.getPropertiesCopy(t),o=this.flags[i.mode];if(o&&o.feature){var n=this.selected[0];if(n){if(n===t)return;this.deselect()}e&&this.setCursor(this.cursors.pointerOver),this.selected=[t],this.store.updateProperty([{id:t,property:"selected",value:!0}]),this.onSelect(t);var r=this.store.getGeometryCopy(t),s=r.type,a=r.coordinates;if("LineString"===s||"Polygon"===s){var l="LineString"===s?a:a[0];l&&o&&o.feature.coordinates&&(this.selectionPoints.create(l,s,t),o.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,o=e.clickedMidPoint;if(this.selected.length&&o)this.midPoints.insert(o.id,this.coordinatePrecision);else if(i&&i.id)this.select(i.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect()},i.start=function(){this.setStarted(),this.setSelecting()},i.stop=function(){this.cleanUp(),this.setStarted(),this.setStopped()},i.onClick=function(t){"right"!==t.button?"left"===t.button&&this.onLeftClick(t):this.onRightClick(t)},i.canScale=function(t){return this.keyEvents.scale&&this.keyEvents.scale.every(function(e){return t.heldKeys.includes(e)})},i.canRotate=function(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(function(e){return t.heldKeys.includes(e)})},i.preventDefaultKeyEvent=function(t){var e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()},i.onKeyDown=function(t){this.preventDefaultKeyEvent(t)},i.onKeyUp=function(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;this.onDeselect(this.selected[0]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()},i.cleanUp=function(){this.selected.length&&this.deselect()},i.onDragStart=function(t,e){if(this.selected.length){var i=this.store.getPropertiesCopy(this.selected[0]),o=this.flags[i.mode];if(o&&o.feature&&(o.feature.draggable||o.feature.coordinates&&o.feature.coordinates.draggable||o.feature.coordinates&&o.feature.coordinates.resizable)){this.dragEventCount=0;var n=this.selected[0],r=this.dragCoordinate.getDraggableIndex(t,n);return o&&o.feature&&o.feature.coordinates&&(o.feature.coordinates.draggable||o.feature.coordinates.resizable)&&-1!==r?(this.setCursor(this.cursors.dragStart),o.feature.coordinates.resizable?this.dragCoordinateResizeFeature.startDragging(n,r):this.dragCoordinate.startDragging(n,r),void e(!1)):o&&o.feature&&o.feature.draggable&&this.dragFeature.canDrag(t,n)?(this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,n),void e(!1)):void 0}}},i.onDrag=function(t,e){var i=this.selected[0];if(i){var o=this.store.getPropertiesCopy(i),n=this.flags[o.mode],r=!0===(n&&n.feature&&n.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){var s=this.validations[o.mode];if(n&&n.feature&&n.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i,s);if(n&&n.feature&&n.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i,s);if(this.dragCoordinateResizeFeature.isDragging()&&n.feature&&n.feature.coordinates&&n.feature.coordinates.resizable){if("globe"===this.projection)throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,n.feature.coordinates.resizable,s)}this.dragCoordinate.isDragging()?this.dragCoordinate.drag(t,r,s):this.dragFeature.isDragging()?this.dragFeature.drag(t,s):e(!0)}}},i.onDragEnd=function(t,e){this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0)},i.onMouseMove=function(t){var e=this;if(this.selected.length){if(!this.dragFeature.isDragging()){var i=!1;this.midPoints.ids.forEach(function(o){if(!i){var n=e.store.getGeometryCopy(o);e.pixelDistance.measure(t,n.coordinates)<e.pointerDistance&&(i=!0)}});var o=!1;if(this.selectionPoints.ids.forEach(function(n){var r=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,r.coordinates)<e.pointerDistance&&(i=!1,o=!0)}),i)this.setCursor(this.cursors.insertMidpoint);else{var n=this.featuresAtMouseEvent.find(t,!0).clickedFeature;this.setCursor(this.selected.length>0&&(n&&n.id===this.selected[0]||o)?this.cursors.pointerOver:"unset")}}}else this.setCursor("unset")},i.styleFeature=function(t){var e=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[U]){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}(J),oe=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,o=new Array(i),n=0;n<i;n++)o[n]=arguments[n];return(e=t.call.apply(t,[this].concat(o))||this).type=R.Static,e.mode="static",e}n(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}(H);function ne(t,e,i,o,n){for(;o>i;){if(o-i>600){var r=o-i+1,s=e-i+1,a=Math.log(r),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(r-l)/r)*(s-r/2<0?-1:1);ne(t,e,Math.max(i,Math.floor(e-s*l/r+c)),Math.min(o,Math.floor(e+(r-s)*l/r+c)),n)}var d=t[e],u=i,h=o;for(re(t,i,e),n(t[o],d)>0&&re(t,i,o);u<h;){for(re(t,u,h),u++,h--;n(t[u],d)<0;)u++;for(;n(t[h],d)>0;)h--}0===n(t[i],d)?re(t,i,h):re(t,++h,o),h<=e&&(i=h+1),e<=h&&(o=h-1)}}function re(t,e,i){var o=t[e];t[e]=t[i],t[i]=o}function se(t,e){ae(t,0,t.children.length,e,t)}function ae(t,e,i,o,n){n||(n=fe([])),n.minX=Infinity,n.minY=Infinity,n.maxX=-Infinity,n.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];le(n,t.leaf?o(s):s)}return n}function le(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 ce(t,e){return t.minX-e.minX}function de(t,e){return t.minY-e.minY}function ue(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function he(t){return t.maxX-t.minX+(t.maxY-t.minY)}function ge(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function pe(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function fe(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function ye(t,e,i,o,n){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=o)){var s=e+Math.ceil((i-e)/o/2)*o;ne(t,s,e,i,n),r.push(e,s,s,i)}}var ve=/*#__PURE__*/function(){function t(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}var e=t.prototype;return e.search=function(t){var e=this.data,i=[];if(!pe(t,e))return i;for(var o=this.toBBox,n=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?o(s):s;pe(t,a)&&(e.leaf?i.push(s):ge(t,a)?this._all(s,i):n.push(s))}e=n.pop()}return i},e.collides=function(t){var e=this.data;if(pe(t,e))for(var i=[];e;){for(var o=0;o<e.children.length;o++){var n=e.children[o],r=e.leaf?this.toBBox(n):n;if(pe(t,r)){if(e.leaf||ge(t,r))return!0;i.push(n)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var o=this.data;this.data=i,i=o}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=fe([])},e.remove=function(t){for(var e,i,o=this.data,n=this.toBBox(t),r=[],s=[],a=!1;o||r.length;){if(o||(o=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),o.leaf){var l=o.children.indexOf(t);-1!==l&&(o.children.splice(l,1),r.push(o),this._condense(r))}a||o.leaf||!ge(o,n)?i?(e++,o=i.children[e],a=!1):o=null:(r.push(o),s.push(e),e=0,i=o,o=o.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,o){var n,r=i-e+1,s=this._maxEntries;if(r<=s)return se(n=fe(t.slice(e,i+1)),this.toBBox),n;o||(o=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,o-1))),(n=fe([])).leaf=!1,n.height=o;var a=Math.ceil(r/s),l=a*Math.ceil(Math.sqrt(s));ye(t,e,i,l,this.compareMinX);for(var c=e;c<=i;c+=l){var d=Math.min(c+l-1,i);ye(t,c,d,a,this.compareMinY);for(var u=c;u<=d;u+=a){var h=Math.min(u+a-1,d);n.children.push(this._build(t,u,h,o-1))}}return se(n,this.toBBox),n},e._chooseSubtree=function(t,e,i,o){for(;o.push(e),!e.leaf&&o.length-1!==i;){for(var n=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var l=e.children[a],c=ue(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,n=c<n?c:n,s=l):d===r&&c<n&&(n=c,s=l)}e=s||e.children[0]}var u,h;return e},e._insert=function(t,e,i){var o=i?t:this.toBBox(t),n=[],r=this._chooseSubtree(o,this.data,e,n);for(r.children.push(t),le(r,o);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(o,n,e)},e._split=function(t,e){var i=t[e],o=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,o);var r=this._chooseSplitIndex(i,n,o),s=fe(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,se(i,this.toBBox),se(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=fe([t,e]),this.data.height=t.height+1,this.data.leaf=!1,se(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var o,n,r,s,a,l,c,d=Infinity,u=Infinity,h=e;h<=i-e;h++){var g=ae(t,0,h,this.toBBox),p=ae(t,h,i,this.toBBox),f=(n=g,r=p,s=Math.max(n.minX,r.minX),a=Math.max(n.minY,r.minY),l=Math.min(n.maxX,r.maxX),c=Math.min(n.maxY,r.maxY),Math.max(0,l-s)*Math.max(0,c-a)),y=ue(g)+ue(p);f<d?(d=f,o=h,u=y<u?y:u):f===d&&y<u&&(u=y,o=h)}return o||i-e},e._chooseSplitAxis=function(t,e,i){var o=t.leaf?this.compareMinX:ce,n=t.leaf?this.compareMinY:de;this._allDistMargin(t,e,i,o)<this._allDistMargin(t,e,i,n)&&t.children.sort(o)},e._allDistMargin=function(t,e,i,o){t.children.sort(o);for(var n=this.toBBox,r=ae(t,0,e,n),s=ae(t,i-e,i,n),a=he(r)+he(s),l=e;l<i-e;l++){var c=t.children[l];le(r,t.leaf?n(c):c),a+=he(r)}for(var d=i-e-1;d>=e;d--){var u=t.children[d];le(s,t.leaf?n(u):u),a+=he(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var o=i;o>=0;o--)le(e[o],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():se(t[i],this.toBBox)},t}(),me=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new ve(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}var e=t.prototype;return e.setMaps=function(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)},e.toBBox=function(t){var e,i=[],o=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var n=0;n<e.length;n++)o.push(e[n][1]),i.push(e[n][0]);var r=Math.min.apply(Math,o),s=Math.max.apply(Math,o);return{minX:Math.min.apply(Math,i),minY:r,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],o=new Set;t.forEach(function(t){var n=e.toBBox(t);if(e.setMaps(t,n),o.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);o.add(String(t.id)),i.push(n)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),Ce={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}},Pe=/*#__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 me,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:Ce}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 o=this.clone(t);o.forEach(function(t){null==t.id&&(t.id=i.idStrategy.getId()),i.tracked&&(t.properties.createdAt?K(t.properties.createdAt):t.properties.createdAt=+new Date,t.properties.updatedAt?K(t.properties.updatedAt):t.properties.updatedAt=+new Date)});var n=[];o.forEach(function(t){var o=t.id;if(e&&!e(t))throw new Error("Feature "+o+" is not valid: "+JSON.stringify(t));if(i.has(o))throw new Error("Feature already exists with this id: "+o);i.store[o]=t,n.push(o)}),this.spatialIndex.load(o),this._onChange(n,"create")}},e.search=function(t,e){var i=this,o=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?o.filter(e):o)},e.registerOnChange=function(t){this._onChange=function(e,i){t(e,i)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t){var e=this,i=[];t.forEach(function(t){var o=t.id,n=t.property,r=t.value,s=e.store[o];if(!s)throw new Error("No feature with this ("+o+"), can not update geometry");i.push(o),s.properties[n]=r,e.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.updateGeometry=function(t){var e=this,i=[];t.forEach(function(t){var o=t.id,n=t.geometry;i.push(o);var r=e.store[o];if(!r)throw new Error("No feature with this ("+o+"), can not update geometry");r.geometry=e.clone(n),e.spatialIndex.update(r),e.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.create=function(t){var e=this,i=[];return t.forEach(function(t){var 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 _e(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(Se(e[0]));for(var o=1;o<e.length;o++)i-=Math.abs(Se(e[o]))}return i}var xe=q*q/2,Me=Math.PI/180;function Se(t){var e=t.length;if(e<=2)return 0;for(var i=0,o=0;o<e;)i+=(t[o+2>=e?(o+2)%e:o+2][0]*Me-t[o][0]*Me)*Math.sin(t[o+1===e?0:o+1][1]*Me),o++;return i*xe}function be(t,e,i){var o=St(t,e),n=St(e,i)-o;return n<0&&(n+=360),180-Math.abs(n-90-90)}var we=/*#__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}n(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,o,n,r,s=this.store.getGeometryCopy(this.currentId).coordinates[0];if(1===this.currentCoordinate){var l=1/Math.pow(10,this.coordinatePrecision-1),c=Math.max(1e-6,l);e=[s[0],[t.lng,t.lat],[t.lng,t.lat-c],s[0]]}else if(2===this.currentCoordinate){var d=s[0],u=s[1],h=At(d,u,this.coordinatePrecision,this.project,this.unproject),g=nt(d[0],d[1]),p=nt(h[0],h[1]),f=nt(u[0],u[1]),y=nt(t.lng,t.lat),v=a(y,g)<a(y,f),m=be(g,p,y),C=v?90-m:be(g,p,y)-90,P=a(p,y),_=Math.cos($(C))*P,x=St(g,f)+("right"==((r=((n=y).x-(o=f).x)*((i=g).y-o.y)-(n.y-o.y)*(i.x-o.x))>1e-10?"left":r<-1e-10?"right":"left")?-90:90),M=xt(g,_,x),S=xt(f,_,x),b=rt(M.x,M.y),w=rt(S.x,S.y);e=[s[0],s[1],[w.lng,w.lat],[b.lng,b.lat],s[0]]}e&&this.updatePolygonGeometry(this.currentId,e,V.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i})||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(Ft([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]],V.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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ht(e,this.coordinatePrecision)},e}(H);function Ee(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var Ie=/*#__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}n(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 o=1/Math.pow(10,this.coordinatePrecision-1),n=Math.max(1e-6,o);e=[i[0],[t.lng,t.lat],[t.lng,t.lat-n],i[0]]}else if(2===this.currentCoordinate){var r=i[0],l=i[1],c=[t.lng,t.lat],d=nt(r[0],r[1]),u=nt(l[0],l[1]),h=nt(c[0],c[1]);if(void 0===this.direction){var g=Ee(d,u,h);this.direction=g?"clockwise":"anticlockwise"}var p,f=a(d,u),y=St(d,u),v=St(d,h),m=this.arcPoints,C=[r],P=bt(y),_=bt(v);"anticlockwise"===this.direction?(p=_-P)<0&&(p+=360):(p=P-_)<0&&(p+=360);var x=("anticlockwise"===this.direction?1:-1)*p/m;C.push(l);for(var M=0;M<=m;M++){var S=xt(d,f,P+M*x),b=rt(S.x,S.y),w=b.lat,E=[s(b.lng,this.coordinatePrecision),s(w,this.coordinatePrecision)];E[0]!==C[C.length-1][0]&&E[1]!==C[C.length-1][1]&&C.push(E)}C.push(r),e=[].concat(C)}e&&this.updatePolygonGeometry(this.currentId,e,V.Provisional)}},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i})||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var i=this.store.getGeometryCopy(this.currentId);if(Ft([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]],V.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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ht(e,this.coordinatePrecision)},e}(H),De=/*#__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}n(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,o=e[0],n=[t.lng,t.lat],r=nt(o[0],o[1]),l=nt(n[0],n[1]),c=nt(i[0],i[1]),d=a(c,r);if(void 0===this.direction){var u=Ee(c,r,l);this.direction=u?"clockwise":"anticlockwise"}var h,g=St(c,r),p=St(c,l),f=this.arcPoints,y=[o],v=bt(g),m=bt(p);"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 _=xt(c,d,v+P*C),x=rt(_.x,_.y),M=x.lat,S=[s(x.lng,this.coordinatePrecision),s(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,V.Provisional)}else if(3===this.currentCoordinate){var b=this.store.getGeometryCopy(this.currentInitialArcId).coordinates;if(b.length<2)return;if(!this.direction)return;var w=this.store.getGeometryCopy(this.currentStartingPointId).coordinates,E=b[0],I=b[b.length-1],D=nt(t.lng,t.lat),F=nt(E[0],E[1]),k=nt(I[0],I[1]),O=nt(w[0],w[1]),j=a(O,F),L=a(O,D)<j?F:D,W=St(O,D),B=St(O,F),G=St(O,k),N=bt(B),A=bt(G),T=bt(W);if(this.notInSector({normalizedCursor:T,normalizedStart:N,normalizedEnd:A,direction:this.direction}))return;for(var R=this.getDeltaBearing(this.direction,N,A),U=this.arcPoints,X=("anticlockwise"===this.direction?1:-1)*R/U,z=a(O,L),Y=[],K=0;K<=U;K++){var H=xt(O,z,N+K*X),J=rt(H.x,H.y),Z=J.lat,q=[s(J.lng,this.coordinatePrecision),s(Z,this.coordinatePrecision)];q[0]!==b[b.length-1][0]&&q[1]!==b[b.length-1][1]&&Y.unshift(q)}if(b.push.apply(b,Y),b.push(b[0]),this.currentId)this.updatePolygonGeometry(this.currentId,b,V.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 o={type:"LineString",coordinates:e};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i})||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.updatePolygonGeometry=function(t,e,i){var o={type:"Polygon",coordinates:[e]};return!(this.validate&&!this.validate({type:"Feature",geometry:o},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:i})||(this.store.updateGeometry([{id:t,geometry:o}]),0))},i.onClick=function(t){if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}]);this.currentStartingPointId=e[0],this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentStartingPointId){var i=this.store.create([{geometry:{type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},properties:{mode:this.mode}}]);this.currentInitialArcId=i[0],this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){try{this.currentStartingPointId&&this.store.delete([this.currentStartingPointId]),this.currentInitialArcId&&this.store.delete([this.currentInitialArcId]),this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=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(e){return!!t.prototype.validateFeature.call(this,e)&&e.properties.mode===this.mode&&ht(e,this.coordinatePrecision)},i.getDeltaBearing=function(t,e,i){var o;return"anticlockwise"===t?(o=i-e)<0&&(o+=360):(o=e-i)<0&&(o+=360),o},i.notInSector=function(t){var e=t.normalizedCursor,i=t.normalizedStart,o=t.normalizedEnd;return"clockwise"===t.direction?i<=o?e>=i&&e<=o:e>=i||e<=o:i>=o?e<=i&&e>=o:e<=i||e>=o},e}(H),Fe={TerraDrawBaseDrawMode:H,TerraDrawBaseAdapter:c};exports.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 oe;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===R.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 Pe({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var s=function(t){var i=[],o=e._store.copyAll().filter(function(e){return!t.includes(e.id)||(i.push(e),!1)});return{changed:i,unchanged:o}},a=function(t,i){e._enabled&&e._eventListeners.finish.forEach(function(e){e(t,i)})},l=function(t,i){if(e._enabled){e._eventListeners.change.forEach(function(e){e(t,i)});var o=s(t),n=o.changed,r=o.unchanged;"create"===i?e._adapter.render({created:n,deletedIds:[],unchanged:r,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:r,updated:n},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:r,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:r,updated:[]},e.getModeStyles())}},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]),o=i.changed;o&&e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:o},e.getModeStyles())}};Object.keys(this._modes).forEach(function(t){e._modes[t].register({mode:t,store:e._store,setCursor:e._adapter.setCursor.bind(e._adapter),project:e._adapter.project.bind(e._adapter),unproject:e._adapter.unproject.bind(e._adapter),setDoubleClickToZoom:e._adapter.setDoubleClickToZoom.bind(e._adapter),onChange: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[U]?t._modes[t._instanceSelectMode].styleFeature.bind(t._modes[t._instanceSelectMode])(e):t._modes[i].styleFeature.bind(t._modes[i])(e)}}),e},e.featuresAtLocation=function(t,e){var i=t.lng,o=t.lat,n=e&&void 0!==e.pointerDistance?e.pointerDistance:30,r=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,s=this._adapter.unproject.bind(this._adapter),l=this._adapter.project.bind(this._adapter),c=l(i,o),d=vt({unproject:s,point:c,pointerDistance:n});return this._store.search(d).filter(function(t){if(r&&(t.properties[X]||t.properties.selectionPoint))return!1;if("Point"===t.geometry.type){var e=t.geometry.coordinates,s=l(e[0],e[1]);return a(c,s)<n}if("LineString"===t.geometry.type){for(var d=t.geometry.coordinates,u=0;u<d.length-1;u++){var h=d[u],g=d[u+1];if(Yt(c,l(h[0],h[1]),l(g[0],g[1]))<n)return!0}return!1}return!!zt([i,o],t.geometry.coordinates)||void 0})},e.getSelectMode=function(){if(this.checkEnabled(),!this._instanceSelectMode)throw new Error("No select mode defined in instance");return this.getMode()!==this._instanceSelectMode&&this.setMode(this._instanceSelectMode),this._modes[this._instanceSelectMode]},e.setModeStyles=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e},e.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)},i(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}]),t}(),exports.TerraDrawAngledRectangleMode=we,exports.TerraDrawArcGISMapsSDKAdapter=T,exports.TerraDrawCircleMode=pt,exports.TerraDrawExtend=Fe,exports.TerraDrawFreehandMode=ft,exports.TerraDrawGoogleMapsAdapter=d,exports.TerraDrawLeafletAdapter=u,exports.TerraDrawLineStringMode=kt,exports.TerraDrawMapLibreGLAdapter=g,exports.TerraDrawMapboxGLAdapter=h,exports.TerraDrawOpenLayersAdapter=A,exports.TerraDrawPointMode=jt,exports.TerraDrawPolygonMode=Wt,exports.TerraDrawRectangleMode=Bt,exports.TerraDrawRenderMode=Gt,exports.TerraDrawSectorMode=Ie,exports.TerraDrawSelectMode=ie,exports.TerraDrawSensorMode=De,exports.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"===t.geometry.type&&_e(t.geometry)<e},exports.ValidateMinAreaSquareMeters=function(t,e){return"Polygon"===t.geometry.type&&_e(t.geometry)>e},exports.ValidateNotSelfIntersecting=function(t){return("Polygon"===t.geometry.type||"LineString"===t.geometry.type)&&!lt(t)};
|
|
2
2
|
//# sourceMappingURL=terra-draw.cjs.map
|