terra-draw 0.0.1-alpha.8 → 0.0.1-alpha.9
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/modes/freehand/freehand.mode.d.ts +7 -3
- 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
|
@@ -10,17 +10,21 @@ declare type FreehandPolygonStyling = {
|
|
|
10
10
|
outlineColor: HexColor;
|
|
11
11
|
outlineWidth: number;
|
|
12
12
|
fillOpacity: number;
|
|
13
|
+
closingPointColor: HexColor;
|
|
14
|
+
closingPointWidth: number;
|
|
15
|
+
closingPointOutlineColor: HexColor;
|
|
16
|
+
closingPointOutlineWidth: number;
|
|
13
17
|
};
|
|
14
18
|
export declare class TerraDrawFreehandMode extends TerraDrawBaseDrawMode<FreehandPolygonStyling> {
|
|
15
19
|
mode: string;
|
|
16
20
|
private startingClick;
|
|
17
21
|
private currentId;
|
|
18
|
-
private
|
|
19
|
-
private
|
|
22
|
+
private closingPointId;
|
|
23
|
+
private minDistance;
|
|
20
24
|
private keyEvents;
|
|
21
25
|
constructor(options?: {
|
|
22
26
|
styles?: Partial<FreehandPolygonStyling>;
|
|
23
|
-
|
|
27
|
+
minDistance?: number;
|
|
24
28
|
keyEvents?: TerraDrawFreehandModeKeyEvents;
|
|
25
29
|
});
|
|
26
30
|
private close;
|
package/dist/terra-draw.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function e(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},i.apply(this,arguments)}function n(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,o(t,e)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function r(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var s=/*#__PURE__*/function(){function t(t){var e=this;this._heldKeys=new Set,this._cursor=void 0,this._cursorStyleSheet=void 0,this._coordinatePrecision=void 0,this._lib=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onMouseMoveCallback=void 0,this._onClickListener=void 0,this._onRightClickListener=void 0,this._onClickCallback=void 0,this._onKeyUpListener=void 0,this._onDragStartListener=void 0,this._onDragListener=void 0,this._onDragEndListener=void 0,this._layers=!1,this.getMapContainer=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.getMapContainer=function(){return e._map.getDiv()},this.project=function(t,i){var n=e._map.getBounds();if(void 0===n)throw new Error("cannot get bounds");var o=new e._lib.LatLng(n.getNorthEast().lat(),n.getSouthWest().lng()),r=e._map.getProjection();if(void 0===r)throw new Error("cannot get projection");var s=r.fromLatLngToPoint(o);if(null===s)throw new Error("cannot get projectedNorthWest");var a=r.fromLatLngToPoint({lng:t,lat:i});if(null===a)throw new Error("cannot get projected lng lat");var l=e._map.getZoom();if(void 0===l)throw new Error("cannot get zoom");var c=Math.pow(2,l);return{x:Math.floor((a.x-s.x)*c),y:Math.floor((a.y-s.y)*c)}},this.unproject=function(t,i){var n=e._map.getProjection();if(void 0===n)throw new Error("cannot get projection");var o=e._map.getBounds();if(void 0===o)throw new Error("cannot get bounds");var r=n.fromLatLngToPoint(o.getNorthEast());if(null===r)throw new Error("cannot get topRight");var s=n.fromLatLngToPoint(o.getSouthWest());if(null===s)throw new Error("cannot get bottomLeft");var a=e._map.getZoom();if(void 0===a)throw new Error("zoom get bounds");var l=Math.pow(2,a),c=new google.maps.Point(t/l+s.x,i/l+r.y),h=n.fromPointToLatLng(c);if(null===h)throw new Error("zoom get bounds");return{lng:h.lng(),lat:h.lat()}},this.setCursor=function(t){if(t!==e._cursor){if(e._cursorStyleSheet&&(e._cursorStyleSheet.remove(),e._cursorStyleSheet=void 0),"unset"!==t){var i=e.getMapContainer(),n=document.createElement("style");n.type="text/css",n.innerHTML="#"+i.id+' [aria-label="Map"] { cursor: '+t+" !important; }",document.getElementsByTagName("head")[0].appendChild(n),e._cursorStyleSheet=n}e._cursor=t}}}var e=t.prototype;return e.circlePath=function(t,e,i){return"M "+t+" "+e+" m -"+i+", 0 a "+i+","+i+" 0 1,0 "+2*i+",0 a "+i+","+i+" 0 1,0 -"+2*i+",0"},e.register=function(t){var e=this;this._onClickCallback=function(i){i.latLng&&t.onClick({lng:r(i.latLng.lng(),e._coordinatePrecision),lat:r(i.latLng.lat(),e._coordinatePrecision),containerX:i.domEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.domEvent.clientY-e.getMapContainer().offsetTop,button:0===i.domEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._onClickListener=this._map.addListener("click",this._onClickCallback),this._onRightClickListener=this._map.addListener("rightclick",this._onClickCallback),this._onMouseMoveCallback=function(i){i.latLng&&t.onMouseMove({lng:r(i.latLng.lng(),e._coordinatePrecision),lat:r(i.latLng.lat(),e._coordinatePrecision),containerX:i.domEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.domEvent.clientY-e.getMapContainer().offsetTop,button:0===i.domEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._onMouseMoveListener=this._map.addListener("mousemove",this._onMouseMoveCallback),this._onKeyUpListener=function(e){t.onKeyUp({key:e.key})},this.getMapContainer().addEventListener("keyup",this._onKeyUpListener);var i="not-dragging";this._onDragStartListener=function(t){i="pre-dragging"};var n=this.getMapContainer();n.addEventListener("mousedown",this._onDragStartListener),this._onDragListener=function(o){var s={x:o.clientX-n.offsetLeft,y:o.clientY-n.offsetTop},a=e.unproject(s.x,s.y),l=a.lat,c={lng:r(a.lng,e._coordinatePrecision),lat:r(l,e._coordinatePrecision),containerX:o.clientX-n.offsetLeft,containerY:o.clientY-n.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)};"pre-dragging"===i?(i="dragging",t.onDragStart(c,function(t){e._map.setOptions({draggable:!1})})):"dragging"===i&&t.onDrag(c)},n.addEventListener("mousemove",this._onDragListener),this._onDragEndListener=function(o){if("dragging"===i){var s={x:o.clientX-n.offsetLeft,y:o.clientY-n.offsetTop},a=e.unproject(s.x,s.y),l=a.lat;t.onDragEnd({lng:r(a.lng,e._coordinatePrecision),lat:r(l,e._coordinatePrecision),containerX:o.clientX-n.offsetLeft,containerY:o.clientY-n.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)},function(t){e._map.setOptions({draggable:t})})}i="not-dragging"},n.addEventListener("mouseup",this._onDragEndListener)},e.unregister=function(){this._onClickListener&&(this._onClickCallback=void 0,this._onClickListener.remove(),this._onClickListener=void 0),this._onRightClickListener&&(this._onClickCallback=void 0,this._onRightClickListener.remove(),this._onRightClickListener=void 0),this._onMouseMoveListener&&(this._onMouseMoveCallback=void 0,this._onMouseMoveListener.remove(),this._onMouseMoveListener=void 0),this._onKeyUpListener&&(this.getMapContainer().removeEventListener("keyup",this._onKeyUpListener),this._onKeyUpListener=void 0)},e.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)}),t.updated.forEach(function(t){if(!t||!t.id)throw new Error("Feature is not valid");var e=i._map.data.getFeatureById(t.id);if(!e)throw new Error("Feature could not be found by Google Maps API");switch(e.forEachProperty(function(t,i){e.setProperty(i,void 0)}),Object.keys(t.properties).forEach(function(i){e.setProperty(i,t.properties[i])}),t.geometry.type){case"Point":var n=t.geometry.coordinates;e.setGeometry(new google.maps.Data.Point(new google.maps.LatLng(n[1],n[0])));break;case"LineString":for(var o=t.geometry.coordinates,r=[],s=0;s<o.length;s++){var a=o[s],l=new google.maps.LatLng(a[1],a[0]);r.push(l)}e.setGeometry(new google.maps.Data.LineString(r));break;case"Polygon":for(var c=t.geometry.coordinates,h=[],d=0;d<c.length;d++){for(var u=[],p=0;p<c[d].length;p++){var g=new google.maps.LatLng(c[d][p][1],c[d][p][0]);u.push(g)}h.push(u)}e.setGeometry(new google.maps.Data.Polygon(h))}}),t.created.forEach(function(t){i._map.data.addGeoJson(t)})):(this._map.data.addListener("click",function(t){i._onClickCallback&&i._onClickCallback(t)}),this._map.data.addListener("mousemove",function(t){i._onMouseMoveCallback&&i._onMouseMoveCallback(t)}));var n={type:"FeatureCollection",features:[].concat(t.created)};this._map.data.addGeoJson(n),this._map.data.setStyle(function(t){var n=t.getProperty("mode"),o=t.getGeometry();if(!o)throw new Error("Google Maps geometry not found");var r=o.getType(),s={};t.forEachProperty(function(t,e){s[e]=t});var a=e[n]({type:"Feature",geometry:{type:r,coordinates:[]},properties:s});switch(r){case"Point":return{clickable:!1,icon:{path:i.circlePath(0,0,a.pointWidth),fillColor:a.pointColor,fillOpacity:1,strokeColor:a.pointOutlineColor,strokeWeight:a.pointOutlineWidth,rotation:0,scale:1}};case"LineString":return{strokeColor:a.lineStringColor,strokeWeight:a.lineStringWidth};case"Polygon":return{strokeColor:a.polygonOutlineColor,strokeWeight:a.polygonOutlineWidth,fillOpacity:a.polygonFillOpacity,fillColor:a.polygonFillColor}}throw Error("Unknown feature type")}),this._layers=!0},t}(),a=/*#__PURE__*/function(){function t(t){var e=this;this._heldKeys=new Set,this._lib=void 0,this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onKeyUpListener=void 0,this._onKeyDownListener=void 0,this._onDragStartListener=void 0,this._onDragListener=void 0,this._onDragEndListener=void 0,this._layer=void 0,this._panes={},this.project=void 0,this.unproject=void 0,this.setCursor=void 0,this.getMapContainer=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.getMapContainer=function(){return e._map.getContainer()},this.project=function(t,i){var n=e._map.latLngToContainerPoint({lng:t,lat:i});return{x:n.x,y:n.y}},this.unproject=function(t,i){var n=e._map.containerPointToLatLng({x:t,y:i});return{lng:n.lng,lat:n.lat}},this.setCursor=function(t){"unset"===t?e.getMapContainer().style.removeProperty("cursor"):e.getMapContainer().style.cursor=t}}var e=t.prototype;return e.createPaneStyleSheet=function(t,e){var i=document.createElement("style");return i.type="text/css",i.innerHTML=".leaflet-"+t+" {z-index: "+e+";}",document.getElementsByTagName("head")[0].appendChild(i),this._map.createPane(t),i},e.register=function(t){var e=this,i=this.getMapContainer(),n="not-dragging";this._onClickListener=function(i){"not-dragging"!==n&&"pre-dragging"!==n||t.onClick({lng:r(i.latlng.lng,e._coordinatePrecision),lat:r(i.latlng.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-e.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._map.on("mouseup",this._onClickListener),this._map.on("contextmenu",this._onClickListener),this._onMouseMoveListener=function(i){i.originalEvent.preventDefault(),t.onMouseMove({lng:r(i.latlng.lng,e._coordinatePrecision),lat:r(i.latlng.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-e.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._map.on("mousemove",this._onMouseMoveListener),this._onDragStartListener=function(t){n="pre-dragging"},i.addEventListener("pointerdown",this._onDragStartListener),this._onDragListener=function(o){var s=e._map.containerPointToLatLng({x:o.clientX-i.offsetLeft,y:o.clientY-i.offsetTop}),a=s.lat,l={lng:r(s.lng,e._coordinatePrecision),lat:r(a,e._coordinatePrecision),containerX:o.clientX-i.offsetLeft,containerY:o.clientY-i.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)};"pre-dragging"===n?(n="dragging",t.onDragStart(l,function(t){t?e._map.dragging.enable():e._map.dragging.disable()})):"dragging"===n&&t.onDrag(l)},i.addEventListener("pointermove",this._onDragListener),this._onDragEndListener=function(o){if(o.preventDefault(),"dragging"===n){var s=e._map.containerPointToLatLng({x:o.clientX-i.offsetLeft,y:o.clientY-i.offsetTop}),a=s.lat;return t.onDragEnd({lng:r(s.lng,e._coordinatePrecision),lat:r(a,e._coordinatePrecision),containerX:o.clientX-i.offsetLeft,containerY:o.clientY-i.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)},function(t){t?e._map.dragging.enable():e._map.dragging.disable()}),n="after-dragging",void e._map.dragging.enable()}n="not-dragging",e._map.dragging.enable()},i.addEventListener("pointerup",this._onDragEndListener),this._onKeyUpListener=function(i){i.preventDefault(),e._heldKeys.delete(i.key),t.onKeyUp({key:i.key})},i.addEventListener("keyup",this._onKeyUpListener),this._onKeyDownListener=function(i){i.preventDefault(),e._heldKeys.add(i.key),t.onKeyDown({key:i.key})},i.addEventListener("keydown",this._onKeyDownListener)},e.unregister=function(){var t=this;this._onClickListener&&(this._map.off("contextmenu",this._onClickListener),this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0),Object.keys(this._panes).forEach(function(e){var i=t._map.getPane(e);i&&i.remove()})},e.render=function(t,e){var i=this,n=[].concat(t.created,t.updated,t.unchanged);this._layer&&this._map.removeLayer(this._layer);var o=this._lib.geoJSON({type:"FeatureCollection",features:n},{pointToLayer:function(t,n){if(!t.properties)throw new Error("Feature has no properties");if("string"!=typeof t.properties.mode)throw new Error("Feature mode is not a string");var o=(0,e[t.properties.mode])(t),r=String(o.zIndex);return i._panes[r]||(i._panes[r]=i.createPaneStyleSheet(r,o.zIndex)),i._lib.circleMarker(n,{radius:o.pointWidth,stroke:o.pointOutlineWidth||!1,color:o.pointOutlineColor,weight:o.pointOutlineWidth,fillOpacity:.8,fillColor:o.pointColor,pane:r,interactive:!1})},style:function(t){if(!t||!t.properties)return{};var i=t,n=(0,e[i.properties.mode])(i);return"LineString"===i.geometry.type?{interactive:!1,color:n.lineStringColor,weight:n.lineStringWidth}:"Polygon"===i.geometry.type?{interactive:!1,fillOpacity:n.polygonFillOpacity,fillColor:n.polygonFillColor,weight:n.polygonOutlineWidth,stroke:!0,color:n.polygonFillColor}:{}}});this._map.addLayer(o),this._layer=o},t}(),l=/*#__PURE__*/function(){function t(t){var e=this;this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.getMapContainer=void 0,this._heldKeys=new Set,this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onDragStartListener=void 0,this._onDragListener=void 0,this._onDragEndListener=void 0,this._onKeyDownListener=void 0,this._onKeyUpListener=void 0,this._rendered={},this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,i){var n=e._map.project({lng:t,lat:i});return{x:n.x,y:n.y}},this.unproject=function(t,i){var n=e._map.unproject({x:t,y:i});return{lng:n.lng,lat:n.lat}},this.setCursor=function(t){e._map.getCanvas().style.cursor=t},this.getMapContainer=function(){return e._map.getContainer()}}var e=t.prototype;return e._addGeoJSONSource=function(t,e){this._map.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:e}})},e._addFillLayer=function(t,e){return this._map.addLayer({id:t,source:t,type:"fill",filter:["all",["match",["geometry-type"],"Polygon",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"fill-color":["get","polygonFillColor"],"fill-opacity":["get","polygonFillOpacity"]}})},e._addFillOutlineLayer=function(t,e,i){var n=this._map.addLayer({id:t+"outline",source:t,type:"line",filter:["all",["match",["geometry-type"],"Polygon",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"line-width":["get","polygonOutlineWidth"],"line-color":["get","polygonOutlineColor"]}});return i&&this._map.moveLayer(t,i),n},e._addLineLayer=function(t,e,i){var n=this._map.addLayer({id:t,source:t,type:"line",filter:["all",["match",["geometry-type"],"LineString",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"line-width":["get","lineStringWidth"],"line-color":["get","lineStringColor"]}});return i&&this._map.moveLayer(t,i),n},e._addPointLayer=function(t,e,i){var n=this._map.addLayer({id:t,source:t,type:"circle",filter:["all",["match",["geometry-type"],"Point",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"circle-stroke-color":["get","pointOutlineColor"],"circle-stroke-width":["get","pointOutlineWidth"],"circle-radius":["get","pointWidth"],"circle-color":["get","pointColor"]}});return i&&this._map.moveLayer(t,i),n},e._addLayer=function(t,e,i,n){"Point"===i&&this._addPointLayer(t,e,n),"LineString"===i&&this._addLineLayer(t,e,n),"Polygon"===i&&(this._addFillLayer(t,e),this._addFillOutlineLayer(t,e,n))},e._addGeoJSONLayer=function(t,e,i){var n="td-"+t+"-"+e.toLowerCase();return this._addGeoJSONSource(n,i),this._addLayer(n,t,e),n},e._setGeoJSONLayerData=function(t,e,i){var n="td-"+t+"-"+e.toLowerCase();return this._map.getSource(n).setData({type:"FeatureCollection",features:i}),n},e.register=function(t){var e=this;this._onClickListener=function(i){t.onClick({lng:r(i.lngLat.lng,e._coordinatePrecision),lat:r(i.lngLat.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-e.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._map.on("click",this._onClickListener),this._map.on("contextmenu",this._onClickListener),this._onMouseMoveListener=function(i){t.onMouseMove({lng:r(i.lngLat.lng,e._coordinatePrecision),lat:r(i.lngLat.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-e.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._map.on("mousemove",this._onMouseMoveListener);var i="not-dragging";this._onDragStartListener=function(t){i="pre-dragging"};var n=this.getMapContainer();n.addEventListener("mousedown",this._onDragStartListener),this._onDragListener=function(o){var s=e._map.unproject({x:o.clientX-n.offsetLeft,y:o.clientY-n.offsetTop}),a=s.lat,l={lng:r(s.lng,e._coordinatePrecision),lat:r(a,e._coordinatePrecision),containerX:o.clientX-n.offsetLeft,containerY:o.clientY-n.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)};"pre-dragging"===i?(i="dragging",t.onDragStart(l,function(t){t?e._map.dragPan.enable():e._map.dragPan.disable()})):"dragging"===i&&t.onDrag(l)},n.addEventListener("mousemove",this._onDragListener),this._onDragEndListener=function(o){if("dragging"===i){var s=e._map.unproject({x:o.clientX-n.offsetLeft,y:o.clientY-n.offsetTop}),a=s.lat;t.onDragEnd({lng:r(s.lng,e._coordinatePrecision),lat:r(a,e._coordinatePrecision),containerX:o.clientX-n.offsetLeft,containerY:o.clientY-n.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)},function(t){t?e._map.dragPan.enable():e._map.dragPan.disable()})}i="not-dragging"},n.addEventListener("mouseup",this._onDragEndListener),this._onKeyUpListener=function(i){i.preventDefault(),e._heldKeys.delete(i.key),t.onKeyUp({key:i.key})},n.addEventListener("keyup",this._onKeyUpListener),this._onKeyDownListener=function(i){i.preventDefault(),e._heldKeys.add(i.key),t.onKeyDown({key:i.key})},n.addEventListener("keydown",this._onKeyDownListener)},e.unregister=function(){this._onClickListener&&(this._map.off("contextmenue",this._onClickListener),this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("mousemove",this._onMouseMoveListener),this._onMouseMoveListener=void 0),this._onKeyUpListener&&this._map.getCanvas().removeEventListener("keypress",this._onKeyUpListener),this._onDragStartListener&&this._map.getCanvas().removeEventListener("mousedown",this._onDragStartListener),this._onDragListener&&this._map.getCanvas().removeEventListener("mousemove",this._onDragListener),this._onDragEndListener&&this._map.getCanvas().removeEventListener("mouseup",this._onDragEndListener)},e.render=function(t,e){var i=this,n=[].concat(t.created,t.updated,t.unchanged),o={};Object.keys(e).forEach(function(t){o[t]||(o[t]={points:[],linestrings:[],polygons:[]})});for(var r=function(t){var i=n[t];Object.keys(e).forEach(function(t){var n=i.properties;if(n.mode===t){var r=e[t](i);"Point"===i.geometry.type?(n.pointColor=r.pointColor,n.pointOutlineColor=r.pointOutlineColor,n.pointOutlineWidth=r.pointOutlineWidth,n.pointWidth=r.pointWidth,o[t].points.push(i)):"LineString"===i.geometry.type?(n.lineStringColor=r.lineStringColor,n.lineStringWidth=r.lineStringWidth,o[t].linestrings.push(i)):"Polygon"===i.geometry.type&&(n.polygonFillColor=r.polygonFillColor,n.polygonFillOpacity=r.polygonFillOpacity,n.polygonOutlineColor=r.polygonOutlineColor,n.polygonOutlineWidth=r.polygonOutlineWidth,o[t].polygons.push(i))}})},s=0;s<n.length;s++)r(s);Object.keys(e).forEach(function(t){if(o[t]){var e=o[t],n=e.points,r=e.linestrings,s=e.polygons;if(i._rendered[t]){var a=i._setGeoJSONLayerData(t,"Point",n);i._setGeoJSONLayerData(t,"LineString",r),i._setGeoJSONLayerData(t,"Polygon",s),i._map.moveLayer(a)}else i._addGeoJSONLayer(t,"Point",n),i._addGeoJSONLayer(t,"LineString",r),i._addGeoJSONLayer(t,"Polygon",s),i._rendered[t]=!0}}),this._map.style&&(this._map._frame&&(this._map._frame.cancel(),this._map._frame=null),this._map._render())},t}();function c(t,e){var i=function(t){return t*Math.PI/180},n=i(t[1]),o=i(t[0]),r=i(e[1]),s=r-n,a=i(e[0])-o,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}function h(t){return t%360*Math.PI/180}function d(t){return t%(2*Math.PI)*180/Math.PI}function u(t,e,i){var n=h(t[0]),o=h(t[1]),r=h(i),s=function(t){return t/6371.0088}(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[d(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),d(a)]}function p(t){for(var e=t.center,i=t.radiusKilometers,n=t.steps?t.steps:64,o=[],r=0;r<n;r++)o.push(u(e,i,-360*r/n));return o.push(o[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[o]},properties:{}}}var g=/*#__PURE__*/function(){var t=n.prototype;function n(t){this._state=void 0,this._styles=void 0,this.behaviors=[],this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.onStyleChange=void 0,this.store=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this._state="unregistered",this._styles=t&&t.styles?i({},t.styles):{},this.pointerDistance=t&&t.pointerDistance||40,this.coordinatePrecision=t&&t.coordinatePrecision||9}return t.registerBehaviors=function(t){},t.setStarted=function(){if("stopped"!==this._state&&"registered"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="started"},t.setStopped=function(){if("started"!==this._state)throw new Error("Mode must be started to be stopped");this._state="stopped"},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.project=t.project,this.unproject=t.unproject,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect,this.setCursor=t.setCursor,this.onStyleChange=t.onChange,this.registerBehaviors({mode:t.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:this.coordinatePrecision})},t.onDeselect=function(t){},t.onSelect=function(t){},t.styleFeature=function(t){},e(n,[{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}}]),n}(),f=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="circle",i.center=void 0,i.clickCount=0,i.currentCircleId=void 0,i.keyEvents=void 0,i.keyEvents=e&&e.keyEvents?e.keyEvents:{cancel:"Escape",finish:"Enter"},i}n(e,t);var o=e.prototype;return o.close=function(){this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onClick=function(t){if(0===this.clickCount){this.center=[t.lng,t.lat];var e=p({center:this.center,radiusKilometers:1e-5}),i=this.store.create([{geometry:e.geometry,properties:{mode:this.mode}}]);this.currentCircleId=i[0],this.clickCount++}else this.close()},o.onMouseMove=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e=c(this.center,[t.lng,t.lat]),i=p({center:this.center,radiusKilometers:e});this.store.updateGeometry([{id:this.currentCircleId,geometry:i.geometry}])}},o.onKeyDown=function(){},o.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.cleanUp=function(){try{this.currentCircleId&&this.store.delete([this.currentCircleId])}catch(t){}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},o.styleFeature=function(t){var e=i({},{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?(this.styles.fillColor&&(e.polygonFillColor=this.styles.fillColor),this.styles.outlineColor&&(e.polygonOutlineColor=this.styles.outlineColor),this.styles.outlineWidth&&(e.polygonOutlineWidth=this.styles.outlineWidth),this.styles.fillOpacity&&(e.polygonFillOpacity=this.styles.fillOpacity),e):e},e}(g),y=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="freehand",i.startingClick=!1,i.currentId=void 0,i.skip=0,i.everyNthMouseEvent=void 0,i.keyEvents=void 0,i.everyNthMouseEvent=e&&e.everyNthMouseEvent||10,i.keyEvents=e&&e.keyEvents?e.keyEvents:{cancel:"Escape",finish:"Enter"},i}n(e,t);var o=e.prototype;return o.close=function(){this.startingClick=!1,this.currentId=void 0},o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onMouseMove=function(t){if(this.currentId&&!1!==this.startingClick){if(this.skip>this.everyNthMouseEvent){this.skip=0;var e=this.store.getGeometryCopy(this.currentId);e.coordinates[0].pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[].concat(e.coordinates[0],[[t.lng,t.lat],e.coordinates[0][0]])]}}])}this.skip++}},o.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}}]);return this.currentId=e[0],void(this.startingClick=!0)}this.close()},o.onKeyDown=function(){},o.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.startingClick=!1},o.styleFeature=function(t){var e=i({},{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?(this.styles.fillColor&&(e.polygonFillColor=this.styles.fillColor),this.styles.outlineColor&&(e.polygonOutlineColor=this.styles.outlineColor),this.styles.outlineWidth&&(e.polygonOutlineWidth=this.styles.outlineWidth),this.styles.fillOpacity&&(e.polygonFillOpacity=this.styles.fillOpacity),e):e},e}(g);function v(t){var e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}for(var i=[],n=0;n<e.length;n++)for(var o=0;o<e[n].length-1;o++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)l(n,o,r,s);return i.length>0;function a(t){return t<0||t>1}function l(t,n,o,r){var s,l=e[t][n],c=e[t][n+1],h=e[o][r],d=e[o][r+1],u=function(t,e,i,n){if(m(t,i)||m(t,n)||m(e,i)||m(n,i))return null;var o=t[0],r=t[1],s=e[0],a=e[1],l=i[0],c=i[1],h=n[0],d=n[1],u=(o-s)*(c-d)-(r-a)*(l-h);return 0===u?null:[((o*a-r*s)*(l-h)-(o-s)*(l*d-c*h))/u,((o*a-r*s)*(c-d)-(r-a)*(l*d-c*h))/u]}(l,c,h,d);null!==u&&(s=d[0]!==h[0]?(u[0]-h[0])/(d[0]-h[0]):(u[1]-h[1])/(d[1]-h[1]),a(c[0]!==l[0]?(u[0]-l[0])/(c[0]-l[0]):(u[1]-l[1])/(c[1]-l[1]))||a(s)||(u.toString(),i.push(u)))}}function m(t,e){return t[0]===e[0]&&t[1]===e[1]}var _=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.sqrt(n*n+i*i)},C=function(t){var e=t.store,i=t.mode,n=t.project,o=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision;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.store=e,this.mode=i,this.project=n,this.unproject=o,this.pointerDistance=r,this.coordinatePrecision=s},P=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.create=function(t){var e=t.containerX,i=t.containerY,n=this.pointerDistance/2;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[this.unproject(e-n,i-n),this.unproject(e+n,i-n),this.unproject(e+n,i+n),this.unproject(e-n,i+n),this.unproject(e-n,i-n)].map(function(t){return[t.lng,t.lat]})]}}},e}(C),M=/*#__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 _({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(C),L=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinate=function(t,e){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)})},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return n(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),o=this.store.search(n,e),r={coord:void 0,minDist:Infinity};return o.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}n.forEach(function(e){var n=i.pixelDistance.measure(t,e);n<r.minDist&&n<i.pointerDistance&&(r.coord=e)})}),r.coord},e}(C),x=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="linestring",i.currentCoordinate=0,i.currentId=void 0,i.closingPointId=void 0,i.allowSelfIntersections=void 0,i.keyEvents=void 0,i.snappingEnabled=void 0,i.snapping=void 0,i.snappingEnabled=!(!e||void 0===e.snapping)&&e.snapping,i.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections,i.keyEvents=e&&e.keyEvents?e.keyEvents:{cancel:"Escape",finish:"Enter"},i}n(e,t);var o=e.prototype;return o.close=function(){if(this.currentId){var t=this.store.getGeometryCopy(this.currentId);t.coordinates.pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[].concat(t.coordinates)}}]),this.closingPointId&&this.store.delete([this.closingPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0}},o.registerBehaviors=function(t){this.snapping=new L(t,new M(t),new P(t))},o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onMouseMove=function(t){if(this.setCursor("crosshair"),this.currentId&&0!==this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);e.coordinates.pop();var i=this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];if(this.closingPointId){var n=e.coordinates[e.coordinates.length-1],o=this.project(n[0],n[1]);_({x:o.x,y:o.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor("pointer")}this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[].concat(e.coordinates,[i])}}])}},o.onClick=function(t){var e=this.currentId&&this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];if(0===this.currentCoordinate){var i=this.store.create([{geometry:{type:"LineString",coordinates:[e,e]},properties:{mode:this.mode}}]);this.currentId=i[0],this.currentCoordinate++}else if(1===this.currentCoordinate&&this.currentId){var n=this.store.getGeometryCopy(this.currentId),o=this.store.create([{geometry:{type:"Point",coordinates:[].concat(e)},properties:{mode:this.mode}}]);this.closingPointId=o[0],this.setCursor("pointer"),this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[n.coordinates[0],e,e]}}]),this.currentCoordinate++}else if(this.currentId){var r=this.store.getGeometryCopy(this.currentId),s=r.coordinates[r.coordinates.length-2],a=this.project(s[0],s[1]);if(_({x:a.x,y:a.y},{x:t.containerX,y:t.containerY})<this.pointerDistance)this.close();else{var l={type:"LineString",coordinates:[].concat(r.coordinates,[e])};if(!this.allowSelfIntersections&&v({type:"Feature",geometry:l,properties:{}}))return;this.closingPointId&&(this.setCursor("pointer"),this.store.updateGeometry([{id:this.currentId,geometry:l},{id:this.closingPointId,geometry:{type:"Point",coordinates:r.coordinates[r.coordinates.length-1]}}]),this.currentCoordinate++)}}},o.onKeyDown=function(){},o.onKeyUp=function(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0},o.styleFeature=function(t){var e=i({},{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?(this.styles.lineStringColor&&(e.lineStringColor=this.styles.lineStringColor),this.styles.lineStringWidth&&(e.lineStringWidth=this.styles.lineStringWidth),e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(this.styles.closingPointColor&&(e.pointColor=this.styles.closingPointColor),this.styles.closingPointWidth&&(e.pointWidth=this.styles.closingPointWidth),e.pointOutlineColor=void 0!==this.styles.closingPointOutlineColor?this.styles.closingPointOutlineColor:"#ffffff",e.pointOutlineWidth=void 0!==this.styles.closingPointOutlineWidth?this.styles.closingPointOutlineWidth:2,e):e},e}(g),E=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="point",i}n(e,t);var o=e.prototype;return o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onClick=function(t){if(!this.store)throw new Error("Mode must be registered first");this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}])},o.onMouseMove=function(){},o.onKeyDown=function(){},o.onKeyUp=function(){},o.cleanUp=function(){},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.styleFeature=function(t){var e=i({},{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?(this.styles.pointColor&&(e.pointColor=this.styles.pointColor),this.styles.pointOutlineColor&&(e.pointOutlineColor=this.styles.pointOutlineColor),this.styles.pointWidth&&(e.pointWidth=this.styles.pointWidth),e):e},e}(g);function k(t,e){return t[0]===e[0]&&t[1]===e[1]}var S=/*#__PURE__*/function(t){function i(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n._startEndPoints=[],n.config=e,n.pixelDistance=i,n}n(i,t);var o=i.prototype;return o.create=function(t,e){var i,n;if(this.ids.length)throw new Error("Opening and closing points already creating");if(t.length<=3)throw new Error("Requires at least 4 cooridnates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:(i={mode:e},i.closingPoint=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(n={mode:e},n.closingPoint=!0,n)}])},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]),n=this.pixelDistance.measure(t,e.coordinates),o=this.pixelDistance.measure(t,i.coordinates);return{isClosing:n<this.pointerDistance,isPreviousClosing:o<this.pointerDistance}},e(i,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}]),i}(C),w=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.allowSelfIntersections=void 0,i.keyEvents=void 0,i.snappingEnabled=void 0,i.isClosed=!1,i.snapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.snappingEnabled=!(!e||void 0===e.snapping)&&e.snapping,i.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections,i.keyEvents=e&&e.keyEvents?e.keyEvents:{cancel:"Escape",finish:"Enter"},i}n(e,t);var o=e.prototype;return o.close=function(){if(this.currentId){var t=this.store.getGeometryCopy(this.currentId).coordinates[0];t.length<5||(this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[].concat(t.slice(0,-2),[t[0]])]}}]),this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete())}},o.registerBehaviors=function(t){this.pixelDistance=new M(t),this.snapping=new L(t,this.pixelDistance,new P(t)),this.closingPoints=new S(t,this.pixelDistance)},o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onMouseMove=function(t){if(this.setCursor("crosshair"),this.currentId&&0!==this.currentCoordinate){var e,i=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0,n=this.store.getGeometryCopy(this.currentId).coordinates[0];if(i&&(t.lng=i[0],t.lat=i[1]),1===this.currentCoordinate){var o=1/Math.pow(10,this.coordinatePrecision-1),r=Math.max(1e-6,o);e=[n[0],[t.lng,t.lat],[t.lng,t.lat+r],n[0]]}else if(2===this.currentCoordinate)e=[n[0],n[1],[t.lng,t.lat],n[0]];else{var s=this.closingPoints.isClosingPoint(t);s.isPreviousClosing||s.isClosing?(this.setCursor("pointer"),e=[].concat(n.slice(0,-2),[n[0],n[0]]),this.isClosed||(this.isClosed=!0)):(this.isClosed&&(this.isClosed=!1),e=[].concat(n.slice(0,-2),[[t.lng,t.lat],n[0]]))}this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[e]}}]),this.closingPoints.ids.length&&this.closingPoints.update(e)}},o.onClick=function(t){var e,i=this.currentId&&this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;if(0===this.currentCoordinate){i&&(t.lng=i[0],t.lat=i[1]);var n=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=n[0],this.currentCoordinate++}else if(1===this.currentCoordinate&&this.currentId){i&&(t.lng=i[0],t.lat=i[1]);var o=this.store.getGeometryCopy(this.currentId);if(k([t.lng,t.lat],o.coordinates[0][0]))return;this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[o.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]]]}}]),this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){i&&(t.lng=i[0],t.lat=i[1]);var r=this.store.getGeometryCopy(this.currentId).coordinates[0];if(k([t.lng,t.lat],r[1]))return;2===this.currentCoordinate&&this.closingPoints.create(r,"polygon"),this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[r[0],r[1],[t.lng,t.lat],[t.lng,t.lat],r[0]]]}}]),this.currentCoordinate++}else if(this.currentId){var s=this.store.getGeometryCopy(this.currentId).coordinates[0],a=this.closingPoints.isClosingPoint(t);if(a.isPreviousClosing||a.isClosing)this.close();else{if(i&&(t.lng=i[0],t.lat=i[1]),k([t.lng,t.lat],s[this.currentCoordinate-1]))return;var l=(void 0===(e=[[].concat(s.slice(0,-1),[[t.lng,t.lat],s[0]])])&&(e=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]),{type:"Feature",geometry:{type:"Polygon",coordinates:e},properties:{}});if(this.currentCoordinate>2&&!this.allowSelfIntersections&&v(l))return;this.store.updateGeometry([{id:this.currentId,geometry:l.geometry}]),this.currentCoordinate++}}},o.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},o.onKeyDown=function(){},o.onDragStart=function(){this.setCursor("unset")},o.onDrag=function(){},o.onDragEnd=function(){this.setCursor("crosshair")},o.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(t){}this.currentId=void 0,this.currentCoordinate=0},o.styleFeature=function(t){var e=i({},{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.styles.fillColor||e.polygonFillColor,e.polygonOutlineColor=this.styles.outlineColor||e.polygonOutlineColor,e.polygonOutlineWidth=this.styles.outlineWidth||e.polygonOutlineWidth,e.polygonFillColor=this.styles.fillColor||e.polygonFillColor,e.zIndex=10,e;if("Point"===t.geometry.type)return e.pointWidth=this.styles.closingPointWidth||e.pointWidth,e.pointColor=this.styles.closingPointColor||e.pointColor,e.pointOutlineColor=this.styles.closingPointOutlineColor||"#ffffff",e.pointOutlineWidth=this.styles.closingPointOutlineWidth||2,e.zIndex=30,e}return e},e}(g),D=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,{styles:e.styles})||this).mode="render",i}n(e,t);var o=e.prototype;return o.registerBehaviors=function(t){this.mode=t.mode},o.start=function(){this.setStarted()},o.stop=function(){this.setStopped()},o.onKeyUp=function(){},o.onKeyDown=function(){},o.onClick=function(){},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.onMouseMove=function(){},o.styleFeature=function(){return i({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0},this.styles)},e}(g);function I(t,e,i){var n=c(t,e),o=function(t,e){var i=h(t[0]),n=h(e[0]),o=h(t[1]),r=h(e[1]),s=Math.sin(n-i)*Math.cos(r),a=Math.cos(o)*Math.sin(r)-Math.sin(o)*Math.cos(r)*Math.cos(n-i);return d(Math.atan2(s,a))}(t,e),s=u(t,n/2,o);return[r(s[0],i),r(s[1],i)]}function b(t,e){for(var i=[],n=0;n<t.length-1;n++){var o=I(t[n],t[n+1],e);i.push(o)}return i}var O=/*#__PURE__*/function(t){function i(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPointBehavior=void 0,n._midPoints=[],n.config=e,n.selectionPointBehavior=i,n}n(i,t);var o=i.prototype;return o.insert=function(t,e){var i=this.store.getGeometryCopy(t),n=this.store.getPropertiesCopy(t),o=n.midPointFeatureId,r=n.midPointSegment,s=this.store.getGeometryCopy(o),a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.splice(r+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[a]:a,this.store.updateGeometry([{id:o,geometry:s}]),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(a,o,e),this.selectionPointBehavior.create(a,s.type,o)},o.create=function(t,e,i){var n=this;if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i){return b(t,i).map(function(t,i){return{geometry:{type:"Point",coordinates:t},properties:e(i)}})}(t,function(t){var i;return(i={mode:n.mode}).midPoint=!0,i.midPointSegment=t,i.midPointFeatureId=e,i},i))},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 b(t,this.coordinatePrecision).map(function(t,i){return{id:e._midPoints[i],geometry:{type:"Point",coordinates:t}}})},e(i,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}]),i}(C),F=/*#__PURE__*/function(t){function i(e){var i;return(i=t.call(this,e)||this)._selectionPoints=[],i}n(i,t);var o=i.prototype;return o.create=function(t,e,i){var n=this;this._selectionPoints=this.store.create(function(t,e,i){for(var n=[],o="Polygon"===e?t.length-1:t.length,r=0;r<o;r++)n.push({geometry:{type:"Point",coordinates:t[r]},properties:i(r)});return n}(t,e,function(t){return{mode:n.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t}}))},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}}},e(i,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}]),i}(C);function W(t,e){for(var i,n,o,r=!1,s=0,a=e.length;s<a;s++)for(var l=e[s],c=0,h=l.length,d=h-1;c<h;d=c++)(n=l[c])[1]>(i=t)[1]!=(o=l[d])[1]>i[1]&&i[0]<(o[0]-n[0])*(i[1]-n[1])/(o[1]-n[1])+n[0]&&(r=!r);return r}var B=function(t,e,i){var n=function(t){return t*t},o=function(t,e){return n(t.x-e.x)+n(t.y-e.y)};return Math.sqrt(function(t,e,i){var n=o(e,i);if(0===n)return o(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/n;return r=Math.max(0,Math.min(1,r)),o(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},K=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.createClickBoundingBox=void 0,o.pixelDistance=void 0,o.config=e,o.createClickBoundingBox=i,o.pixelDistance=n,o}return n(e,t),e.prototype.find=function(t,e){for(var i=void 0,n=Infinity,o=void 0,r=Infinity,s=this.createClickBoundingBox.create(t),a=this.store.search(s),l=0;l<a.length;l++){var c=a[l],h=c.geometry;if("Point"===h.type){if(c.properties.selectionPoint||!e&&c.properties.midPoint)continue;var d=this.pixelDistance.measure(t,h.coordinates);c.properties.midPoint&&d<this.pointerDistance&&d<r?(r=d,o=c):!c.properties.midPoint&&d<this.pointerDistance&&d<n&&(n=d,i=c)}else if("LineString"===h.type)for(var u=0;u<h.coordinates.length-1;u++){var p=h.coordinates[u],g=h.coordinates[u+1],f=B({x:t.containerX,y:t.containerY},this.project(p[0],p[1]),this.project(g[0],g[1]));f<this.pointerDistance&&f<n&&(n=f,i=c)}else"Polygon"===h.type&&W([t.lng,t.lat],h.coordinates)&&(n=0,i=c)}return{clickedFeature:i,clickedMidPoint:o}},e}(C),j=/*#__PURE__*/function(t){function i(e,i,n,o){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.dragPosition=void 0,r.config=e,r.featuresAtMouseEvent=i,r.selectionPoints=n,r.midPoints=o,r}return n(i,t),i.prototype.drag=function(t,e){var i=this.featuresAtMouseEvent.find(t,!0).clickedFeature;if(i&&i.id===e){var n=this.store.getGeometryCopy(e),o=[t.lng,t.lat];if("Polygon"===n.type||"LineString"===n.type){var r,s;if("Polygon"===n.type?s=(r=n.coordinates[0]).length-1:"LineString"===n.type&&(s=(r=n.coordinates).length),void 0===s||!r||!this.dragPosition)return!1;for(var a=0;a<s;a++){var l=r[a],c=[this.dragPosition[0]-o[0],this.dragPosition[1]-o[1]];r[a]=[l[0]-c[0],l[1]-c[1]]}"Polygon"===n.type&&(r[r.length-1]=[r[0][0],r[0][1]]);var h=this.selectionPoints.getUpdated(r)||[],d=this.midPoints.getUpdated(r)||[];this.store.updateGeometry([{id:e,geometry:n}].concat(h,d))}else"Point"===n.type&&this.store.updateGeometry([{id:e,geometry:{type:"Point",coordinates:o}}])}},e(i,[{key:"position",get:function(){return this.dragPosition?this.dragPosition.concat():void 0},set:function(t){if(void 0!==t){if(!Array.isArray(t)||2!==t.length||"number"!=typeof t[0]||"number"!=typeof t[1])throw new Error("Position must be [number, number] array");this.dragPosition=t.concat()}else this.dragPosition=void 0}}]),i}(C),X=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.config=e,r.pixelDistance=i,r.selectionPoints=n,r.midPoints=o,r}return n(e,t),e.prototype.drag=function(t,e){var i,n=this.store.getGeometryCopy(e);if("LineString"===n.type)i=n.coordinates;else{if("Polygon"!==n.type)return!1;i=n.coordinates[0]}for(var o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1},r=0;r<i.length;r++){var s=this.pixelDistance.measure(t,i[r]);if(s<this.pointerDistance&&s<o.dist){var a="Polygon"===n.type&&(r===i.length-1||0===r);o.dist=s,o.index=a?0:r,o.isFirstOrLastPolygonCoord=a}}if(-1===o.index)return!1;var l=[t.lng,t.lat];if(o.isFirstOrLastPolygonCoord){var c=i.length-1;i[0]=l,i[c]=l}else i[o.index]=l;var h=this.selectionPoints.getOneUpdated(o.index,l),d=h?[h]:[],u=this.midPoints.getUpdated(i)||[];return this.store.updateGeometry([{id:e,geometry:n}].concat(d,u)),!0},e}(C);function Y(t){var e=0,i=0,n=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],n++},!0),[e/n,i/n]}function G(t,e){var i=t,n=e,o=h(i[1]),r=h(n[1]),s=h(n[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),l=(d(Math.atan2(s,a))+360)%360;return l>180?-(360-l):l}function T(t,e,i){var n=e/6371008.8,o=t[0]*Math.PI/180,r=h(t[1]),s=h(i),a=n*Math.cos(s),l=r+a;Math.abs(l)>Math.PI/2&&(l=l>0?Math.PI-l:-Math.PI-l);var c=Math.log(Math.tan(l/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),d=Math.abs(c)>1e-11?a/c:Math.cos(r),u=[(180*(o+n*Math.sin(s)/d)/Math.PI+540)%360-180,180*l/Math.PI];return u[0]+=u[0]-t[0]>180?-360:t[0]-u[0]>180?360:0,u}function U(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=e[1]*Math.PI/180,n=t[1]*Math.PI/180,o=n-i,r=Math.abs(t[0]-e[0])*Math.PI/180;r>Math.PI&&(r-=2*Math.PI);var s=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),a=Math.abs(s)>1e-11?o/s:Math.cos(i);return 6371008.8*Math.sqrt(o*o+a*a*r*r)}var N=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.lastBearing=void 0,o.config=e,o.selectionPoints=i,o.midPoints=n,o}n(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0},i.rotate=function(t,e){var i=this,n=this.store.getGeometryCopy(e);if("Polygon"===n.type||"LineString"===n.type){var o=[t.lng,t.lat],s=G(Y({type:"Feature",geometry:n,properties:{}}),o);if(this.lastBearing){var a;if(function(t,e){if(0===e)return t;var i=Y(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=G(i,t)+e,o=U(i,t),r=T(i,o,n);t[0]=r[0],t[1]=r[1]})}({type:"Feature",geometry:n,properties:{}},-(this.lastBearing-(s+180))),"Polygon"===n.type)a=n.coordinates[0];else{if("LineString"!==n.type)return;a=n.coordinates}a.forEach(function(t){t[0]=r(t[0],i.coordinatePrecision),t[1]=r(t[1],i.coordinatePrecision)});var l=this.midPoints.getUpdated(a)||[],c=this.selectionPoints.getUpdated(a)||[];this.store.updateGeometry([{id:e,geometry:n}].concat(c,l)),this.lastBearing=s+180}else this.lastBearing=s+180}},e}(C),A=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.lastDistance=void 0,o.config=e,o.selectionPoints=i,o.midPoints=n,o}n(e,t);var i=e.prototype;return i.reset=function(){this.lastDistance=void 0},i.scale=function(t,e){var i=this,n=this.store.getGeometryCopy(e);if("Polygon"===n.type||"LineString"===n.type){var o=[t.lng,t.lat],s=c(Y({type:"Feature",geometry:n,properties:{}}),o);if(this.lastDistance){var a;if(function(t,e){if(1===e)return t;var i=Y(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=U(i,t),o=G(i,t),r=T(i,n*e,o);t[0]=r[0],t[1]=r[1]})}({type:"Feature",geometry:n,properties:{}},1-(this.lastDistance-s)/s),"Polygon"===n.type)a=n.coordinates[0];else{if("LineString"!==n.type)return;a=n.coordinates}a.forEach(function(t){t[0]=r(t[0],i.coordinatePrecision),t[1]=r(t[1],i.coordinatePrecision)});var l=this.midPoints.getUpdated(a)||[],h=this.selectionPoints.getUpdated(a)||[];this.store.updateGeometry([{id:e,geometry:n}].concat(h,l)),this.lastDistance=s}else this.lastDistance=s}},e}(C),z=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="select",i.dragEventThrottle=5,i.dragEventCount=0,i.selected=[],i.flags=void 0,i.keyEvents=void 0,i.selectionPoints=void 0,i.midPoints=void 0,i.featuresAtMouseEvent=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.dragFeature=void 0,i.dragCoordinate=void 0,i.rotateFeature=void 0,i.scaleFeature=void 0,i.flags=e&&e.flags?e.flags:{},i.keyEvents=e&&e.keyEvents?e.keyEvents:{deselect:"Escape",delete:"Delete",rotate:"r",scale:"s"},i.dragEventThrottle=e&&void 0!==e.dragEventThrottle&&e.dragEventThrottle||5,i}n(e,t);var o=e.prototype;return o.registerBehaviors=function(t){this.pixelDistance=new M(t),this.clickBoundingBox=new P(t),this.featuresAtMouseEvent=new K(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new F(t),this.midPoints=new O(t,this.selectionPoints),this.rotateFeature=new N(t,this.selectionPoints,this.midPoints),this.scaleFeature=new A(t,this.selectionPoints,this.midPoints),this.dragFeature=new j(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new X(t,this.pixelDistance,this.selectionPoints,this.midPoints)},o.deselect=function(){this.store.updateProperty(this.selected.map(function(t){return{id:t,property:"selected",value:!1}})),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()},o.deleteSelected=function(){this.store.delete(this.selected),this.selected=[]},o.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,n=Infinity;if(this.selectionPoints.ids.forEach(function(o){var r=e.store.getGeometryCopy(o),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<n&&(n=s,i=e.store.getPropertiesCopy(o))}),i){var o=i.selectionPointFeatureId,r=i.index,s=this.store.getPropertiesCopy(o),a=this.flags[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var l,c=this.store.getGeometryCopy(o);if("Polygon"===c.type){if((l=c.coordinates[0]).length<=4)return}else if("LineString"===c.type&&(l=c.coordinates).length<=3)return;l&&("Polygon"===c.type&&0===r||r===l.length-1?(l.shift(),l.pop(),l.push([l[0][0],l[0][1]])):l.splice(r,1),this.store.delete([].concat(this.midPoints.ids,this.selectionPoints.ids)),this.store.updateGeometry([{id:o,geometry:c}]),this.selectionPoints.create(l,c.type,o),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(l,o,this.coordinatePrecision))}}}},o.onLeftClick=function(t){var e=this.featuresAtMouseEvent.find(t,this.selected.length>0),i=e.clickedFeature,n=e.clickedMidPoint;if(this.selected.length&&n)this.midPoints.insert(n.id,this.coordinatePrecision);else if(i){var o=this.store.getPropertiesCopy(i.id).mode,r=this.selected[0];if(r){if(r===i.id)return;this.deselect()}var s=this.flags[o];if(!s||!s.feature)return;this.selected=[i.id],this.store.updateProperty([{id:i.id,property:"selected",value:!0}]),this.onSelect(i.id);var a,l=this.store.getGeometryCopy(i.id),c=l.type,h=l.coordinates;"LineString"===c?a=h:"Polygon"===c&&(a=h[0]),a&&s&&s.feature.coordinates&&(this.selectionPoints.create(a,c,i.id),s.feature.coordinates.midpoints&&this.midPoints.create(a,i.id,this.coordinatePrecision))}else if(this.selected.length)return void this.deselect()},o.start=function(){this.setStarted()},o.stop=function(){this.setStopped(),this.cleanUp()},o.onClick=function(t){"right"!==t.button?"left"===t.button&&this.onLeftClick(t):this.onRightClick(t)},o.onKeyDown=function(){},o.onKeyUp=function(t){if(t.key===this.keyEvents.delete){if(!this.selected.length)return;this.onDeselect(this.selected[0]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else t.key===this.keyEvents.deselect&&this.cleanUp()},o.cleanUp=function(){this.selected.length&&this.deselect()},o.onDragStart=function(t,e){if(this.selected.length){var i=this.store.getPropertiesCopy(this.selected[0]),n=this.flags[i.mode];n&&n.feature&&(n.feature.draggable||n.feature.coordinates&&n.feature.coordinates.draggable)&&(this.dragEventCount=0,this.setCursor("grabbing"),this.dragFeature.position=[t.lng,t.lat],e(!1))}},o.onDrag=function(t){var e=this.selected[0];if(e&&this.dragFeature.position){var i=this.store.getPropertiesCopy(e),n=this.flags[i.mode];if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0)if(n&&n.feature&&n.feature.rotateable&&t.heldKeys.includes("r"))this.rotateFeature.rotate(t,e);else if(n&&n.feature&&n.feature.scaleable&&t.heldKeys.includes("s"))this.scaleFeature.scale(t,e);else{if(n&&n.feature&&n.feature.coordinates&&n.feature.coordinates.draggable&&this.dragCoordinate.drag(t,e))return;n&&n.feature&&n.feature.draggable&&(this.dragFeature.drag(t,e),this.dragFeature.position=[t.lng,t.lat])}}},o.onDragEnd=function(t,e){this.setCursor("grab"),this.dragFeature.position=void 0,this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0)},o.onMouseMove=function(t){var e=this;if(this.selected.length&&!this.dragFeature.position){var i=!1;this.midPoints.ids.forEach(function(n){if(!i){var o=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,o.coordinates)<e.pointerDistance&&(i=!0)}}),this.selectionPoints.ids.forEach(function(n){var o=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,o.coordinates)<e.pointerDistance&&(i=!1)}),this.setCursor(i?"crosshair":"unset")}},o.styleFeature=function(t){var e=i({},{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 this.styles.selectedColor&&(e.polygonFillColor=this.styles.selectedColor),this.styles.selectedColor&&(e.polygonOutlineColor=this.styles.selectedColor),e.zIndex=10,e;if("Point"===t.geometry.type){if(t.properties.selectionPoint)return e.pointColor=this.styles.selectionPointColor||e.pointColor,e.pointOutlineColor=this.styles.selectionPointOutlineColor||e.pointOutlineColor,e.pointWidth=this.styles.selectionPointWidth||e.pointWidth,e.pointOutlineWidth=this.styles.midPointOutlineWidth||2,e.zIndex=30,e;if(t.properties.midPoint)return e.pointColor=this.styles.midPointColor||e.pointColor,e.pointOutlineColor=this.styles.midPointOutlineColor||e.pointOutlineColor,e.pointWidth=this.styles.midPointWidth||4,e.pointOutlineWidth=this.styles.midPointOutlineWidth||2,e.zIndex=40,e}}return e},e}(g),J=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).mode="static",e}n(e,t);var o=e.prototype;return o.start=function(){},o.stop=function(){},o.onKeyUp=function(){},o.onKeyDown=function(){},o.onClick=function(){},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.onMouseMove=function(){},o.styleFeature=function(){return i({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0})},e}(g),R=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)})};function q(t,e,i,n,o){for(;n>i;){if(n-i>600){var r=n-i+1,s=e-i+1,a=Math.log(r),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(r-l)/r)*(s-r/2<0?-1:1);q(t,e,Math.max(i,Math.floor(e-s*l/r+c)),Math.min(n,Math.floor(e+(r-s)*l/r+c)),o)}var h=t[e],d=i,u=n;for(H(t,i,e),o(t[n],h)>0&&H(t,i,n);d<u;){for(H(t,d,u),d++,u--;o(t[d],h)<0;)d++;for(;o(t[u],h)>0;)u--}0===o(t[i],h)?H(t,i,u):H(t,++u,n),u<=e&&(i=u+1),e<=u&&(n=u-1)}}function H(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function Z(t,e){Q(t,0,t.children.length,e,t)}function Q(t,e,i,n,o){o||(o=rt([])),o.minX=Infinity,o.minY=Infinity,o.maxX=-Infinity,o.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];V(o,t.leaf?n(s):s)}return o}function V(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 $(t,e){return t.minX-e.minX}function tt(t,e){return t.minY-e.minY}function et(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function it(t){return t.maxX-t.minX+(t.maxY-t.minY)}function nt(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function ot(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function rt(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function st(t,e,i,n,o){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=n)){var s=e+Math.ceil((i-e)/n/2)*n;q(t,s,e,i,o),r.push(e,s,s,i)}}var at=/*#__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(!ot(t,e))return i;for(var n=this.toBBox,o=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?n(s):s;ot(t,a)&&(e.leaf?i.push(s):nt(t,a)?this._all(s,i):o.push(s))}e=o.pop()}return i},e.collides=function(t){var e=this.data;if(ot(t,e))for(var i=[];e;){for(var n=0;n<e.children.length;n++){var o=e.children[n],r=e.leaf?this.toBBox(o):o;if(ot(t,r)){if(e.leaf||nt(t,r))return!0;i.push(o)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var n=this.data;this.data=i,i=n}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=rt([])},e.remove=function(t){for(var e,i,n=this.data,o=this.toBBox(t),r=[],s=[],a=!1;n||r.length;){if(n||(n=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),n.leaf){var l=n.children.indexOf(t);-1!==l&&(n.children.splice(l,1),r.push(n),this._condense(r))}a||n.leaf||!nt(n,o)?i?(e++,n=i.children[e],a=!1):n=null:(r.push(n),s.push(e),e=0,i=n,n=n.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,n){var o,r=i-e+1,s=this._maxEntries;if(r<=s)return Z(o=rt(t.slice(e,i+1)),this.toBBox),o;n||(n=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,n-1))),(o=rt([])).leaf=!1,o.height=n;var a=Math.ceil(r/s),l=a*Math.ceil(Math.sqrt(s));st(t,e,i,l,this.compareMinX);for(var c=e;c<=i;c+=l){var h=Math.min(c+l-1,i);st(t,c,h,a,this.compareMinY);for(var d=c;d<=h;d+=a){var u=Math.min(d+a-1,h);o.children.push(this._build(t,d,u,n-1))}}return Z(o,this.toBBox),o},e._chooseSubtree=function(t,e,i,n){for(;n.push(e),!e.leaf&&n.length-1!==i;){for(var o=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var l=e.children[a],c=et(l),h=(d=t,u=l,(Math.max(u.maxX,d.maxX)-Math.min(u.minX,d.minX))*(Math.max(u.maxY,d.maxY)-Math.min(u.minY,d.minY))-c);h<r?(r=h,o=c<o?c:o,s=l):h===r&&c<o&&(o=c,s=l)}e=s||e.children[0]}var d,u;return e},e._insert=function(t,e,i){var n=i?t:this.toBBox(t),o=[],r=this._chooseSubtree(n,this.data,e,o);for(r.children.push(t),V(r,n);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)},e._split=function(t,e){var i=t[e],n=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,n);var r=this._chooseSplitIndex(i,o,n),s=rt(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,Z(i,this.toBBox),Z(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=rt([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Z(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var n,o,r,s,a,l,c,h=Infinity,d=Infinity,u=e;u<=i-e;u++){var p=Q(t,0,u,this.toBBox),g=Q(t,u,i,this.toBBox),f=(o=p,r=g,s=Math.max(o.minX,r.minX),a=Math.max(o.minY,r.minY),l=Math.min(o.maxX,r.maxX),c=Math.min(o.maxY,r.maxY),Math.max(0,l-s)*Math.max(0,c-a)),y=et(p)+et(g);f<h?(h=f,n=u,d=y<d?y:d):f===h&&y<d&&(d=y,n=u)}return n||i-e},e._chooseSplitAxis=function(t,e,i){var n=t.leaf?this.compareMinX:$,o=t.leaf?this.compareMinY:tt;this._allDistMargin(t,e,i,n)<this._allDistMargin(t,e,i,o)&&t.children.sort(n)},e._allDistMargin=function(t,e,i,n){t.children.sort(n);for(var o=this.toBBox,r=Q(t,0,e,o),s=Q(t,i-e,i,o),a=it(r)+it(s),l=e;l<i-e;l++){var c=t.children[l];V(r,t.leaf?o(c):c),a+=it(r)}for(var h=i-e-1;h>=e;h--){var d=t.children[h];V(s,t.leaf?o(d):d),a+=it(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var n=i;n>=0;n--)V(e[n],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():Z(t[i],this.toBBox)},t}(),lt=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new at(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(String(t.id),e),this.nodeToId.set(e,String(t.id))},e.toBBox=function(t){var e,i=[],n=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var o=0;o<e.length;o++)n.push(e[o][1]),i.push(e[o][0]);var r=Math.min.apply(Math,n),s=Math.max.apply(Math,n);return{minX:Math.min.apply(Math,i),minY:r,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],n=new Set;t.forEach(function(t){var o=e.toBBox(t);if(e.setMaps(t,o),n.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);n.add(String(t.id)),i.push(o)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),ct=/*#__PURE__*/function(){function t(t){this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=function(){},this.store={},this.spatialIndex=new lt,this.tracked=!t||!1!==t.tracked,t&&t.data&&this.load(t.data,t.validateFeature)}var e=t.prototype;return e.getId=function(){return R()},e.clone=function(t){return JSON.parse(JSON.stringify(t))},e.has=function(t){return Boolean(this.store[t])},e.load=function(t,e){var i=this;if(0!==t.length){var n=this.clone(t);n.forEach(function(t){t.id||(t.id=R()),i.tracked&&(t.properties.createdAt||(t.properties.createdAt=+new Date),t.properties.updatedAt||(t.properties.updatedAt=+new Date))});var o=[];n.forEach(function(t){e&&e(t),i.store[t.id]=t,o.push(t.id)}),this.spatialIndex.load(n),this._onChange(o,"create")}},e.search=function(t,e){var i=this,n=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?n.filter(e):n)},e.registerOnChange=function(t){this._onChange=function(e,i){t(e,i)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t){var e=this,i=[];t.forEach(function(t){var n=t.id,o=t.property,r=t.value,s=e.store[n];if(!s)throw new Error("No feature with this ("+n+"), can not update geometry");i.push(n),s.properties[o]=r,e.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.updateGeometry=function(t){var e=this,i=[];t.forEach(function(t){var n=t.id,o=t.geometry;i.push(n);var r=e.store[n];if(!r)throw new Error("No feature with this ("+n+"), can not update geometry");r.geometry=e.clone(o),e.spatialIndex.update(r),e.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.create=function(t){var e=this,n=[];return t.forEach(function(t){var o,r=t.geometry,s=t.properties,a=i({},s);e.tracked&&(o=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:o,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:o):a={createdAt:o,updatedAt:o});var l=e.getId(),c={id:l,type:"Feature",geometry:r,properties:a};e.store[l]=c,e.spatialIndex.insert(c),n.push(l)}),this._onChange&&this._onChange([].concat(n),"create"),n},e.delete=function(t){var e=this;t.forEach(function(t){if(!e.store[t])throw new Error("No feature with this id, can not delete");delete e.store[t],e.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete")},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},t}();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._adapter=t.adapter,this._mode=new J,this._modes=i({},t.modes,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[]},this._store=t.data?new ct({data:t.data}):new ct;var n=function(t){var i=[],n=e._store.copyAll().filter(function(e){return!t.includes(e.id)||(i.push(e),!1)});return{changed:i,unchanged:n}},o=function(t,i){e._eventListeners.change.forEach(function(e){e(t,i)});var o=n(t),r=o.changed,s=o.unchanged;"create"===i?e._adapter.render({created:r,deletedIds:[],unchanged:s,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:s,updated:r},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:s,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:s,updated:[]},e.getModeStyles())},r=function(t){e._eventListeners.select.forEach(function(e){e(t)});var i=n([t]);e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:i.changed},e.getModeStyles())},s=function(t){e._eventListeners.deselect.forEach(function(t){t()});var i=n([t]),o=i.changed;o&&e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:o},e.getModeStyles())};if(Object.keys(this._modes).forEach(function(t){e._modes[t].register({mode:t,store:e._store,setCursor:e._adapter.setCursor,project:e._adapter.project,unproject:e._adapter.unproject,onChange:o,onSelect:r,onDeselect:s})}),t.data){var a=this._store.copyAll().filter(function(t){return!(t.properties&&!Object.keys(e._modes).includes(t.properties.mode)&&(e._store.delete([t.id]),1))});this._adapter.render({created:a,deletedIds:[],unchanged:[],updated:[]},this.getModeStyles())}}var n=t.prototype;return n.getModeStyles=function(){var t=this,e={};return Object.keys(this._modes).forEach(function(i){e[i]=t._modes[i].styleFeature.bind(t._modes[i])}),e},n.setModeStyles=function(t,e){this._modes[t].styles=e},n.getSnapshot=function(){return this._store.copyAll()},n.getCurrentMode=function(){return this._mode.mode},n.changeMode=function(t){if(!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()},n.start=function(){var t=this;this._enabled=!0,this._adapter.register({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){t._mode.onDrag(e)},onDragEnd:function(e,i){t._mode.onDragEnd(e,i)}})},n.stop=function(){this._enabled=!1,this._adapter.unregister()},n.on=function(t,e){var i=this._eventListeners[t];i.includes(e)||i.push(e)},n.off=function(t,e){var i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)},e(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}]),t}(),exports.TerraDrawCircleMode=f,exports.TerraDrawFreehandMode=y,exports.TerraDrawGoogleMapsAdapter=s,exports.TerraDrawLeafletAdapter=a,exports.TerraDrawLineStringMode=x,exports.TerraDrawMapboxGLAdapter=l,exports.TerraDrawPointMode=E,exports.TerraDrawPolygonMode=w,exports.TerraDrawRenderMode=D,exports.TerraDrawSelectMode=z;
|
|
1
|
+
function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function e(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},i.apply(this,arguments)}function n(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,o(t,e)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function r(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var s=/*#__PURE__*/function(){function t(t){var e=this;this._heldKeys=new Set,this._cursor=void 0,this._cursorStyleSheet=void 0,this._coordinatePrecision=void 0,this._lib=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onMouseMoveCallback=void 0,this._onClickListener=void 0,this._onRightClickListener=void 0,this._onClickCallback=void 0,this._onKeyUpListener=void 0,this._onDragStartListener=void 0,this._onDragListener=void 0,this._onDragEndListener=void 0,this._layers=!1,this.getMapContainer=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.getMapContainer=function(){return e._map.getDiv()},this.project=function(t,i){var n=e._map.getBounds();if(void 0===n)throw new Error("cannot get bounds");var o=new e._lib.LatLng(n.getNorthEast().lat(),n.getSouthWest().lng()),r=e._map.getProjection();if(void 0===r)throw new Error("cannot get projection");var s=r.fromLatLngToPoint(o);if(null===s)throw new Error("cannot get projectedNorthWest");var a=r.fromLatLngToPoint({lng:t,lat:i});if(null===a)throw new Error("cannot get projected lng lat");var l=e._map.getZoom();if(void 0===l)throw new Error("cannot get zoom");var c=Math.pow(2,l);return{x:Math.floor((a.x-s.x)*c),y:Math.floor((a.y-s.y)*c)}},this.unproject=function(t,i){var n=e._map.getProjection();if(void 0===n)throw new Error("cannot get projection");var o=e._map.getBounds();if(void 0===o)throw new Error("cannot get bounds");var r=n.fromLatLngToPoint(o.getNorthEast());if(null===r)throw new Error("cannot get topRight");var s=n.fromLatLngToPoint(o.getSouthWest());if(null===s)throw new Error("cannot get bottomLeft");var a=e._map.getZoom();if(void 0===a)throw new Error("zoom get bounds");var l=Math.pow(2,a),c=new google.maps.Point(t/l+s.x,i/l+r.y),h=n.fromPointToLatLng(c);if(null===h)throw new Error("zoom get bounds");return{lng:h.lng(),lat:h.lat()}},this.setCursor=function(t){if(t!==e._cursor){if(e._cursorStyleSheet&&(e._cursorStyleSheet.remove(),e._cursorStyleSheet=void 0),"unset"!==t){var i=e.getMapContainer(),n=document.createElement("style");n.type="text/css",n.innerHTML="#"+i.id+' [aria-label="Map"] { cursor: '+t+" !important; }",document.getElementsByTagName("head")[0].appendChild(n),e._cursorStyleSheet=n}e._cursor=t}}}var e=t.prototype;return e.circlePath=function(t,e,i){return"M "+t+" "+e+" m -"+i+", 0 a "+i+","+i+" 0 1,0 "+2*i+",0 a "+i+","+i+" 0 1,0 -"+2*i+",0"},e.register=function(t){var e=this;this._onClickCallback=function(i){i.latLng&&t.onClick({lng:r(i.latLng.lng(),e._coordinatePrecision),lat:r(i.latLng.lat(),e._coordinatePrecision),containerX:i.domEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.domEvent.clientY-e.getMapContainer().offsetTop,button:0===i.domEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._onClickListener=this._map.addListener("click",this._onClickCallback),this._onRightClickListener=this._map.addListener("rightclick",this._onClickCallback),this._onMouseMoveCallback=function(i){i.latLng&&t.onMouseMove({lng:r(i.latLng.lng(),e._coordinatePrecision),lat:r(i.latLng.lat(),e._coordinatePrecision),containerX:i.domEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.domEvent.clientY-e.getMapContainer().offsetTop,button:0===i.domEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._onMouseMoveListener=this._map.addListener("mousemove",this._onMouseMoveCallback),this._onKeyUpListener=function(e){t.onKeyUp({key:e.key})},this.getMapContainer().addEventListener("keyup",this._onKeyUpListener);var i="not-dragging";this._onDragStartListener=function(t){i="pre-dragging"};var n=this.getMapContainer();n.addEventListener("mousedown",this._onDragStartListener),this._onDragListener=function(o){var s={x:o.clientX-n.offsetLeft,y:o.clientY-n.offsetTop},a=e.unproject(s.x,s.y),l=a.lat,c={lng:r(a.lng,e._coordinatePrecision),lat:r(l,e._coordinatePrecision),containerX:o.clientX-n.offsetLeft,containerY:o.clientY-n.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)};"pre-dragging"===i?(i="dragging",t.onDragStart(c,function(t){e._map.setOptions({draggable:!1})})):"dragging"===i&&t.onDrag(c)},n.addEventListener("mousemove",this._onDragListener),this._onDragEndListener=function(o){if("dragging"===i){var s={x:o.clientX-n.offsetLeft,y:o.clientY-n.offsetTop},a=e.unproject(s.x,s.y),l=a.lat;t.onDragEnd({lng:r(a.lng,e._coordinatePrecision),lat:r(l,e._coordinatePrecision),containerX:o.clientX-n.offsetLeft,containerY:o.clientY-n.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)},function(t){e._map.setOptions({draggable:t})})}i="not-dragging"},n.addEventListener("mouseup",this._onDragEndListener)},e.unregister=function(){this._onClickListener&&(this._onClickCallback=void 0,this._onClickListener.remove(),this._onClickListener=void 0),this._onRightClickListener&&(this._onClickCallback=void 0,this._onRightClickListener.remove(),this._onRightClickListener=void 0),this._onMouseMoveListener&&(this._onMouseMoveCallback=void 0,this._onMouseMoveListener.remove(),this._onMouseMoveListener=void 0),this._onKeyUpListener&&(this.getMapContainer().removeEventListener("keyup",this._onKeyUpListener),this._onKeyUpListener=void 0)},e.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)}),t.updated.forEach(function(t){if(!t||!t.id)throw new Error("Feature is not valid");var e=i._map.data.getFeatureById(t.id);if(!e)throw new Error("Feature could not be found by Google Maps API");switch(e.forEachProperty(function(t,i){e.setProperty(i,void 0)}),Object.keys(t.properties).forEach(function(i){e.setProperty(i,t.properties[i])}),t.geometry.type){case"Point":var n=t.geometry.coordinates;e.setGeometry(new google.maps.Data.Point(new google.maps.LatLng(n[1],n[0])));break;case"LineString":for(var o=t.geometry.coordinates,r=[],s=0;s<o.length;s++){var a=o[s],l=new google.maps.LatLng(a[1],a[0]);r.push(l)}e.setGeometry(new google.maps.Data.LineString(r));break;case"Polygon":for(var c=t.geometry.coordinates,h=[],d=0;d<c.length;d++){for(var u=[],p=0;p<c[d].length;p++){var g=new google.maps.LatLng(c[d][p][1],c[d][p][0]);u.push(g)}h.push(u)}e.setGeometry(new google.maps.Data.Polygon(h))}}),t.created.forEach(function(t){i._map.data.addGeoJson(t)})):(this._map.data.addListener("click",function(t){i._onClickCallback&&i._onClickCallback(t)}),this._map.data.addListener("mousemove",function(t){i._onMouseMoveCallback&&i._onMouseMoveCallback(t)}));var n={type:"FeatureCollection",features:[].concat(t.created)};this._map.data.addGeoJson(n),this._map.data.setStyle(function(t){var n=t.getProperty("mode"),o=t.getGeometry();if(!o)throw new Error("Google Maps geometry not found");var r=o.getType(),s={};t.forEachProperty(function(t,e){s[e]=t});var a=e[n]({type:"Feature",geometry:{type:r,coordinates:[]},properties:s});switch(r){case"Point":return{clickable:!1,icon:{path:i.circlePath(0,0,a.pointWidth),fillColor:a.pointColor,fillOpacity:1,strokeColor:a.pointOutlineColor,strokeWeight:a.pointOutlineWidth,rotation:0,scale:1}};case"LineString":return{strokeColor:a.lineStringColor,strokeWeight:a.lineStringWidth};case"Polygon":return{strokeColor:a.polygonOutlineColor,strokeWeight:a.polygonOutlineWidth,fillOpacity:a.polygonFillOpacity,fillColor:a.polygonFillColor}}throw Error("Unknown feature type")}),this._layers=!0},t}(),a=/*#__PURE__*/function(){function t(t){var e=this;this._heldKeys=new Set,this._lib=void 0,this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onKeyUpListener=void 0,this._onKeyDownListener=void 0,this._onDragStartListener=void 0,this._onDragListener=void 0,this._onDragEndListener=void 0,this._layer=void 0,this._panes={},this.project=void 0,this.unproject=void 0,this.setCursor=void 0,this.getMapContainer=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.getMapContainer=function(){return e._map.getContainer()},this.project=function(t,i){var n=e._map.latLngToContainerPoint({lng:t,lat:i});return{x:n.x,y:n.y}},this.unproject=function(t,i){var n=e._map.containerPointToLatLng({x:t,y:i});return{lng:n.lng,lat:n.lat}},this.setCursor=function(t){"unset"===t?e.getMapContainer().style.removeProperty("cursor"):e.getMapContainer().style.cursor=t}}var e=t.prototype;return e.createPaneStyleSheet=function(t,e){var i=document.createElement("style");return i.type="text/css",i.innerHTML=".leaflet-"+t+" {z-index: "+e+";}",document.getElementsByTagName("head")[0].appendChild(i),this._map.createPane(t),i},e.register=function(t){var e=this,i=this.getMapContainer(),n="not-dragging";this._onClickListener=function(i){"not-dragging"!==n&&"pre-dragging"!==n||t.onClick({lng:r(i.latlng.lng,e._coordinatePrecision),lat:r(i.latlng.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-e.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._map.on("mouseup",this._onClickListener),this._map.on("contextmenu",this._onClickListener),this._onMouseMoveListener=function(i){i.originalEvent.preventDefault(),t.onMouseMove({lng:r(i.latlng.lng,e._coordinatePrecision),lat:r(i.latlng.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-e.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._map.on("mousemove",this._onMouseMoveListener),this._onDragStartListener=function(t){n="pre-dragging"},i.addEventListener("pointerdown",this._onDragStartListener),this._onDragListener=function(o){var s=e._map.containerPointToLatLng({x:o.clientX-i.offsetLeft,y:o.clientY-i.offsetTop}),a=s.lat,l={lng:r(s.lng,e._coordinatePrecision),lat:r(a,e._coordinatePrecision),containerX:o.clientX-i.offsetLeft,containerY:o.clientY-i.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)};"pre-dragging"===n?(n="dragging",t.onDragStart(l,function(t){t?e._map.dragging.enable():e._map.dragging.disable()})):"dragging"===n&&t.onDrag(l)},i.addEventListener("pointermove",this._onDragListener),this._onDragEndListener=function(o){if(o.preventDefault(),"dragging"===n){var s=e._map.containerPointToLatLng({x:o.clientX-i.offsetLeft,y:o.clientY-i.offsetTop}),a=s.lat;return t.onDragEnd({lng:r(s.lng,e._coordinatePrecision),lat:r(a,e._coordinatePrecision),containerX:o.clientX-i.offsetLeft,containerY:o.clientY-i.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)},function(t){t?e._map.dragging.enable():e._map.dragging.disable()}),n="after-dragging",void e._map.dragging.enable()}n="not-dragging",e._map.dragging.enable()},i.addEventListener("pointerup",this._onDragEndListener),this._onKeyUpListener=function(i){i.preventDefault(),e._heldKeys.delete(i.key),t.onKeyUp({key:i.key})},i.addEventListener("keyup",this._onKeyUpListener),this._onKeyDownListener=function(i){i.preventDefault(),e._heldKeys.add(i.key),t.onKeyDown({key:i.key})},i.addEventListener("keydown",this._onKeyDownListener)},e.unregister=function(){var t=this;this._onClickListener&&(this._map.off("contextmenu",this._onClickListener),this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0),Object.keys(this._panes).forEach(function(e){var i=t._map.getPane(e);i&&i.remove()})},e.render=function(t,e){var i=this,n=[].concat(t.created,t.updated,t.unchanged);this._layer&&this._map.removeLayer(this._layer);var o=this._lib.geoJSON({type:"FeatureCollection",features:n},{pointToLayer:function(t,n){if(!t.properties)throw new Error("Feature has no properties");if("string"!=typeof t.properties.mode)throw new Error("Feature mode is not a string");var o=(0,e[t.properties.mode])(t),r=String(o.zIndex);return i._panes[r]||(i._panes[r]=i.createPaneStyleSheet(r,o.zIndex)),i._lib.circleMarker(n,{radius:o.pointWidth,stroke:o.pointOutlineWidth||!1,color:o.pointOutlineColor,weight:o.pointOutlineWidth,fillOpacity:.8,fillColor:o.pointColor,pane:r,interactive:!1})},style:function(t){if(!t||!t.properties)return{};var i=t,n=(0,e[i.properties.mode])(i);return"LineString"===i.geometry.type?{interactive:!1,color:n.lineStringColor,weight:n.lineStringWidth}:"Polygon"===i.geometry.type?{interactive:!1,fillOpacity:n.polygonFillOpacity,fillColor:n.polygonFillColor,weight:n.polygonOutlineWidth,stroke:!0,color:n.polygonFillColor}:{}}});this._map.addLayer(o),this._layer=o},t}(),l=/*#__PURE__*/function(){function t(t){var e=this;this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.getMapContainer=void 0,this._heldKeys=new Set,this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onDragStartListener=void 0,this._onDragListener=void 0,this._onDragEndListener=void 0,this._onKeyDownListener=void 0,this._onKeyUpListener=void 0,this._rendered={},this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,i){var n=e._map.project({lng:t,lat:i});return{x:n.x,y:n.y}},this.unproject=function(t,i){var n=e._map.unproject({x:t,y:i});return{lng:n.lng,lat:n.lat}},this.setCursor=function(t){e._map.getCanvas().style.cursor=t},this.getMapContainer=function(){return e._map.getContainer()}}var e=t.prototype;return e._addGeoJSONSource=function(t,e){this._map.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:e}})},e._addFillLayer=function(t,e){return this._map.addLayer({id:t,source:t,type:"fill",filter:["all",["match",["geometry-type"],"Polygon",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"fill-color":["get","polygonFillColor"],"fill-opacity":["get","polygonFillOpacity"]}})},e._addFillOutlineLayer=function(t,e,i){var n=this._map.addLayer({id:t+"outline",source:t,type:"line",filter:["all",["match",["geometry-type"],"Polygon",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"line-width":["get","polygonOutlineWidth"],"line-color":["get","polygonOutlineColor"]}});return i&&this._map.moveLayer(t,i),n},e._addLineLayer=function(t,e,i){var n=this._map.addLayer({id:t,source:t,type:"line",filter:["all",["match",["geometry-type"],"LineString",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"line-width":["get","lineStringWidth"],"line-color":["get","lineStringColor"]}});return i&&this._map.moveLayer(t,i),n},e._addPointLayer=function(t,e,i){var n=this._map.addLayer({id:t,source:t,type:"circle",filter:["all",["match",["geometry-type"],"Point",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"circle-stroke-color":["get","pointOutlineColor"],"circle-stroke-width":["get","pointOutlineWidth"],"circle-radius":["get","pointWidth"],"circle-color":["get","pointColor"]}});return i&&this._map.moveLayer(t,i),n},e._addLayer=function(t,e,i,n){"Point"===i&&this._addPointLayer(t,e,n),"LineString"===i&&this._addLineLayer(t,e,n),"Polygon"===i&&(this._addFillLayer(t,e),this._addFillOutlineLayer(t,e,n))},e._addGeoJSONLayer=function(t,e,i){var n="td-"+t+"-"+e.toLowerCase();return this._addGeoJSONSource(n,i),this._addLayer(n,t,e),n},e._setGeoJSONLayerData=function(t,e,i){var n="td-"+t+"-"+e.toLowerCase();return this._map.getSource(n).setData({type:"FeatureCollection",features:i}),n},e.register=function(t){var e=this;this._onClickListener=function(i){t.onClick({lng:r(i.lngLat.lng,e._coordinatePrecision),lat:r(i.lngLat.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-e.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._map.on("click",this._onClickListener),this._map.on("contextmenu",this._onClickListener),this._onMouseMoveListener=function(i){t.onMouseMove({lng:r(i.lngLat.lng,e._coordinatePrecision),lat:r(i.lngLat.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-e.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[].concat(e._heldKeys)})},this._map.on("mousemove",this._onMouseMoveListener);var i="not-dragging";this._onDragStartListener=function(t){i="pre-dragging"};var n=this.getMapContainer();n.addEventListener("mousedown",this._onDragStartListener),this._onDragListener=function(o){var s=e._map.unproject({x:o.clientX-n.offsetLeft,y:o.clientY-n.offsetTop}),a=s.lat,l={lng:r(s.lng,e._coordinatePrecision),lat:r(a,e._coordinatePrecision),containerX:o.clientX-n.offsetLeft,containerY:o.clientY-n.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)};"pre-dragging"===i?(i="dragging",t.onDragStart(l,function(t){t?e._map.dragPan.enable():e._map.dragPan.disable()})):"dragging"===i&&t.onDrag(l)},n.addEventListener("mousemove",this._onDragListener),this._onDragEndListener=function(o){if("dragging"===i){var s=e._map.unproject({x:o.clientX-n.offsetLeft,y:o.clientY-n.offsetTop}),a=s.lat;t.onDragEnd({lng:r(s.lng,e._coordinatePrecision),lat:r(a,e._coordinatePrecision),containerX:o.clientX-n.offsetLeft,containerY:o.clientY-n.offsetTop,button:0===o.button?"left":"right",heldKeys:[].concat(e._heldKeys)},function(t){t?e._map.dragPan.enable():e._map.dragPan.disable()})}i="not-dragging"},n.addEventListener("mouseup",this._onDragEndListener),this._onKeyUpListener=function(i){i.preventDefault(),e._heldKeys.delete(i.key),t.onKeyUp({key:i.key})},n.addEventListener("keyup",this._onKeyUpListener),this._onKeyDownListener=function(i){i.preventDefault(),e._heldKeys.add(i.key),t.onKeyDown({key:i.key})},n.addEventListener("keydown",this._onKeyDownListener)},e.unregister=function(){this._onClickListener&&(this._map.off("contextmenue",this._onClickListener),this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("mousemove",this._onMouseMoveListener),this._onMouseMoveListener=void 0),this._onKeyUpListener&&this._map.getCanvas().removeEventListener("keypress",this._onKeyUpListener),this._onDragStartListener&&this._map.getCanvas().removeEventListener("mousedown",this._onDragStartListener),this._onDragListener&&this._map.getCanvas().removeEventListener("mousemove",this._onDragListener),this._onDragEndListener&&this._map.getCanvas().removeEventListener("mouseup",this._onDragEndListener)},e.render=function(t,e){var i=this,n=[].concat(t.created,t.updated,t.unchanged),o={};Object.keys(e).forEach(function(t){o[t]||(o[t]={points:[],linestrings:[],polygons:[]})});for(var r=function(t){var i=n[t];Object.keys(e).forEach(function(t){var n=i.properties;if(n.mode===t){var r=e[t](i);"Point"===i.geometry.type?(n.pointColor=r.pointColor,n.pointOutlineColor=r.pointOutlineColor,n.pointOutlineWidth=r.pointOutlineWidth,n.pointWidth=r.pointWidth,o[t].points.push(i)):"LineString"===i.geometry.type?(n.lineStringColor=r.lineStringColor,n.lineStringWidth=r.lineStringWidth,o[t].linestrings.push(i)):"Polygon"===i.geometry.type&&(n.polygonFillColor=r.polygonFillColor,n.polygonFillOpacity=r.polygonFillOpacity,n.polygonOutlineColor=r.polygonOutlineColor,n.polygonOutlineWidth=r.polygonOutlineWidth,o[t].polygons.push(i))}})},s=0;s<n.length;s++)r(s);Object.keys(e).forEach(function(t){if(o[t]){var e=o[t],n=e.points,r=e.linestrings,s=e.polygons;if(i._rendered[t]){var a=i._setGeoJSONLayerData(t,"Point",n);i._setGeoJSONLayerData(t,"LineString",r),i._setGeoJSONLayerData(t,"Polygon",s),i._map.moveLayer(a)}else i._addGeoJSONLayer(t,"Point",n),i._addGeoJSONLayer(t,"LineString",r),i._addGeoJSONLayer(t,"Polygon",s),i._rendered[t]=!0}}),this._map.style&&(this._map._frame&&(this._map._frame.cancel(),this._map._frame=null),this._map._render())},t}();function c(t,e){var i=function(t){return t*Math.PI/180},n=i(t[1]),o=i(t[0]),r=i(e[1]),s=r-n,a=i(e[0])-o,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l))*6371e3/1e3}function h(t){return t%360*Math.PI/180}function d(t){return t%(2*Math.PI)*180/Math.PI}function u(t,e,i){var n=h(t[0]),o=h(t[1]),r=h(i),s=function(t){return t/6371.0088}(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[d(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),d(a)]}function p(t){for(var e=t.center,i=t.radiusKilometers,n=t.steps?t.steps:64,o=[],r=0;r<n;r++)o.push(u(e,i,-360*r/n));return o.push(o[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[o]},properties:{}}}var g=/*#__PURE__*/function(){var t=n.prototype;function n(t){this._state=void 0,this._styles=void 0,this.behaviors=[],this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.onStyleChange=void 0,this.store=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this._state="unregistered",this._styles=t&&t.styles?i({},t.styles):{},this.pointerDistance=t&&t.pointerDistance||40,this.coordinatePrecision=t&&t.coordinatePrecision||9}return t.registerBehaviors=function(t){},t.setStarted=function(){if("stopped"!==this._state&&"registered"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="started"},t.setStopped=function(){if("started"!==this._state)throw new Error("Mode must be started to be stopped");this._state="stopped"},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.project=t.project,this.unproject=t.unproject,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect,this.setCursor=t.setCursor,this.onStyleChange=t.onChange,this.registerBehaviors({mode:t.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:this.coordinatePrecision})},t.onDeselect=function(t){},t.onSelect=function(t){},t.styleFeature=function(t){},e(n,[{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}}]),n}(),f=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="circle",i.center=void 0,i.clickCount=0,i.currentCircleId=void 0,i.keyEvents=void 0,i.keyEvents=e&&e.keyEvents?e.keyEvents:{cancel:"Escape",finish:"Enter"},i}n(e,t);var o=e.prototype;return o.close=function(){this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onClick=function(t){if(0===this.clickCount){this.center=[t.lng,t.lat];var e=p({center:this.center,radiusKilometers:1e-5}),i=this.store.create([{geometry:e.geometry,properties:{mode:this.mode}}]);this.currentCircleId=i[0],this.clickCount++}else this.close()},o.onMouseMove=function(t){if(1===this.clickCount&&this.center&&this.currentCircleId){var e=c(this.center,[t.lng,t.lat]),i=p({center:this.center,radiusKilometers:e});this.store.updateGeometry([{id:this.currentCircleId,geometry:i.geometry}])}},o.onKeyDown=function(){},o.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.cleanUp=function(){try{this.currentCircleId&&this.store.delete([this.currentCircleId])}catch(t){}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},o.styleFeature=function(t){var e=i({},{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?(this.styles.fillColor&&(e.polygonFillColor=this.styles.fillColor),this.styles.outlineColor&&(e.polygonOutlineColor=this.styles.outlineColor),this.styles.outlineWidth&&(e.polygonOutlineWidth=this.styles.outlineWidth),this.styles.fillOpacity&&(e.polygonFillOpacity=this.styles.fillOpacity),e):e},e}(g),y=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.sqrt(n*n+i*i)},v=/*#__PURE__*/function(t){function e(e){var i;return(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.minDistance=e&&e.minDistance||20,i.keyEvents=e&&e.keyEvents?e.keyEvents:{cancel:"Escape",finish:"Enter"},i}n(e,t);var o=e.prototype;return o.close=function(){this.closingPointId&&this.store.delete([this.closingPointId]),this.startingClick=!1,this.currentId=void 0,this.closingPointId=void 0},o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onMouseMove=function(t){if(this.currentId&&!1!==this.startingClick){var e=this.store.getGeometryCopy(this.currentId),i=e.coordinates[0][e.coordinates[0].length-2],n=this.project(i[0],i[1]),o=y({x:n.x,y:n.y},{x:t.containerX,y:t.containerY}),r=e.coordinates[0][0],s=this.project(r[0],r[1]),a=y({x:s.x,y:s.y},{x:t.containerX,y:t.containerY});this.setCursor(a<this.pointerDistance?"pointer":"crosshair"),o<this.minDistance||(e.coordinates[0].pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[].concat(e.coordinates[0],[[t.lng,t.lat],e.coordinates[0][0]])]}}]))}},o.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,void(this.startingClick=!0)}this.close()},o.onKeyDown=function(){},o.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}this.closingPointId=void 0,this.currentId=void 0,this.startingClick=!1},o.styleFeature=function(t){var e=i({},{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?(this.styles.fillColor&&(e.polygonFillColor=this.styles.fillColor),this.styles.outlineColor&&(e.polygonOutlineColor=this.styles.outlineColor),this.styles.outlineWidth&&(e.polygonOutlineWidth=this.styles.outlineWidth),this.styles.fillOpacity&&(e.polygonFillOpacity=this.styles.fillOpacity),e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(this.styles.closingPointColor&&(e.pointColor=this.styles.closingPointColor),this.styles.closingPointWidth&&(e.pointWidth=this.styles.closingPointWidth),e.pointOutlineColor=void 0!==this.styles.closingPointOutlineColor?this.styles.closingPointOutlineColor:"#ffffff",e.pointOutlineWidth=void 0!==this.styles.closingPointOutlineWidth?this.styles.closingPointOutlineWidth:2,e):e},e}(g);function m(t){var e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}for(var i=[],n=0;n<e.length;n++)for(var o=0;o<e[n].length-1;o++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)l(n,o,r,s);return i.length>0;function a(t){return t<0||t>1}function l(t,n,o,r){var s,l=e[t][n],c=e[t][n+1],h=e[o][r],d=e[o][r+1],u=function(t,e,i,n){if(_(t,i)||_(t,n)||_(e,i)||_(n,i))return null;var o=t[0],r=t[1],s=e[0],a=e[1],l=i[0],c=i[1],h=n[0],d=n[1],u=(o-s)*(c-d)-(r-a)*(l-h);return 0===u?null:[((o*a-r*s)*(l-h)-(o-s)*(l*d-c*h))/u,((o*a-r*s)*(c-d)-(r-a)*(l*d-c*h))/u]}(l,c,h,d);null!==u&&(s=d[0]!==h[0]?(u[0]-h[0])/(d[0]-h[0]):(u[1]-h[1])/(d[1]-h[1]),a(c[0]!==l[0]?(u[0]-l[0])/(c[0]-l[0]):(u[1]-l[1])/(c[1]-l[1]))||a(s)||(u.toString(),i.push(u)))}}function _(t,e){return t[0]===e[0]&&t[1]===e[1]}var C=function(t){var e=t.store,i=t.mode,n=t.project,o=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision;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.store=e,this.mode=i,this.project=n,this.unproject=o,this.pointerDistance=r,this.coordinatePrecision=s},P=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.create=function(t){var e=t.containerX,i=t.containerY,n=this.pointerDistance/2;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[this.unproject(e-n,i-n),this.unproject(e+n,i-n),this.unproject(e+n,i+n),this.unproject(e-n,i+n),this.unproject(e-n,i-n)].map(function(t){return[t.lng,t.lat]})]}}},e}(C),M=/*#__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 y({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(C),L=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinate=function(t,e){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)})},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return n(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),o=this.store.search(n,e),r={coord:void 0,minDist:Infinity};return o.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}n.forEach(function(e){var n=i.pixelDistance.measure(t,e);n<r.minDist&&n<i.pointerDistance&&(r.coord=e)})}),r.coord},e}(C),x=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="linestring",i.currentCoordinate=0,i.currentId=void 0,i.closingPointId=void 0,i.allowSelfIntersections=void 0,i.keyEvents=void 0,i.snappingEnabled=void 0,i.snapping=void 0,i.snappingEnabled=!(!e||void 0===e.snapping)&&e.snapping,i.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections,i.keyEvents=e&&e.keyEvents?e.keyEvents:{cancel:"Escape",finish:"Enter"},i}n(e,t);var o=e.prototype;return o.close=function(){if(this.currentId){var t=this.store.getGeometryCopy(this.currentId);t.coordinates.pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[].concat(t.coordinates)}}]),this.closingPointId&&this.store.delete([this.closingPointId]),this.currentCoordinate=0,this.currentId=void 0,this.closingPointId=void 0}},o.registerBehaviors=function(t){this.snapping=new L(t,new M(t),new P(t))},o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onMouseMove=function(t){if(this.setCursor("crosshair"),this.currentId&&0!==this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);e.coordinates.pop();var i=this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];if(this.closingPointId){var n=e.coordinates[e.coordinates.length-1],o=this.project(n[0],n[1]);y({x:o.x,y:o.y},{x:t.containerX,y:t.containerY})<this.pointerDistance&&this.setCursor("pointer")}this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[].concat(e.coordinates,[i])}}])}},o.onClick=function(t){var e=this.currentId&&this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];if(0===this.currentCoordinate){var i=this.store.create([{geometry:{type:"LineString",coordinates:[e,e]},properties:{mode:this.mode}}]);this.currentId=i[0],this.currentCoordinate++}else if(1===this.currentCoordinate&&this.currentId){var n=this.store.getGeometryCopy(this.currentId),o=this.store.create([{geometry:{type:"Point",coordinates:[].concat(e)},properties:{mode:this.mode}}]);this.closingPointId=o[0],this.setCursor("pointer"),this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[n.coordinates[0],e,e]}}]),this.currentCoordinate++}else if(this.currentId){var r=this.store.getGeometryCopy(this.currentId),s=r.coordinates[r.coordinates.length-2],a=this.project(s[0],s[1]);if(y({x:a.x,y:a.y},{x:t.containerX,y:t.containerY})<this.pointerDistance)this.close();else{var l={type:"LineString",coordinates:[].concat(r.coordinates,[e])};if(!this.allowSelfIntersections&&m({type:"Feature",geometry:l,properties:{}}))return;this.closingPointId&&(this.setCursor("pointer"),this.store.updateGeometry([{id:this.currentId,geometry:l},{id:this.closingPointId,geometry:{type:"Point",coordinates:r.coordinates[r.coordinates.length-1]}}]),this.currentCoordinate++)}}},o.onKeyDown=function(){},o.onKeyUp=function(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPointId&&this.store.delete([this.closingPointId])}catch(t){}this.closingPointId=void 0,this.currentId=void 0,this.currentCoordinate=0},o.styleFeature=function(t){var e=i({},{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?(this.styles.lineStringColor&&(e.lineStringColor=this.styles.lineStringColor),this.styles.lineStringWidth&&(e.lineStringWidth=this.styles.lineStringWidth),e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(this.styles.closingPointColor&&(e.pointColor=this.styles.closingPointColor),this.styles.closingPointWidth&&(e.pointWidth=this.styles.closingPointWidth),e.pointOutlineColor=void 0!==this.styles.closingPointOutlineColor?this.styles.closingPointOutlineColor:"#ffffff",e.pointOutlineWidth=void 0!==this.styles.closingPointOutlineWidth?this.styles.closingPointOutlineWidth:2,e):e},e}(g),E=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="point",i}n(e,t);var o=e.prototype;return o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onClick=function(t){if(!this.store)throw new Error("Mode must be registered first");this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}])},o.onMouseMove=function(){},o.onKeyDown=function(){},o.onKeyUp=function(){},o.cleanUp=function(){},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.styleFeature=function(t){var e=i({},{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?(this.styles.pointColor&&(e.pointColor=this.styles.pointColor),this.styles.pointOutlineColor&&(e.pointOutlineColor=this.styles.pointOutlineColor),this.styles.pointWidth&&(e.pointWidth=this.styles.pointWidth),e):e},e}(g);function k(t,e){return t[0]===e[0]&&t[1]===e[1]}var S=/*#__PURE__*/function(t){function i(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.pixelDistance=void 0,n._startEndPoints=[],n.config=e,n.pixelDistance=i,n}n(i,t);var o=i.prototype;return o.create=function(t,e){var i,n;if(this.ids.length)throw new Error("Opening and closing points already creating");if(t.length<=3)throw new Error("Requires at least 4 cooridnates");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:(i={mode:e},i.closingPoint=!0,i)},{geometry:{type:"Point",coordinates:t[t.length-2]},properties:(n={mode:e},n.closingPoint=!0,n)}])},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]),n=this.pixelDistance.measure(t,e.coordinates),o=this.pixelDistance.measure(t,i.coordinates);return{isClosing:n<this.pointerDistance,isPreviousClosing:o<this.pointerDistance}},e(i,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}]),i}(C),w=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.allowSelfIntersections=void 0,i.keyEvents=void 0,i.snappingEnabled=void 0,i.isClosed=!1,i.snapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.snappingEnabled=!(!e||void 0===e.snapping)&&e.snapping,i.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections,i.keyEvents=e&&e.keyEvents?e.keyEvents:{cancel:"Escape",finish:"Enter"},i}n(e,t);var o=e.prototype;return o.close=function(){if(this.currentId){var t=this.store.getGeometryCopy(this.currentId).coordinates[0];t.length<5||(this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[].concat(t.slice(0,-2),[t[0]])]}}]),this.currentCoordinate=0,this.currentId=void 0,this.closingPoints.delete())}},o.registerBehaviors=function(t){this.pixelDistance=new M(t),this.snapping=new L(t,this.pixelDistance,new P(t)),this.closingPoints=new S(t,this.pixelDistance)},o.start=function(){this.setStarted(),this.setCursor("crosshair")},o.stop=function(){this.setStopped(),this.setCursor("unset"),this.cleanUp()},o.onMouseMove=function(t){if(this.setCursor("crosshair"),this.currentId&&0!==this.currentCoordinate){var e,i=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0,n=this.store.getGeometryCopy(this.currentId).coordinates[0];if(i&&(t.lng=i[0],t.lat=i[1]),1===this.currentCoordinate){var o=1/Math.pow(10,this.coordinatePrecision-1),r=Math.max(1e-6,o);e=[n[0],[t.lng,t.lat],[t.lng,t.lat+r],n[0]]}else if(2===this.currentCoordinate)e=[n[0],n[1],[t.lng,t.lat],n[0]];else{var s=this.closingPoints.isClosingPoint(t);s.isPreviousClosing||s.isClosing?(this.setCursor("pointer"),e=[].concat(n.slice(0,-2),[n[0],n[0]]),this.isClosed||(this.isClosed=!0)):(this.isClosed&&(this.isClosed=!1),e=[].concat(n.slice(0,-2),[[t.lng,t.lat],n[0]]))}this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[e]}}]),this.closingPoints.ids.length&&this.closingPoints.update(e)}},o.onClick=function(t){var e,i=this.currentId&&this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;if(0===this.currentCoordinate){i&&(t.lng=i[0],t.lat=i[1]);var n=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=n[0],this.currentCoordinate++}else if(1===this.currentCoordinate&&this.currentId){i&&(t.lng=i[0],t.lat=i[1]);var o=this.store.getGeometryCopy(this.currentId);if(k([t.lng,t.lat],o.coordinates[0][0]))return;this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[o.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]]]}}]),this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){i&&(t.lng=i[0],t.lat=i[1]);var r=this.store.getGeometryCopy(this.currentId).coordinates[0];if(k([t.lng,t.lat],r[1]))return;2===this.currentCoordinate&&this.closingPoints.create(r,"polygon"),this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[r[0],r[1],[t.lng,t.lat],[t.lng,t.lat],r[0]]]}}]),this.currentCoordinate++}else if(this.currentId){var s=this.store.getGeometryCopy(this.currentId).coordinates[0],a=this.closingPoints.isClosingPoint(t);if(a.isPreviousClosing||a.isClosing)this.close();else{if(i&&(t.lng=i[0],t.lat=i[1]),k([t.lng,t.lat],s[this.currentCoordinate-1]))return;var l=(void 0===(e=[[].concat(s.slice(0,-1),[[t.lng,t.lat],s[0]])])&&(e=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]),{type:"Feature",geometry:{type:"Polygon",coordinates:e},properties:{}});if(this.currentCoordinate>2&&!this.allowSelfIntersections&&m(l))return;this.store.updateGeometry([{id:this.currentId,geometry:l.geometry}]),this.currentCoordinate++}}},o.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},o.onKeyDown=function(){},o.onDragStart=function(){this.setCursor("unset")},o.onDrag=function(){},o.onDragEnd=function(){this.setCursor("crosshair")},o.cleanUp=function(){try{this.currentId&&this.store.delete([this.currentId]),this.closingPoints.ids.length&&this.closingPoints.delete()}catch(t){}this.currentId=void 0,this.currentCoordinate=0},o.styleFeature=function(t){var e=i({},{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.styles.fillColor||e.polygonFillColor,e.polygonOutlineColor=this.styles.outlineColor||e.polygonOutlineColor,e.polygonOutlineWidth=this.styles.outlineWidth||e.polygonOutlineWidth,e.polygonFillColor=this.styles.fillColor||e.polygonFillColor,e.zIndex=10,e;if("Point"===t.geometry.type)return e.pointWidth=this.styles.closingPointWidth||e.pointWidth,e.pointColor=this.styles.closingPointColor||e.pointColor,e.pointOutlineColor=this.styles.closingPointOutlineColor||"#ffffff",e.pointOutlineWidth=this.styles.closingPointOutlineWidth||2,e.zIndex=30,e}return e},e}(g),D=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,{styles:e.styles})||this).mode="render",i}n(e,t);var o=e.prototype;return o.registerBehaviors=function(t){this.mode=t.mode},o.start=function(){this.setStarted()},o.stop=function(){this.setStopped()},o.onKeyUp=function(){},o.onKeyDown=function(){},o.onClick=function(){},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.onMouseMove=function(){},o.styleFeature=function(){return i({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0},this.styles)},e}(g);function I(t,e,i){var n=c(t,e),o=function(t,e){var i=h(t[0]),n=h(e[0]),o=h(t[1]),r=h(e[1]),s=Math.sin(n-i)*Math.cos(r),a=Math.cos(o)*Math.sin(r)-Math.sin(o)*Math.cos(r)*Math.cos(n-i);return d(Math.atan2(s,a))}(t,e),s=u(t,n/2,o);return[r(s[0],i),r(s[1],i)]}function O(t,e){for(var i=[],n=0;n<t.length-1;n++){var o=I(t[n],t[n+1],e);i.push(o)}return i}var b=/*#__PURE__*/function(t){function i(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.selectionPointBehavior=void 0,n._midPoints=[],n.config=e,n.selectionPointBehavior=i,n}n(i,t);var o=i.prototype;return o.insert=function(t,e){var i=this.store.getGeometryCopy(t),n=this.store.getPropertiesCopy(t),o=n.midPointFeatureId,r=n.midPointSegment,s=this.store.getGeometryCopy(o),a="Polygon"===s.type?s.coordinates[0]:s.coordinates;a.splice(r+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[a]:a,this.store.updateGeometry([{id:o,geometry:s}]),this.store.delete([].concat(this._midPoints,this.selectionPointBehavior.ids)),this.create(a,o,e),this.selectionPointBehavior.create(a,s.type,o)},o.create=function(t,e,i){var n=this;if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i){return O(t,i).map(function(t,i){return{geometry:{type:"Point",coordinates:t},properties:e(i)}})}(t,function(t){var i;return(i={mode:n.mode}).midPoint=!0,i.midPointSegment=t,i.midPointFeatureId=e,i},i))},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 O(t,this.coordinatePrecision).map(function(t,i){return{id:e._midPoints[i],geometry:{type:"Point",coordinates:t}}})},e(i,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}]),i}(C),F=/*#__PURE__*/function(t){function i(e){var i;return(i=t.call(this,e)||this)._selectionPoints=[],i}n(i,t);var o=i.prototype;return o.create=function(t,e,i){var n=this;this._selectionPoints=this.store.create(function(t,e,i){for(var n=[],o="Polygon"===e?t.length-1:t.length,r=0;r<o;r++)n.push({geometry:{type:"Point",coordinates:t[r]},properties:i(r)});return n}(t,e,function(t){return{mode:n.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t}}))},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}}},e(i,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}]),i}(C);function W(t,e){for(var i,n,o,r=!1,s=0,a=e.length;s<a;s++)for(var l=e[s],c=0,h=l.length,d=h-1;c<h;d=c++)(n=l[c])[1]>(i=t)[1]!=(o=l[d])[1]>i[1]&&i[0]<(o[0]-n[0])*(i[1]-n[1])/(o[1]-n[1])+n[0]&&(r=!r);return r}var B=function(t,e,i){var n=function(t){return t*t},o=function(t,e){return n(t.x-e.x)+n(t.y-e.y)};return Math.sqrt(function(t,e,i){var n=o(e,i);if(0===n)return o(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/n;return r=Math.max(0,Math.min(1,r)),o(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},K=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.createClickBoundingBox=void 0,o.pixelDistance=void 0,o.config=e,o.createClickBoundingBox=i,o.pixelDistance=n,o}return n(e,t),e.prototype.find=function(t,e){for(var i=void 0,n=Infinity,o=void 0,r=Infinity,s=this.createClickBoundingBox.create(t),a=this.store.search(s),l=0;l<a.length;l++){var c=a[l],h=c.geometry;if("Point"===h.type){if(c.properties.selectionPoint||!e&&c.properties.midPoint)continue;var d=this.pixelDistance.measure(t,h.coordinates);c.properties.midPoint&&d<this.pointerDistance&&d<r?(r=d,o=c):!c.properties.midPoint&&d<this.pointerDistance&&d<n&&(n=d,i=c)}else if("LineString"===h.type)for(var u=0;u<h.coordinates.length-1;u++){var p=h.coordinates[u],g=h.coordinates[u+1],f=B({x:t.containerX,y:t.containerY},this.project(p[0],p[1]),this.project(g[0],g[1]));f<this.pointerDistance&&f<n&&(n=f,i=c)}else"Polygon"===h.type&&W([t.lng,t.lat],h.coordinates)&&(n=0,i=c)}return{clickedFeature:i,clickedMidPoint:o}},e}(C),j=/*#__PURE__*/function(t){function i(e,i,n,o){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.dragPosition=void 0,r.config=e,r.featuresAtMouseEvent=i,r.selectionPoints=n,r.midPoints=o,r}return n(i,t),i.prototype.drag=function(t,e){var i=this.featuresAtMouseEvent.find(t,!0).clickedFeature;if(i&&i.id===e){var n=this.store.getGeometryCopy(e),o=[t.lng,t.lat];if("Polygon"===n.type||"LineString"===n.type){var r,s;if("Polygon"===n.type?s=(r=n.coordinates[0]).length-1:"LineString"===n.type&&(s=(r=n.coordinates).length),void 0===s||!r||!this.dragPosition)return!1;for(var a=0;a<s;a++){var l=r[a],c=[this.dragPosition[0]-o[0],this.dragPosition[1]-o[1]];r[a]=[l[0]-c[0],l[1]-c[1]]}"Polygon"===n.type&&(r[r.length-1]=[r[0][0],r[0][1]]);var h=this.selectionPoints.getUpdated(r)||[],d=this.midPoints.getUpdated(r)||[];this.store.updateGeometry([{id:e,geometry:n}].concat(h,d))}else"Point"===n.type&&this.store.updateGeometry([{id:e,geometry:{type:"Point",coordinates:o}}])}},e(i,[{key:"position",get:function(){return this.dragPosition?this.dragPosition.concat():void 0},set:function(t){if(void 0!==t){if(!Array.isArray(t)||2!==t.length||"number"!=typeof t[0]||"number"!=typeof t[1])throw new Error("Position must be [number, number] array");this.dragPosition=t.concat()}else this.dragPosition=void 0}}]),i}(C),X=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.selectionPoints=void 0,r.midPoints=void 0,r.config=e,r.pixelDistance=i,r.selectionPoints=n,r.midPoints=o,r}return n(e,t),e.prototype.drag=function(t,e){var i,n=this.store.getGeometryCopy(e);if("LineString"===n.type)i=n.coordinates;else{if("Polygon"!==n.type)return!1;i=n.coordinates[0]}for(var o={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1},r=0;r<i.length;r++){var s=this.pixelDistance.measure(t,i[r]);if(s<this.pointerDistance&&s<o.dist){var a="Polygon"===n.type&&(r===i.length-1||0===r);o.dist=s,o.index=a?0:r,o.isFirstOrLastPolygonCoord=a}}if(-1===o.index)return!1;var l=[t.lng,t.lat];if(o.isFirstOrLastPolygonCoord){var c=i.length-1;i[0]=l,i[c]=l}else i[o.index]=l;var h=this.selectionPoints.getOneUpdated(o.index,l),d=h?[h]:[],u=this.midPoints.getUpdated(i)||[];return this.store.updateGeometry([{id:e,geometry:n}].concat(d,u)),!0},e}(C);function Y(t){var e=0,i=0,n=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],n++},!0),[e/n,i/n]}function G(t,e){var i=t,n=e,o=h(i[1]),r=h(n[1]),s=h(n[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),l=(d(Math.atan2(s,a))+360)%360;return l>180?-(360-l):l}function T(t,e,i){var n=e/6371008.8,o=t[0]*Math.PI/180,r=h(t[1]),s=h(i),a=n*Math.cos(s),l=r+a;Math.abs(l)>Math.PI/2&&(l=l>0?Math.PI-l:-Math.PI-l);var c=Math.log(Math.tan(l/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),d=Math.abs(c)>1e-11?a/c:Math.cos(r),u=[(180*(o+n*Math.sin(s)/d)/Math.PI+540)%360-180,180*l/Math.PI];return u[0]+=u[0]-t[0]>180?-360:t[0]-u[0]>180?360:0,u}function U(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=e[1]*Math.PI/180,n=t[1]*Math.PI/180,o=n-i,r=Math.abs(t[0]-e[0])*Math.PI/180;r>Math.PI&&(r-=2*Math.PI);var s=Math.log(Math.tan(n/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),a=Math.abs(s)>1e-11?o/s:Math.cos(i);return 6371008.8*Math.sqrt(o*o+a*a*r*r)}var A=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.lastBearing=void 0,o.config=e,o.selectionPoints=i,o.midPoints=n,o}n(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0},i.rotate=function(t,e){var i=this,n=this.store.getGeometryCopy(e);if("Polygon"===n.type||"LineString"===n.type){var o=[t.lng,t.lat],s=G(Y({type:"Feature",geometry:n,properties:{}}),o);if(this.lastBearing){var a;if(function(t,e){if(0===e)return t;var i=Y(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=G(i,t)+e,o=U(i,t),r=T(i,o,n);t[0]=r[0],t[1]=r[1]})}({type:"Feature",geometry:n,properties:{}},-(this.lastBearing-(s+180))),"Polygon"===n.type)a=n.coordinates[0];else{if("LineString"!==n.type)return;a=n.coordinates}a.forEach(function(t){t[0]=r(t[0],i.coordinatePrecision),t[1]=r(t[1],i.coordinatePrecision)});var l=this.midPoints.getUpdated(a)||[],c=this.selectionPoints.getUpdated(a)||[];this.store.updateGeometry([{id:e,geometry:n}].concat(c,l)),this.lastBearing=s+180}else this.lastBearing=s+180}},e}(C),N=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.selectionPoints=void 0,o.midPoints=void 0,o.lastDistance=void 0,o.config=e,o.selectionPoints=i,o.midPoints=n,o}n(e,t);var i=e.prototype;return i.reset=function(){this.lastDistance=void 0},i.scale=function(t,e){var i=this,n=this.store.getGeometryCopy(e);if("Polygon"===n.type||"LineString"===n.type){var o=[t.lng,t.lat],s=c(Y({type:"Feature",geometry:n,properties:{}}),o);if(this.lastDistance){var a;if(function(t,e){if(1===e)return t;var i=Y(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=U(i,t),o=G(i,t),r=T(i,n*e,o);t[0]=r[0],t[1]=r[1]})}({type:"Feature",geometry:n,properties:{}},1-(this.lastDistance-s)/s),"Polygon"===n.type)a=n.coordinates[0];else{if("LineString"!==n.type)return;a=n.coordinates}a.forEach(function(t){t[0]=r(t[0],i.coordinatePrecision),t[1]=r(t[1],i.coordinatePrecision)});var l=this.midPoints.getUpdated(a)||[],h=this.selectionPoints.getUpdated(a)||[];this.store.updateGeometry([{id:e,geometry:n}].concat(h,l)),this.lastDistance=s}else this.lastDistance=s}},e}(C),z=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).mode="select",i.dragEventThrottle=5,i.dragEventCount=0,i.selected=[],i.flags=void 0,i.keyEvents=void 0,i.selectionPoints=void 0,i.midPoints=void 0,i.featuresAtMouseEvent=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.dragFeature=void 0,i.dragCoordinate=void 0,i.rotateFeature=void 0,i.scaleFeature=void 0,i.flags=e&&e.flags?e.flags:{},i.keyEvents=e&&e.keyEvents?e.keyEvents:{deselect:"Escape",delete:"Delete",rotate:"r",scale:"s"},i.dragEventThrottle=e&&void 0!==e.dragEventThrottle&&e.dragEventThrottle||5,i}n(e,t);var o=e.prototype;return o.registerBehaviors=function(t){this.pixelDistance=new M(t),this.clickBoundingBox=new P(t),this.featuresAtMouseEvent=new K(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new F(t),this.midPoints=new b(t,this.selectionPoints),this.rotateFeature=new A(t,this.selectionPoints,this.midPoints),this.scaleFeature=new N(t,this.selectionPoints,this.midPoints),this.dragFeature=new j(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new X(t,this.pixelDistance,this.selectionPoints,this.midPoints)},o.deselect=function(){this.store.updateProperty(this.selected.map(function(t){return{id:t,property:"selected",value:!1}})),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()},o.deleteSelected=function(){this.store.delete(this.selected),this.selected=[]},o.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,n=Infinity;if(this.selectionPoints.ids.forEach(function(o){var r=e.store.getGeometryCopy(o),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<n&&(n=s,i=e.store.getPropertiesCopy(o))}),i){var o=i.selectionPointFeatureId,r=i.index,s=this.store.getPropertiesCopy(o),a=this.flags[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var l,c=this.store.getGeometryCopy(o);if("Polygon"===c.type){if((l=c.coordinates[0]).length<=4)return}else if("LineString"===c.type&&(l=c.coordinates).length<=3)return;l&&("Polygon"===c.type&&0===r||r===l.length-1?(l.shift(),l.pop(),l.push([l[0][0],l[0][1]])):l.splice(r,1),this.store.delete([].concat(this.midPoints.ids,this.selectionPoints.ids)),this.store.updateGeometry([{id:o,geometry:c}]),this.selectionPoints.create(l,c.type,o),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create(l,o,this.coordinatePrecision))}}}},o.onLeftClick=function(t){var e=this.featuresAtMouseEvent.find(t,this.selected.length>0),i=e.clickedFeature,n=e.clickedMidPoint;if(this.selected.length&&n)this.midPoints.insert(n.id,this.coordinatePrecision);else if(i){var o=this.store.getPropertiesCopy(i.id).mode,r=this.selected[0];if(r){if(r===i.id)return;this.deselect()}var s=this.flags[o];if(!s||!s.feature)return;this.selected=[i.id],this.store.updateProperty([{id:i.id,property:"selected",value:!0}]),this.onSelect(i.id);var a,l=this.store.getGeometryCopy(i.id),c=l.type,h=l.coordinates;"LineString"===c?a=h:"Polygon"===c&&(a=h[0]),a&&s&&s.feature.coordinates&&(this.selectionPoints.create(a,c,i.id),s.feature.coordinates.midpoints&&this.midPoints.create(a,i.id,this.coordinatePrecision))}else if(this.selected.length)return void this.deselect()},o.start=function(){this.setStarted()},o.stop=function(){this.setStopped(),this.cleanUp()},o.onClick=function(t){"right"!==t.button?"left"===t.button&&this.onLeftClick(t):this.onRightClick(t)},o.onKeyDown=function(){},o.onKeyUp=function(t){if(t.key===this.keyEvents.delete){if(!this.selected.length)return;this.onDeselect(this.selected[0]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else t.key===this.keyEvents.deselect&&this.cleanUp()},o.cleanUp=function(){this.selected.length&&this.deselect()},o.onDragStart=function(t,e){if(this.selected.length){var i=this.store.getPropertiesCopy(this.selected[0]),n=this.flags[i.mode];n&&n.feature&&(n.feature.draggable||n.feature.coordinates&&n.feature.coordinates.draggable)&&(this.dragEventCount=0,this.setCursor("grabbing"),this.dragFeature.position=[t.lng,t.lat],e(!1))}},o.onDrag=function(t){var e=this.selected[0];if(e&&this.dragFeature.position){var i=this.store.getPropertiesCopy(e),n=this.flags[i.mode];if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0)if(n&&n.feature&&n.feature.rotateable&&t.heldKeys.includes("r"))this.rotateFeature.rotate(t,e);else if(n&&n.feature&&n.feature.scaleable&&t.heldKeys.includes("s"))this.scaleFeature.scale(t,e);else{if(n&&n.feature&&n.feature.coordinates&&n.feature.coordinates.draggable&&this.dragCoordinate.drag(t,e))return;n&&n.feature&&n.feature.draggable&&(this.dragFeature.drag(t,e),this.dragFeature.position=[t.lng,t.lat])}}},o.onDragEnd=function(t,e){this.setCursor("grab"),this.dragFeature.position=void 0,this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0)},o.onMouseMove=function(t){var e=this;if(this.selected.length&&!this.dragFeature.position){var i=!1;this.midPoints.ids.forEach(function(n){if(!i){var o=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,o.coordinates)<e.pointerDistance&&(i=!0)}}),this.selectionPoints.ids.forEach(function(n){var o=e.store.getGeometryCopy(n);e.pixelDistance.measure(t,o.coordinates)<e.pointerDistance&&(i=!1)}),this.setCursor(i?"crosshair":"unset")}},o.styleFeature=function(t){var e=i({},{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 this.styles.selectedColor&&(e.polygonFillColor=this.styles.selectedColor),this.styles.selectedColor&&(e.polygonOutlineColor=this.styles.selectedColor),e.zIndex=10,e;if("Point"===t.geometry.type){if(t.properties.selectionPoint)return e.pointColor=this.styles.selectionPointColor||e.pointColor,e.pointOutlineColor=this.styles.selectionPointOutlineColor||e.pointOutlineColor,e.pointWidth=this.styles.selectionPointWidth||e.pointWidth,e.pointOutlineWidth=this.styles.midPointOutlineWidth||2,e.zIndex=30,e;if(t.properties.midPoint)return e.pointColor=this.styles.midPointColor||e.pointColor,e.pointOutlineColor=this.styles.midPointOutlineColor||e.pointOutlineColor,e.pointWidth=this.styles.midPointWidth||4,e.pointOutlineWidth=this.styles.midPointOutlineWidth||2,e.zIndex=40,e}}return e},e}(g),J=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).mode="static",e}n(e,t);var o=e.prototype;return o.start=function(){},o.stop=function(){},o.onKeyUp=function(){},o.onKeyDown=function(){},o.onClick=function(){},o.onDragStart=function(){},o.onDrag=function(){},o.onDragEnd=function(){},o.onMouseMove=function(){},o.styleFeature=function(){return i({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#ffffff",pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,zIndex:0})},e}(g),R=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)})};function q(t,e,i,n,o){for(;n>i;){if(n-i>600){var r=n-i+1,s=e-i+1,a=Math.log(r),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(r-l)/r)*(s-r/2<0?-1:1);q(t,e,Math.max(i,Math.floor(e-s*l/r+c)),Math.min(n,Math.floor(e+(r-s)*l/r+c)),o)}var h=t[e],d=i,u=n;for(H(t,i,e),o(t[n],h)>0&&H(t,i,n);d<u;){for(H(t,d,u),d++,u--;o(t[d],h)<0;)d++;for(;o(t[u],h)>0;)u--}0===o(t[i],h)?H(t,i,u):H(t,++u,n),u<=e&&(i=u+1),e<=u&&(n=u-1)}}function H(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function Z(t,e){Q(t,0,t.children.length,e,t)}function Q(t,e,i,n,o){o||(o=rt([])),o.minX=Infinity,o.minY=Infinity,o.maxX=-Infinity,o.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];V(o,t.leaf?n(s):s)}return o}function V(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 $(t,e){return t.minX-e.minX}function tt(t,e){return t.minY-e.minY}function et(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function it(t){return t.maxX-t.minX+(t.maxY-t.minY)}function nt(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function ot(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function rt(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function st(t,e,i,n,o){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=n)){var s=e+Math.ceil((i-e)/n/2)*n;q(t,s,e,i,o),r.push(e,s,s,i)}}var at=/*#__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(!ot(t,e))return i;for(var n=this.toBBox,o=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?n(s):s;ot(t,a)&&(e.leaf?i.push(s):nt(t,a)?this._all(s,i):o.push(s))}e=o.pop()}return i},e.collides=function(t){var e=this.data;if(ot(t,e))for(var i=[];e;){for(var n=0;n<e.children.length;n++){var o=e.children[n],r=e.leaf?this.toBBox(o):o;if(ot(t,r)){if(e.leaf||nt(t,r))return!0;i.push(o)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var n=this.data;this.data=i,i=n}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=rt([])},e.remove=function(t){for(var e,i,n=this.data,o=this.toBBox(t),r=[],s=[],a=!1;n||r.length;){if(n||(n=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),n.leaf){var l=n.children.indexOf(t);-1!==l&&(n.children.splice(l,1),r.push(n),this._condense(r))}a||n.leaf||!nt(n,o)?i?(e++,n=i.children[e],a=!1):n=null:(r.push(n),s.push(e),e=0,i=n,n=n.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,n){var o,r=i-e+1,s=this._maxEntries;if(r<=s)return Z(o=rt(t.slice(e,i+1)),this.toBBox),o;n||(n=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,n-1))),(o=rt([])).leaf=!1,o.height=n;var a=Math.ceil(r/s),l=a*Math.ceil(Math.sqrt(s));st(t,e,i,l,this.compareMinX);for(var c=e;c<=i;c+=l){var h=Math.min(c+l-1,i);st(t,c,h,a,this.compareMinY);for(var d=c;d<=h;d+=a){var u=Math.min(d+a-1,h);o.children.push(this._build(t,d,u,n-1))}}return Z(o,this.toBBox),o},e._chooseSubtree=function(t,e,i,n){for(;n.push(e),!e.leaf&&n.length-1!==i;){for(var o=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var l=e.children[a],c=et(l),h=(d=t,u=l,(Math.max(u.maxX,d.maxX)-Math.min(u.minX,d.minX))*(Math.max(u.maxY,d.maxY)-Math.min(u.minY,d.minY))-c);h<r?(r=h,o=c<o?c:o,s=l):h===r&&c<o&&(o=c,s=l)}e=s||e.children[0]}var d,u;return e},e._insert=function(t,e,i){var n=i?t:this.toBBox(t),o=[],r=this._chooseSubtree(n,this.data,e,o);for(r.children.push(t),V(r,n);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)},e._split=function(t,e){var i=t[e],n=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,n);var r=this._chooseSplitIndex(i,o,n),s=rt(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,Z(i,this.toBBox),Z(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=rt([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Z(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var n,o,r,s,a,l,c,h=Infinity,d=Infinity,u=e;u<=i-e;u++){var p=Q(t,0,u,this.toBBox),g=Q(t,u,i,this.toBBox),f=(o=p,r=g,s=Math.max(o.minX,r.minX),a=Math.max(o.minY,r.minY),l=Math.min(o.maxX,r.maxX),c=Math.min(o.maxY,r.maxY),Math.max(0,l-s)*Math.max(0,c-a)),y=et(p)+et(g);f<h?(h=f,n=u,d=y<d?y:d):f===h&&y<d&&(d=y,n=u)}return n||i-e},e._chooseSplitAxis=function(t,e,i){var n=t.leaf?this.compareMinX:$,o=t.leaf?this.compareMinY:tt;this._allDistMargin(t,e,i,n)<this._allDistMargin(t,e,i,o)&&t.children.sort(n)},e._allDistMargin=function(t,e,i,n){t.children.sort(n);for(var o=this.toBBox,r=Q(t,0,e,o),s=Q(t,i-e,i,o),a=it(r)+it(s),l=e;l<i-e;l++){var c=t.children[l];V(r,t.leaf?o(c):c),a+=it(r)}for(var h=i-e-1;h>=e;h--){var d=t.children[h];V(s,t.leaf?o(d):d),a+=it(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var n=i;n>=0;n--)V(e[n],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():Z(t[i],this.toBBox)},t}(),lt=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new at(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(String(t.id),e),this.nodeToId.set(e,String(t.id))},e.toBBox=function(t){var e,i=[],n=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var o=0;o<e.length;o++)n.push(e[o][1]),i.push(e[o][0]);var r=Math.min.apply(Math,n),s=Math.max.apply(Math,n);return{minX:Math.min.apply(Math,i),minY:r,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],n=new Set;t.forEach(function(t){var o=e.toBBox(t);if(e.setMaps(t,o),n.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);n.add(String(t.id)),i.push(o)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),ct=/*#__PURE__*/function(){function t(t){this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=function(){},this.store={},this.spatialIndex=new lt,this.tracked=!t||!1!==t.tracked,t&&t.data&&this.load(t.data,t.validateFeature)}var e=t.prototype;return e.getId=function(){return R()},e.clone=function(t){return JSON.parse(JSON.stringify(t))},e.has=function(t){return Boolean(this.store[t])},e.load=function(t,e){var i=this;if(0!==t.length){var n=this.clone(t);n.forEach(function(t){t.id||(t.id=R()),i.tracked&&(t.properties.createdAt||(t.properties.createdAt=+new Date),t.properties.updatedAt||(t.properties.updatedAt=+new Date))});var o=[];n.forEach(function(t){e&&e(t),i.store[t.id]=t,o.push(t.id)}),this.spatialIndex.load(n),this._onChange(o,"create")}},e.search=function(t,e){var i=this,n=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?n.filter(e):n)},e.registerOnChange=function(t){this._onChange=function(e,i){t(e,i)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t){var e=this,i=[];t.forEach(function(t){var n=t.id,o=t.property,r=t.value,s=e.store[n];if(!s)throw new Error("No feature with this ("+n+"), can not update geometry");i.push(n),s.properties[o]=r,e.tracked&&(s.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.updateGeometry=function(t){var e=this,i=[];t.forEach(function(t){var n=t.id,o=t.geometry;i.push(n);var r=e.store[n];if(!r)throw new Error("No feature with this ("+n+"), can not update geometry");r.geometry=e.clone(o),e.spatialIndex.update(r),e.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(i,"update")},e.create=function(t){var e=this,n=[];return t.forEach(function(t){var o,r=t.geometry,s=t.properties,a=i({},s);e.tracked&&(o=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:o,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:o):a={createdAt:o,updatedAt:o});var l=e.getId(),c={id:l,type:"Feature",geometry:r,properties:a};e.store[l]=c,e.spatialIndex.insert(c),n.push(l)}),this._onChange&&this._onChange([].concat(n),"create"),n},e.delete=function(t){var e=this;t.forEach(function(t){if(!e.store[t])throw new Error("No feature with this id, can not delete");delete e.store[t],e.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete")},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},t}();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._adapter=t.adapter,this._mode=new J,this._modes=i({},t.modes,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[]},this._store=t.data?new ct({data:t.data}):new ct;var n=function(t){var i=[],n=e._store.copyAll().filter(function(e){return!t.includes(e.id)||(i.push(e),!1)});return{changed:i,unchanged:n}},o=function(t,i){e._eventListeners.change.forEach(function(e){e(t,i)});var o=n(t),r=o.changed,s=o.unchanged;"create"===i?e._adapter.render({created:r,deletedIds:[],unchanged:s,updated:[]},e.getModeStyles()):"update"===i?e._adapter.render({created:[],deletedIds:[],unchanged:s,updated:r},e.getModeStyles()):"delete"===i?e._adapter.render({created:[],deletedIds:t,unchanged:s,updated:[]},e.getModeStyles()):"styling"===i&&e._adapter.render({created:[],deletedIds:[],unchanged:s,updated:[]},e.getModeStyles())},r=function(t){e._eventListeners.select.forEach(function(e){e(t)});var i=n([t]);e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:i.changed},e.getModeStyles())},s=function(t){e._eventListeners.deselect.forEach(function(t){t()});var i=n([t]),o=i.changed;o&&e._adapter.render({created:[],deletedIds:[],unchanged:i.unchanged,updated:o},e.getModeStyles())};if(Object.keys(this._modes).forEach(function(t){e._modes[t].register({mode:t,store:e._store,setCursor:e._adapter.setCursor,project:e._adapter.project,unproject:e._adapter.unproject,onChange:o,onSelect:r,onDeselect:s})}),t.data){var a=this._store.copyAll().filter(function(t){return!(t.properties&&!Object.keys(e._modes).includes(t.properties.mode)&&(e._store.delete([t.id]),1))});this._adapter.render({created:a,deletedIds:[],unchanged:[],updated:[]},this.getModeStyles())}}var n=t.prototype;return n.getModeStyles=function(){var t=this,e={};return Object.keys(this._modes).forEach(function(i){e[i]=t._modes[i].styleFeature.bind(t._modes[i])}),e},n.setModeStyles=function(t,e){this._modes[t].styles=e},n.getSnapshot=function(){return this._store.copyAll()},n.getCurrentMode=function(){return this._mode.mode},n.changeMode=function(t){if(!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()},n.start=function(){var t=this;this._enabled=!0,this._adapter.register({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){t._mode.onDrag(e)},onDragEnd:function(e,i){t._mode.onDragEnd(e,i)}})},n.stop=function(){this._enabled=!1,this._adapter.unregister()},n.on=function(t,e){var i=this._eventListeners[t];i.includes(e)||i.push(e)},n.off=function(t,e){var i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)},e(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}]),t}(),exports.TerraDrawCircleMode=f,exports.TerraDrawFreehandMode=v,exports.TerraDrawGoogleMapsAdapter=s,exports.TerraDrawLeafletAdapter=a,exports.TerraDrawLineStringMode=x,exports.TerraDrawMapboxGLAdapter=l,exports.TerraDrawPointMode=E,exports.TerraDrawPolygonMode=w,exports.TerraDrawRenderMode=D,exports.TerraDrawSelectMode=z;
|
|
2
2
|
//# sourceMappingURL=terra-draw.cjs.map
|