terra-draw 0.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +27 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +5 -0
- package/CODE_OF_CONDUCT.md +36 -0
- package/CONTRIBUTING.md +17 -0
- package/DEVELOPMENT.md +77 -0
- package/LICENSE +8 -0
- package/README.md +19 -0
- package/ROADMAP.md +63 -0
- package/common/addModeChangeHandler.ts +26 -0
- package/data/sample.ts +10126 -0
- package/dist/adapters/google-maps.adapter.d.ts +38 -0
- package/dist/adapters/leaflet.adapter.d.ts +35 -0
- package/dist/adapters/mapbox-gl.adapter.d.ts +36 -0
- package/dist/bundle.js +6 -0
- package/dist/bundle.js.LICENSE.txt +4 -0
- package/dist/common.d.ts +99 -0
- package/dist/geometry/boolean/point-in-polygon.d.ts +2 -0
- package/dist/geometry/boolean/self-intersects.d.ts +2 -0
- package/dist/geometry/centroid.d.ts +2 -0
- package/dist/geometry/coordinates-identical.d.ts +2 -0
- package/dist/geometry/create-circle.d.ts +6 -0
- package/dist/geometry/get-coordinates-as-points.d.ts +6 -0
- package/dist/geometry/get-midpoints.d.ts +7 -0
- package/dist/geometry/get-pixel-distance-to-line.d.ts +10 -0
- package/dist/geometry/get-pixel-distance.d.ts +7 -0
- package/dist/geometry/haversine-distance.d.ts +1 -0
- package/dist/geometry/helpers.d.ts +4 -0
- package/dist/geometry/limit-decimal-precision.d.ts +1 -0
- package/dist/geometry/measure/haversine-distance.d.ts +2 -0
- package/dist/geometry/measure/pixel-distance-to-line.d.ts +10 -0
- package/dist/geometry/measure/pixel-distance.d.ts +7 -0
- package/dist/geometry/measure/rhumb-bearing.d.ts +2 -0
- package/dist/geometry/measure/rhumb-destination.d.ts +2 -0
- package/dist/geometry/measure/rhumb-distance.d.ts +2 -0
- package/dist/geometry/midpoint-coordinate.d.ts +2 -0
- package/dist/geometry/point-in-polygon.d.ts +1 -0
- package/dist/geometry/self-intersects.d.ts +2 -0
- package/dist/geometry/shape/create-circle.d.ts +7 -0
- package/dist/geometry/transform/rotate.d.ts +2 -0
- package/dist/geometry/transform/scale.d.ts +2 -0
- package/dist/modes/base.behavior.d.ts +19 -0
- package/dist/modes/base.mode.d.ts +30 -0
- package/dist/modes/circle/circle.mode.d.ts +27 -0
- package/dist/modes/circle.mode.d.ts +18 -0
- package/dist/modes/click-bounding-box.behavior.d.ts +7 -0
- package/dist/modes/freehand/freehand.mode.d.ts +29 -0
- package/dist/modes/freehand.mode.d.ts +20 -0
- package/dist/modes/line-string.mode.d.ts +21 -0
- package/dist/modes/linestring/linestring.mode.d.ts +34 -0
- package/dist/modes/pixel-distance.behavior.d.ts +7 -0
- package/dist/modes/point/point.mode.d.ts +18 -0
- package/dist/modes/point.mode.d.ts +14 -0
- package/dist/modes/polygon/behaviors/start-end-point.behavior.d.ts +11 -0
- package/dist/modes/polygon/polygon.mode.d.ts +37 -0
- package/dist/modes/polygon.mode.d.ts +21 -0
- package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +13 -0
- package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +17 -0
- package/dist/modes/select/behaviors/features-at-mouse-event.behavior.d.ts +15 -0
- package/dist/modes/select/behaviors/midpoint.behavior.d.ts +18 -0
- package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +13 -0
- package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +13 -0
- package/dist/modes/select/behaviors/selection-point.behavior.d.ts +18 -0
- package/dist/modes/select/select.mode.d.ts +62 -0
- package/dist/modes/select.mode.d.ts +21 -0
- package/dist/modes/snapping.behavior.d.ts +13 -0
- package/dist/modes/static/static.mode.d.ts +13 -0
- package/dist/modes/static.mode.d.ts +10 -0
- package/dist/store/spatial-index/quickselect.d.ts +2 -0
- package/dist/store/spatial-index/rbush.d.ts +35 -0
- package/dist/store/spatial-index/spatial-index.d.ts +18 -0
- package/dist/store/store.d.ts +48 -0
- package/dist/terra-draw.cjs +2 -0
- package/dist/terra-draw.cjs.map +1 -0
- package/dist/terra-draw.d.ts +47 -0
- package/dist/terra-draw.modern.js +2 -0
- package/dist/terra-draw.modern.js.map +1 -0
- package/dist/terra-draw.module.js +2 -0
- package/dist/terra-draw.module.js.map +1 -0
- package/dist/terra-draw.umd.js +2 -0
- package/dist/terra-draw.umd.js.map +1 -0
- package/dist/util/geoms.d.ts +3 -0
- package/dist/util/id.d.ts +1 -0
- package/dist/util/styling.d.ts +2 -0
- package/jest.config.ts +27 -0
- package/package.json +86 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(t[i]=o[i])}return t},t.apply(this,arguments)}function e(t,e){void 0===e&&(e=9);var o=Math.pow(10,e);return Math.round(t*o)/o}var o=/*#__PURE__*/function(){function t(t){var e=this;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._onClickCallback=void 0,this._onKeyUpListener=void 0,this._layers=void 0,this.project=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,o){var i=e._map.getBounds(),n=new e._lib.LatLng(i.getNorthEast().lat(),i.getSouthWest().lng()),r=e._map.getProjection(),s=r.fromLatLngToPoint(n),l=r.fromLatLngToPoint({lng:t,lat:o}),a=Math.pow(2,e._map.getZoom());return{x:Math.floor((l.x-s.x)*a),y:Math.floor((l.y-s.y)*a)}}}var o=t.prototype;return o.circlePath=function(t,e,o){return"M "+t+" "+e+" m -"+o+", 0 a "+o+","+o+" 0 1,0 "+2*o+",0 a "+o+","+o+" 0 1,0 -"+2*o+",0"},o.register=function(t){var o=this;this._onClickCallback=function(i){t.onClick({lng:e(i.latLng.lng(),o._coordinatePrecision),lat:e(i.latLng.lat(),o._coordinatePrecision),containerX:i.domEvent.clientX-o._map.getDiv().offsetLeft,containerY:i.domEvent.clientY-o._map.getDiv().offsetTop})},this._onClickListener=this._map.addListener("click",this._onClickCallback),this._onMouseMoveCallback=function(i){t.onMouseMove({lng:e(i.latLng.lng(),o._coordinatePrecision),lat:e(i.latLng.lat(),o._coordinatePrecision),containerX:i.domEvent.clientX,containerY:i.domEvent.clientY})},this._onMouseMoveListener=this._map.addListener("mousemove",this._onMouseMoveCallback),this._onKeyUpListener=function(e){t.onKeyPress({key:e.key})},this._map.getDiv().addEventListener("keyup",this._onKeyUpListener)},o.unregister=function(){this._onClickListener&&(this._onClickCallback=void 0,this._onClickListener.remove(),this._onClickListener=void 0),this._onMouseMoveListener&&(this._onMouseMoveCallback=void 0,this._onMouseMoveListener.remove(),this._onMouseMoveListener=void 0),this._onKeyUpListener&&(this._map.getDiv().removeEventListener("keyup",this._onKeyUpListener),this._onKeyUpListener=void 0)},o.render=function(t,e){var o=this;this._layers?this._map.data.forEach(function(t){o._map.data.remove(t)}):(this._map.data.addListener("click",function(t){o._onClickCallback(t)}),this._map.data.addListener("mousemove",function(t){o._onMouseMoveCallback(t)})),console.log(t),this._map.data.addGeoJson({type:"FeatureCollection",features:t}),this._map.data.setStyle(function(t){var i=t.getProperty("mode"),n=t.getGeometry().getType(),r=t.getProperty("selected");switch(n){case"Point":return{icon:{path:o.circlePath(e[i].pointWidth,e[i].pointWidth,e[i].pointWidth),fillColor:r?e[i].selectedColor:e[i].pointColor,fillOpacity:1,strokeWeight:0,rotation:0,scale:1}};case"LineString":return{strokeColor:r?e[i].selectedColor:e[i].lineStringColor,strokeWeight:e[i].lineStringWidth};case"Polygon":return console.log("STYLING",e,i,e[i]),{strokeColor:e[i].polygonOutlineColor,strokeWeight:e[i].polygonOutlineWidth,fillOpacity:e[i].polygonFillOpacity,fillColor:r?e[i].selectedColor:e[i].polygonFillColor}}}),this._layers=!0},t}(),i=/*#__PURE__*/function(){function t(t){var e=this;this._lib=void 0,this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onKeyPressListener=void 0,this._layer=void 0,this.project=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,o){var i=e._map.latLngToContainerPoint({lng:t,lat:o});return{x:i.x,y:i.y}}}var o=t.prototype;return o.register=function(t){var o=this;this._onClickListener=function(i){i.originalEvent.preventDefault(),t.onClick({lng:e(i.latlng.lng,o._coordinatePrecision),lat:e(i.latlng.lat,o._coordinatePrecision),containerX:i.originalEvent.clientX-o._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-o._map.getContainer().offsetTop})},this._map.on("click",this._onClickListener),this._onMouseMoveListener=function(i){i.originalEvent.preventDefault(),t.onMouseMove({lng:e(i.latlng.lng,o._coordinatePrecision),lat:e(i.latlng.lat,o._coordinatePrecision),containerX:i.originalEvent.clientX-o._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-o._map.getContainer().offsetTop})},this._map.on("mousemove",this._onMouseMoveListener),this._onKeyPressListener=function(e){e.originalEvent.preventDefault(),t.onKeyPress({key:e.originalEvent.key})},this._map.on("keyup",this._onKeyPressListener)},o.unregister=function(){this._onClickListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0)},o.render=function(t,e){var o=this;this._layer&&this._map.removeLayer(this._layer);var i=this._lib.geoJSON({type:"FeatureCollection",features:t},{pointToLayer:function(t,i){var n=e[t.properties.mode];return o._lib.circleMarker(i,{radius:n.pointWidth,fillColor:t.properties.selected?n.selectedColor:n.pointColor,color:n.pointOutlineColor,weight:1,opacity:1,fillOpacity:.8})},style:function(t){var o=e[t.properties.mode];return"LineString"===t.geometry.type?{color:t.properties.selected?o.selectedColor:o.lineStringColor,weight:o.lineStringWidth}:"Polygon"===t.geometry.type?{fillOpacity:o.polygonFillOpacity,color:t.properties.selected?o.selectedColor:o.polygonFillColor}:void 0}});i.addTo(this._map),this._layer=i},t}(),n=/*#__PURE__*/function(){function t(t){var e=this;this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onKeyPressListener=void 0,this._rendered=!1,this.project=void 0,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,o){var i=e._map.project({lng:t,lat:o});return{x:i.x,y:i.y}}}var o=t.prototype;return o._addGeoJSONSource=function(t,e){this._map.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:e}})},o._addFillLayer=function(t,e,o){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","selectedStyle"],"fill-opacity":o.polygonFillOpacity}})},o._addFillOutlineLayer=function(t,e,o){return 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":o.polygonOutlineWidth,"line-color":["get","selectedStyle"]}})},o._addLineLayer=function(t,e,o){return 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":o.lineStringWidth,"line-color":["get","selectedStyle"]}})},o._addPointLayer=function(t,e,o){return 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-radius":o.pointWidth,"circle-color":["get","selectedStyle"]}})},o._addLayer=function(t,e,o,i){"Point"===o&&this._addPointLayer(t,e,i),"LineString"===o&&this._addLineLayer(t,e,i),"Polygon"===o&&(this._addFillLayer(t,e,i),this._addFillOutlineLayer(t,e,i))},o._addGeoJSONLayer=function(t,e,o,i){var n=t+"-"+e.toLowerCase();this._addGeoJSONSource(n,o),this._addLayer(n,t,e,i)},o._setGeoJSONLayerData=function(t,e,o){var i=t+"-"+e.toLowerCase();this._map.getSource(i).setData({type:"FeatureCollection",features:o})},o.register=function(t){var o=this;this._onClickListener=function(i){i.preventDefault(),t.onClick({lng:e(i.lngLat.lng,o._coordinatePrecision),lat:e(i.lngLat.lat,o._coordinatePrecision),containerX:i.originalEvent.clientX-o._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-o._map.getContainer().offsetTop})},this._map.on("click",this._onClickListener),this._onMouseMoveListener=function(i){i.preventDefault(),t.onMouseMove({lng:e(i.lngLat.lng,o._coordinatePrecision),lat:e(i.lngLat.lat,o._coordinatePrecision),containerX:i.originalEvent.clientX-o._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-o._map.getContainer().offsetTop})},this._map.on("mousemove",this._onMouseMoveListener),this._onKeyPressListener=function(e){e.preventDefault(),t.onKeyPress({key:e.key})},this._map.getCanvas().addEventListener("keyup",this._onKeyPressListener)},o.unregister=function(){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._onKeyPressListener&&this._map.getCanvas().removeEventListener("keypress",this._onKeyPressListener)},o.render=function(t,e){var o=this,i=function(t,e){return e.filter(function(e){return e.geometry.type===t})},n=function(n){Object.keys(e).forEach(function(r){var s=e[r],l=t.filter(function(t){return t.properties.mode===r}),a=i("Point",l);a.forEach(function(t){t.properties.selectedStyle=t.properties.selected?s.selectedColor:s.pointColor});var c=i("LineString",l);c.forEach(function(t){t.properties.selectedStyle=t.properties.selected?s.selectedColor:s.lineStringColor});var h=i("Polygon",l);h.forEach(function(t){t.properties.selectedStyle=t.properties.selected?s.selectedColor:s.polygonFillColor}),"create"===n?(o._addGeoJSONLayer(r,"Point",a,s),o._addGeoJSONLayer(r,"LineString",c,s),o._addGeoJSONLayer(r,"Polygon",h,s)):"update"===n&&(o._setGeoJSONLayerData(r,"Point",a),o._setGeoJSONLayerData(r,"LineString",c),o._setGeoJSONLayerData(r,"Polygon",h))})};this._rendered?n("update"):(n("create"),this._rendered=!0)},t}();function r(t){return t%360*Math.PI/180}function s(t){return t%(2*Math.PI)*180/Math.PI}function l(t){for(var e,o,i,n,l,a,c,h,d=t.center,u=t.radiusKilometers,p=t.steps?t.steps:64,y=[],g=0;g<p;g++)y.push((o=u,i=-360*g/p,n=r((e=d)[0]),l=r(e[1]),a=r(i),c=function(t){return t/6371.0088}(o),h=Math.asin(Math.sin(l)*Math.cos(c)+Math.cos(l)*Math.sin(c)*Math.cos(a)),[s(n+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(l),Math.cos(c)-Math.sin(l)*Math.sin(h))),s(h)]));return y.push(y[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[y]},properties:{}}}var a=/*#__PURE__*/function(){function e(e){this.mode="circle",this.store=void 0,this.project=void 0,this.center=void 0,this.clickCount=0,this.currentCircleId=void 0,this.styling=void 0,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onClick=function(t){if(0===this.clickCount){this.center=[t.lng,t.lat];var e=l({center:this.center,radiusKilometers:1e-5});this.currentCircleId=this.store.create(e.geometry,{mode:this.mode}),this.clickCount++}else this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},o.onMouseMove=function(t){if(1===this.clickCount){var e=(n=[t.lng,t.lat],s=(r=function(t){return t*Math.PI/180})((i=this.center)[1]),a=r(i[0]),h=(c=r(n[1]))-s,d=r(n[0])-a,u=Math.sin(h/2)*Math.sin(h/2)+Math.cos(s)*Math.cos(c)*Math.sin(d/2)*Math.sin(d/2),2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u))*6371e3/1e3),o=l({center:this.center,radiusKilometers:e});this.store.updateGeometry(this.currentCircleId,o.geometry)}var i,n,r,s,a,c,h,d,u},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentCircleId)}catch(t){}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},e}(),c=/*#__PURE__*/function(){function e(e){this.mode="freehand",this.store=void 0,this.project=void 0,this.startingClick=!1,this.currentId=void 0,this.skip=0,this.everyNthMouseEvent=void 0,this.styling=void 0,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},this.everyNthMouseEvent=e&&e.everyNthMouseEvent||10}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},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(this.currentId,{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)return this.currentId=this.store.create({type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},{mode:this.mode}),void(this.startingClick=!0);this.startingClick=!1,this.currentId=void 0},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentId)}catch(t){}this.currentId=void 0,this.startingClick=!1},e}();function h(t){var e;"Polygon"===t.geometry.type?e=t.geometry.coordinates:"LineString"===t.geometry.type&&(e=[t.geometry.coordinates]);for(var o=[],i=0;i<e.length;i++)for(var n=0;n<e[i].length-1;n++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)a(i,n,r,s);return o.length>0;function l(t){return t<0||t>1}function a(t,i,n,r){var s,a=e[t][i],c=e[t][i+1],h=e[n][r],u=e[n][r+1],p=function(t,e,o,i){if(d(t,o)||d(t,i)||d(e,o)||d(i,o))return null;var n=t[0],r=t[1],s=e[0],l=e[1],a=o[0],c=o[1],h=i[0],u=i[1],p=(n-s)*(c-u)-(r-l)*(a-h);return 0===p?null:[((n*l-r*s)*(a-h)-(n-s)*(a*u-c*h))/p,((n*l-r*s)*(c-u)-(r-l)*(a*u-c*h))/p]}(a,c,h,u);null!==p&&(s=u[0]!==h[0]?(p[0]-h[0])/(u[0]-h[0]):(p[1]-h[1])/(u[1]-h[1]),l(c[0]!==a[0]?(p[0]-a[0])/(c[0]-a[0]):(p[1]-a[1])/(c[1]-a[1]))||l(s)||(p.toString(),o.push(p)))}}function d(t,e){return t[0]===e[0]&&t[1]===e[1]}var u=function(t,e){var o=e.x-t.x,i=e.y-t.y;return Math.sqrt(i*i+o*o)},p=/*#__PURE__*/function(){function e(e){this.mode="linestring",this.store=void 0,this.project=void 0,this.pointerDistance=void 0,this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=void 0,this.styling=void 0,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},this.pointerDistance=e&&e.pointerDistance||40,this.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onMouseMove=function(t){if(this.currentId&&0!==this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);e.coordinates.pop(),this.store.updateGeometry(this.currentId,{type:"LineString",coordinates:[].concat(e.coordinates,[[t.lng,t.lat]])})}},o.onClick=function(t){if(0===this.currentCoordinate)this.currentId=this.store.create({type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},{mode:this.mode}),this.currentCoordinate++;else if(1===this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry(this.currentId,{type:"LineString",coordinates:[e.coordinates[0],[t.lng,t.lat],[t.lng,t.lat]]}),this.currentCoordinate++}else{var o=this.store.getGeometryCopy(this.currentId),i=o.coordinates[o.coordinates.length-2],n=this.project(i[0],i[1]);if(u({x:n.x,y:n.y},{x:t.containerX,y:t.containerY})<this.pointerDistance)o.coordinates.pop(),this.store.updateGeometry(this.currentId,{type:"LineString",coordinates:[].concat(o.coordinates)}),this.currentCoordinate=0,this.currentId=void 0;else{var r={type:"LineString",coordinates:[].concat(o.coordinates,[[t.lng,t.lat]])};if(!this.allowSelfIntersections&&h({type:"Feature",geometry:r,properties:{}}))return;this.store.updateGeometry(this.currentId,r),this.currentCoordinate++}}},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentId)}catch(t){}this.currentId=void 0,this.currentCoordinate=0},e}(),y=/*#__PURE__*/function(){function e(e){this.mode="point",this.store=void 0,this.styling=void 0,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange)},o.onClick=function(t){if(!this.store)throw new Error("Mode must be registered first");this.store.create({type:"Point",coordinates:[t.lng,t.lat]},{mode:this.mode})},o.onMouseMove=function(){},o.onKeyPress=function(){},o.cleanUp=function(){},e}(),g=/*#__PURE__*/function(){function e(e){this.mode="polygon",this.store=void 0,this.project=void 0,this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=void 0,this.pointerDistance=void 0,this.styling=void 0,this.pointerDistance=e&&e.pointerDistance||40,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},this.allowSelfIntersections=!e||void 0===e.allowSelfIntersections||e.allowSelfIntersections}var o=e.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onMouseMove=function(t){if(this.currentId&&0!==this.currentCoordinate){var e,o=this.store.getGeometryCopy(this.currentId).coordinates[0];e=1===this.currentCoordinate?[o[0],[t.lng,t.lat],o[0],o[0]]:2===this.currentCoordinate?[o[0],o[1],[t.lng,t.lat],o[0]]:[].concat(o.slice(0,-2),[[t.lng,t.lat],o[0]]),this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[e]})}},o.onClick=function(t){if(0===this.currentCoordinate)this.currentId=this.store.create({type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},{mode:this.mode}),this.currentCoordinate++;else if(1===this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[[e.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],e.coordinates[0][0]]]}),this.currentCoordinate++}else if(2===this.currentCoordinate){var o=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[[o.coordinates[0][0],o.coordinates[0][1],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]]]}),this.currentCoordinate++}else{var i=this.store.getGeometryCopy(this.currentId),n=i.coordinates[0][0],r=this.project(n[0],n[1]),s=u({x:r.x,y:r.y},{x:t.containerX,y:t.containerY});if(console.log(s,this.pointerDistance),s<this.pointerDistance)this.currentCoordinate=0,this.currentId=void 0;else{var l={type:"Polygon",coordinates:[[].concat(i.coordinates[0].slice(0,-1),[[t.lng,t.lat],i.coordinates[0][0]])]};if(this.currentCoordinate>2&&!this.allowSelfIntersections&&h({type:"Feature",geometry:l,properties:{}}))return void this.store.updateGeometry(this.currentId,i);console.log(l),this.store.updateGeometry(this.currentId,l),this.currentCoordinate++}}},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentId)}catch(t){}this.currentId=void 0,this.currentCoordinate=0},e}();function f(t,e){for(var o,i,n,r=!1,s=0,l=e.length;s<l;s++)for(var a=e[s],c=0,h=a.length,d=h-1;c<h;d=c++)(i=a[c])[1]>(o=t)[1]!=(n=a[d])[1]>o[1]&&o[0]<(n[0]-i[0])*(o[1]-i[1])/(n[1]-i[1])+i[0]&&(r=!r);return r}var v=function(t,e,o){var i=function(t){return t*t},n=function(t,e){return i(t.x-e.x)+i(t.y-e.y)};return Math.sqrt(function(t,e,o){var i=n(e,o);if(0===i)return n(t,e);var r=((t.x-e.x)*(o.x-e.x)+(t.y-e.y)*(o.y-e.y))/i;return r=Math.max(0,Math.min(1,r)),n(t,{x:e.x+r*(o.x-e.x),y:e.y+r*(o.y-e.y)})}(t,e,o))},C=/*#__PURE__*/function(){function e(e){this.mode="select",this.store=void 0,this.project=void 0,this.selected=[],this.pointerDistance=void 0,this.styling=void 0,this.pointerDistance=e&&e.pointerDistance||40,this.styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var o=e.prototype;return o.onClick=function(t){for(var e,o=this.store.copyAll(),i=Infinity,n=0;n<o.length;n++){var r=o[n],s=r.geometry;if("Point"===s.type){var l=this.project(s.coordinates[0],s.coordinates[1]),a=u({x:l.x,y:l.y},{x:t.containerX,y:t.containerY});a<this.pointerDistance&&a<i&&(i=a,e=r.id)}else if("LineString"===s.type)for(var c=0;c<s.coordinates.length-1;c++){var h=s.coordinates[c],d=s.coordinates[c+1],p=v({x:t.containerX,y:t.containerY},this.project(h[0],h[1]),this.project(d[0],d[1]));p<this.pointerDistance&&p<i&&(i=p,e=r.id)}else"Polygon"===s.type&&f([t.lng,t.lat],s.coordinates)&&(i=0,e=r.id)}e?(this.selected=[e],this.onSelect(e)):this.selected.length&&(this.selected=[],this.onDeselect())},o.onKeyPress=function(t){var e=this;if("Delete"===t.key){if(!this.selected.length)return;this.selected.forEach(function(t){e.store.delete(t)}),this.selected=[],this.onDeselect()}else"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){this.selected.length&&this.onDeselect(),this.selected=[]},o.onMouseMove=function(){},o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect},o.onDeselect=function(){},o.onSelect=function(t){},e}(),_=/*#__PURE__*/function(){function t(){this.mode="static",this.styling={polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var e=t.prototype;return e.register=function(){},e.onKeyPress=function(){},e.onClick=function(){},e.onMouseMove=function(){},e.cleanUp=function(){},t}(),m=/*#__PURE__*/function(){function t(t){var e=this;this.store=void 0,this._onChange=void 0,this.store={},t&&t.data&&t.data.forEach(function(t){e.featureValidation(t),e.store[t.id]=t})}var e=t.prototype;return e.featureValidation=function(t){if(!t||!t.id)throw new Error("Feature has no id");if("string"!=typeof t.id||36!==t.id.length)throw new Error("Feature must have uuid4 ID "+t.id);if(!t.geometry)throw new Error("Feature has no geometry");if(!t.properties)throw new Error("Feature has no properties");if(!["Polygon","LineString","Point"].includes(t.geometry.type))throw new Error("Feature is not Point, LineString or Polygon");if(!Array.isArray(t.geometry.coordinates))throw new Error("Feature coordinates is not an array")},e.getId=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},e.registerOnChange=function(t){this._onChange=function(e,o){t(e,o)}},e.updateGeometry=function(t,e){var o=this.store[t];if(!o)throw new Error("No feature with this id, can not update geometry");return o.geometry=JSON.parse(JSON.stringify(e)),this._onChange&&this._onChange(t,"update"),t},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id, can not get geometry copy");return JSON.parse(JSON.stringify(e.geometry))},e.create=function(t,e){void 0===e&&(e={});var o=this.getId();return this.store[o]={id:o,type:"Feature",geometry:t,properties:e},this._onChange&&this._onChange(o,"create"),o},e.delete=function(t){if(!this.store[t])throw new Error("No feature with this id, can not delete");delete this.store[t],this._onChange&&this._onChange(t,"delete")},e.copyAll=function(){var t=this;return JSON.parse(JSON.stringify(Object.keys(this.store).map(function(e){return t.store[e]})))},t}(),L=/*#__PURE__*/function(){function e(e){var o=this;if(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=e.adapter,this._mode=new _,this._modes=t({},e.modes,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[]},e.data){this._store=new m({data:e.data});var i=this._store.copyAll().filter(function(t){return!!Object.keys(o._modes).includes(t.properties.mode)||(o._store.delete(t.id),!1)});this._adapter.render(i,this.getModeStyles())}else this._store=new m;Object.keys(this._modes).forEach(function(t){o._modes[t].register({store:o._store,project:o._adapter.project,onChange:function(t,e){o._eventListeners.change.forEach(function(o){o(t,e)}),o._adapter.render(o._store.copyAll(),o.getModeStyles())},onSelect:function(t){o._eventListeners.select.forEach(function(e){e(t)});var e=o._store.copyAll();e.forEach(function(e){e.id===t&&(e.properties.selected=!0)}),o._adapter.render(e,o.getModeStyles())},onDeselect:function(){o._eventListeners.deselect.forEach(function(t){t()});var t=o._store.copyAll();o._adapter.render(t,o.getModeStyles())}})})}var o,i,n=e.prototype;return n.getModeStyles=function(){var t=this,e={};return Object.keys(this._modes).forEach(function(o){e[o]=t._modes[o].styling}),e},n.getSnapshot=function(){return this._store.copyAll()},n.changeMode=function(t){if(!this._modes[t])throw new Error("No mode with this name present");this._mode.cleanUp(),this._mode=this._modes[t]},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)},onKeyPress:function(e){t._mode.onKeyPress(e)}})},n.stop=function(){this._enabled=!1,this._adapter.unregister()},n.on=function(t,e){var o=this._eventListeners[t];o.includes(e)||o.push(e)},n.off=function(t,e){var o=this._eventListeners[t];o.includes(e)&&o.splice(o.indexOf(e),1)},o=e,(i=[{key:"enabled",get:function(){return this._enabled}}])&&function(t,e){for(var o=0;o<e.length;o++){var i=e[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}(o.prototype,i),Object.defineProperty(o,"prototype",{writable:!1}),e}();export{L as TerraDraw,a as TerraDrawCircleMode,c as TerraDrawFreehandMode,o as TerraDrawGoogleMapsAdapter,i as TerraDrawLeafletAdapter,p as TerraDrawLineStringMode,n as TerraDrawMapboxGLAdapter,y as TerraDrawPointMode,g as TerraDrawPolygonMode,C as TerraDrawSelectMode};
|
|
2
|
+
//# sourceMappingURL=terra-draw.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terra-draw.module.js","sources":["../src/geometry/limit-decimal-precision.ts","../src/adapters/google-maps.adapter.ts","../src/adapters/leaflet.adapter.ts","../src/adapters/mapbox-gl.adapter.ts","../src/geometry/create-circle.ts","../src/util/styling.ts","../src/modes/circle.mode.ts","../src/geometry/haversine-distance.ts","../src/modes/freehand.mode.ts","../src/geometry/self-intersects.ts","../src/geometry/get-pixel-distance.ts","../src/modes/line-string.mode.ts","../src/modes/point.mode.ts","../src/modes/polygon.mode.ts","../src/geometry/point-in-polygon.ts","../src/geometry/get-pixel-distance-to-line.ts","../src/modes/select.mode.ts","../src/modes/static.mode.ts","../src/store/store.ts","../src/util/id.ts","../src/terra-draw.ts"],"sourcesContent":["export function limitPrecision(num: number, decimalLimit = 9) {\n const decimals = Math.pow(10, decimalLimit);\n return Math.round(num * decimals) / decimals;\n}\n","import {\n TerraDrawCallbacks,\n TerraDrawAdapter,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { Feature, GeoJsonObject } from \"geojson\";\n\nimport { limitPrecision } from \"../geometry/limit-decimal-precision\";\n\nexport class TerraDrawGoogleMapsAdapter implements TerraDrawAdapter {\n constructor(config: {\n lib: typeof google.maps;\n map: google.maps.Map;\n coordinatePrecision?: number;\n }) {\n this._lib = config.lib;\n this._map = config.map;\n this._coordinatePrecision =\n typeof config.coordinatePrecision === \"number\"\n ? config.coordinatePrecision\n : 9;\n\n this.project = (lng: number, lat: number) => {\n const bounds = this._map.getBounds();\n const northWest = new this._lib.LatLng(\n bounds.getNorthEast().lat(),\n bounds.getSouthWest().lng()\n );\n const projection = this._map.getProjection();\n const projectedNorthWest = projection.fromLatLngToPoint(northWest);\n const projected = projection.fromLatLngToPoint({ lng, lat });\n\n const scale = Math.pow(2, this._map.getZoom());\n return {\n x: Math.floor((projected.x - projectedNorthWest.x) * scale),\n y: Math.floor((projected.y - projectedNorthWest.y) * scale),\n };\n };\n }\n\n private _coordinatePrecision: number;\n private _lib: typeof google.maps;\n private _map: google.maps.Map;\n private _onMouseMoveListener: google.maps.MapsEventListener;\n private _onMouseMoveCallback: (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => void;\n private _onClickListener: google.maps.MapsEventListener;\n private _onClickCallback: (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => void;\n private _onKeyUpListener: any;\n private _layers: boolean;\n\n public project: TerraDrawModeRegisterConfig[\"project\"];\n\n // https://stackoverflow.com/a/27905268/1363484\n private circlePath(cx: number, cy: number, r: number) {\n return (\n \"M \" +\n cx +\n \" \" +\n cy +\n \" m -\" +\n r +\n \", 0 a \" +\n r +\n \",\" +\n r +\n \" 0 1,0 \" +\n r * 2 +\n \",0 a \" +\n r +\n \",\" +\n r +\n \" 0 1,0 -\" +\n r * 2 +\n \",0\"\n );\n }\n\n register(callbacks: TerraDrawCallbacks) {\n this._onClickCallback = (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => {\n callbacks.onClick({\n lng: limitPrecision(event.latLng.lng(), this._coordinatePrecision),\n lat: limitPrecision(event.latLng.lat(), this._coordinatePrecision),\n containerX: event.domEvent.clientX - this._map.getDiv().offsetLeft,\n containerY: event.domEvent.clientY - this._map.getDiv().offsetTop,\n });\n };\n this._onClickListener = this._map.addListener(\n \"click\",\n this._onClickCallback\n );\n\n this._onMouseMoveCallback = (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => {\n callbacks.onMouseMove({\n lng: limitPrecision(event.latLng.lng(), this._coordinatePrecision),\n lat: limitPrecision(event.latLng.lat(), this._coordinatePrecision),\n containerX: event.domEvent.clientX,\n containerY: event.domEvent.clientY,\n });\n };\n this._onMouseMoveListener = this._map.addListener(\n \"mousemove\",\n this._onMouseMoveCallback\n );\n\n this._onKeyUpListener = (event: KeyboardEvent) => {\n callbacks.onKeyPress({ key: event.key });\n };\n\n this._map.getDiv().addEventListener(\"keyup\", this._onKeyUpListener);\n }\n\n unregister() {\n if (this._onClickListener) {\n this._onClickCallback = undefined;\n this._onClickListener.remove();\n this._onClickListener = undefined;\n }\n if (this._onMouseMoveListener) {\n this._onMouseMoveCallback = undefined;\n this._onMouseMoveListener.remove();\n this._onMouseMoveListener = undefined;\n }\n\n if (this._onKeyUpListener) {\n this._map.getDiv().removeEventListener(\"keyup\", this._onKeyUpListener);\n this._onKeyUpListener = undefined;\n }\n }\n\n render(\n features: Feature[],\n styling: { [mode: string]: TerraDrawAdapterStyling }\n ) {\n if (this._layers) {\n this._map.data.forEach((layer) => {\n this._map.data.remove(layer);\n });\n } else {\n // Clicking on data geometries triggers\n // swallows the map onclick event,\n // so we need to forward it to the click callback handler\n this._map.data.addListener(\n \"click\",\n (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => {\n this._onClickCallback(event);\n }\n );\n\n this._map.data.addListener(\n \"mousemove\",\n (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => {\n this._onMouseMoveCallback(event);\n }\n );\n }\n\n console.log(features);\n\n // features.forEach((feature) => {\n // if (feature.geometry.type === \"Polygon\") {\n // console.log(feature.geometry.coordinates);\n\n // if (feature.geometry.coordinates[0].length === 2) {\n // feature.geometry.coordinates[0] = [\n // feature.geometry.coordinates[0][0],\n // feature.geometry.coordinates[0][1],\n // feature.geometry.coordinates[0][1],\n // feature.geometry.coordinates[0][0],\n // ];\n // } else if (feature.geometry.coordinates[0].length === 3) {\n // feature.geometry.coordinates[0] = [\n // feature.geometry.coordinates[0][0],\n // feature.geometry.coordinates[0][1],\n // feature.geometry.coordinates[0][2],\n // feature.geometry.coordinates[0][0],\n // ];\n // } else if (feature.geometry.coordinates[0].length > 3) {\n // feature.geometry.coordinates[0] = [\n // feature.geometry.coordinates[0][0],\n // feature.geometry.coordinates[0][1],\n // feature.geometry.coordinates[0][2],\n // feature.geometry.coordinates[0][0],\n // ]\n // }\n // }\n // });\n\n const featureCollection = {\n type: \"FeatureCollection\",\n features,\n } as GeoJsonObject;\n\n this._map.data.addGeoJson(featureCollection);\n\n this._map.data.setStyle((feature) => {\n const mode = feature.getProperty(\"mode\");\n const type = feature.getGeometry().getType();\n const selected = feature.getProperty(\"selected\");\n\n switch (type) {\n case \"Point\":\n return {\n icon: {\n path: this.circlePath(\n styling[mode].pointWidth,\n styling[mode].pointWidth,\n styling[mode].pointWidth\n ),\n fillColor: selected\n ? styling[mode].selectedColor\n : styling[mode].pointColor,\n fillOpacity: 1,\n strokeWeight: 0,\n rotation: 0,\n scale: 1,\n },\n };\n\n case \"LineString\":\n return {\n strokeColor: selected\n ? styling[mode].selectedColor\n : styling[mode].lineStringColor,\n strokeWeight: styling[mode].lineStringWidth,\n };\n case \"Polygon\":\n console.log(\"STYLING\", styling, mode, styling[mode]);\n return {\n strokeColor: styling[mode].polygonOutlineColor,\n strokeWeight: styling[mode].polygonOutlineWidth,\n fillOpacity: styling[mode].polygonFillOpacity,\n fillColor: selected\n ? styling[mode].selectedColor\n : styling[mode].polygonFillColor,\n };\n }\n\n return;\n });\n\n this._layers = true;\n }\n}\n","import {\n TerraDrawCallbacks,\n TerraDrawAdapter,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { Feature, GeoJsonObject } from \"geojson\";\nimport L from \"leaflet\";\nimport { limitPrecision } from \"../geometry/limit-decimal-precision\";\n\nexport class TerraDrawLeafletAdapter implements TerraDrawAdapter {\n constructor(config: {\n lib: typeof L;\n map: L.Map;\n coordinatePrecision?: number;\n }) {\n this._lib = config.lib;\n this._map = config.map;\n this._coordinatePrecision =\n typeof config.coordinatePrecision === \"number\"\n ? config.coordinatePrecision\n : 9;\n\n this.project = (lng: number, lat: number) => {\n const { x, y } = this._map.latLngToContainerPoint({ lng, lat });\n return { x, y };\n };\n }\n\n private _lib: typeof L;\n private _coordinatePrecision: number;\n private _map: L.Map;\n private _onMouseMoveListener: (ev: any) => void;\n private _onClickListener: (ev: any) => void;\n private _onKeyPressListener: (ev: any) => void;\n private _layer: L.Layer;\n\n public project: TerraDrawModeRegisterConfig[\"project\"];\n\n register(callbacks: TerraDrawCallbacks) {\n this._onClickListener = (event: L.LeafletMouseEvent) => {\n event.originalEvent.preventDefault();\n\n callbacks.onClick({\n lng: limitPrecision(event.latlng.lng, this._coordinatePrecision),\n lat: limitPrecision(event.latlng.lat, this._coordinatePrecision),\n containerX:\n event.originalEvent.clientX - this._map.getContainer().offsetLeft,\n containerY:\n event.originalEvent.clientY - this._map.getContainer().offsetTop,\n });\n };\n\n this._map.on(\"click\", this._onClickListener);\n\n this._onMouseMoveListener = (event: L.LeafletMouseEvent) => {\n event.originalEvent.preventDefault();\n\n callbacks.onMouseMove({\n lng: limitPrecision(event.latlng.lng, this._coordinatePrecision),\n lat: limitPrecision(event.latlng.lat, this._coordinatePrecision),\n containerX:\n event.originalEvent.clientX - this._map.getContainer().offsetLeft,\n containerY:\n event.originalEvent.clientY - this._map.getContainer().offsetTop,\n });\n };\n\n this._map.on(\"mousemove\", this._onMouseMoveListener);\n\n this._onKeyPressListener = (event: L.LeafletKeyboardEvent) => {\n event.originalEvent.preventDefault();\n\n callbacks.onKeyPress({ key: event.originalEvent.key });\n };\n\n this._map.on(\"keyup\", this._onKeyPressListener);\n }\n\n unregister() {\n if (this._onClickListener) {\n this._map.off(\"click\", this._onClickListener);\n this._onClickListener = undefined;\n }\n if (this._onMouseMoveListener) {\n this._map.off(\"click\", this._onClickListener);\n this._onClickListener = undefined;\n }\n }\n\n render(\n features: Feature[],\n styling: { [mode: string]: TerraDrawAdapterStyling }\n ) {\n if (this._layer) {\n this._map.removeLayer(this._layer);\n }\n\n const featureCollection = {\n type: \"FeatureCollection\",\n features,\n } as GeoJsonObject;\n\n // Style points - convert markers to circle markers\n const pointToLayer = (feature: Feature, latlng: L.LatLngExpression) => {\n const mode = feature.properties.mode;\n const modeStyle = styling[mode];\n\n return this._lib.circleMarker(latlng, {\n radius: modeStyle.pointWidth,\n fillColor: feature.properties.selected\n ? modeStyle.selectedColor\n : modeStyle.pointColor,\n color: modeStyle.pointOutlineColor,\n weight: 1,\n opacity: 1,\n fillOpacity: 0.8,\n });\n };\n\n // Style LineStrings and Polygons\n const style = (feature: Feature) => {\n const mode = feature.properties.mode;\n const modeStyle = styling[mode];\n\n if (feature.geometry.type === \"LineString\") {\n return {\n color: feature.properties.selected\n ? modeStyle.selectedColor\n : modeStyle.lineStringColor,\n\n weight: modeStyle.lineStringWidth,\n };\n } else if (feature.geometry.type === \"Polygon\") {\n return {\n fillOpacity: modeStyle.polygonFillOpacity,\n color: feature.properties.selected\n ? modeStyle.selectedColor\n : modeStyle.polygonFillColor,\n };\n }\n };\n\n const layer = this._lib.geoJSON(featureCollection, {\n pointToLayer,\n style,\n });\n\n layer.addTo(this._map);\n\n this._layer = layer;\n }\n}\n","import {\n TerraDrawCallbacks,\n TerraDrawAdapter,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { Feature, LineString, Point, Polygon } from \"geojson\";\nimport { limitPrecision } from \"../geometry/limit-decimal-precision\";\nimport { CircleLayer, FillLayer, LineLayer } from \"mapbox-gl\";\nimport { GeoJSONStoreFeatures, GeoJSONStoreGeometries } from \"../store/store\";\n\nexport class TerraDrawMapboxGLAdapter implements TerraDrawAdapter {\n constructor(config: { map: mapboxgl.Map; coordinatePrecision: number }) {\n this._map = config.map;\n this._coordinatePrecision =\n typeof config.coordinatePrecision === \"number\"\n ? config.coordinatePrecision\n : 9;\n\n this.project = (lng: number, lat: number) => {\n const { x, y } = this._map.project({ lng, lat });\n return { x, y };\n };\n }\n\n private _coordinatePrecision: number;\n private _map: mapboxgl.Map;\n private _onMouseMoveListener: (\n event: mapboxgl.MapMouseEvent & mapboxgl.EventData\n ) => void;\n private _onClickListener: (\n event: mapboxgl.MapMouseEvent & mapboxgl.EventData\n ) => void;\n private _onKeyPressListener: (event: KeyboardEvent) => any;\n private _rendered: boolean = false;\n\n public project: TerraDrawModeRegisterConfig[\"project\"];\n\n private _addGeoJSONSource(id: string, features: Feature[]) {\n this._map.addSource(id, {\n type: \"geojson\",\n data: {\n type: \"FeatureCollection\",\n features: features,\n },\n });\n }\n\n private _addFillLayer(\n id: string,\n mode: string,\n styling: TerraDrawAdapterStyling\n ) {\n return this._map.addLayer({\n id,\n source: id,\n type: \"fill\",\n filter: [\n \"all\",\n [\"match\", [\"geometry-type\"], \"Polygon\", true, false],\n [\"match\", [\"get\", \"mode\"], mode, true, false],\n ],\n paint: {\n \"fill-color\": [\"get\", \"selectedStyle\"],\n \"fill-opacity\": styling.polygonFillOpacity,\n },\n } as FillLayer);\n }\n\n private _addFillOutlineLayer(\n id: string,\n mode: string,\n styling: TerraDrawAdapterStyling\n ) {\n return this._map.addLayer({\n id: id + \"outline\",\n source: id,\n type: \"line\",\n filter: [\n \"all\",\n [\"match\", [\"geometry-type\"], \"Polygon\", true, false],\n [\"match\", [\"get\", \"mode\"], mode, true, false],\n ],\n paint: {\n \"line-width\": styling.polygonOutlineWidth,\n \"line-color\": [\"get\", \"selectedStyle\"],\n },\n } as LineLayer);\n }\n\n private _addLineLayer(\n id: string,\n mode: string,\n styling: TerraDrawAdapterStyling\n ) {\n return this._map.addLayer({\n id,\n source: id,\n type: \"line\",\n filter: [\n \"all\",\n [\"match\", [\"geometry-type\"], \"LineString\", true, false],\n [\"match\", [\"get\", \"mode\"], mode, true, false],\n ],\n paint: {\n \"line-width\": styling.lineStringWidth,\n \"line-color\": [\"get\", \"selectedStyle\"],\n },\n } as LineLayer);\n }\n\n private _addPointLayer(\n id: string,\n mode: string,\n styling: TerraDrawAdapterStyling\n ) {\n return this._map.addLayer({\n id,\n source: id,\n type: \"circle\",\n filter: [\n \"all\",\n [\"match\", [\"geometry-type\"], \"Point\", true, false],\n [\"match\", [\"get\", \"mode\"], mode, true, false],\n ],\n paint: {\n \"circle-radius\": styling.pointWidth,\n \"circle-color\": [\"get\", \"selectedStyle\"],\n },\n } as CircleLayer);\n }\n\n private _addLayer(\n id: string,\n mode: string,\n featureType: \"Point\" | \"LineString\" | \"Polygon\",\n styling: TerraDrawAdapterStyling\n ) {\n if (featureType === \"Point\") {\n this._addPointLayer(id, mode, styling);\n }\n if (featureType === \"LineString\") {\n this._addLineLayer(id, mode, styling);\n }\n if (featureType === \"Polygon\") {\n this._addFillLayer(id, mode, styling);\n this._addFillOutlineLayer(id, mode, styling);\n }\n }\n\n private _addGeoJSONLayer<T extends GeoJSONStoreGeometries>(\n mode: string,\n featureType: Feature<T>[\"geometry\"][\"type\"],\n features: Feature<T>[],\n styling: TerraDrawAdapterStyling\n ) {\n const id = `${mode}-${featureType.toLowerCase()}`;\n\n this._addGeoJSONSource(id, features);\n\n this._addLayer(id, mode, featureType, styling);\n }\n\n private _setGeoJSONLayerData<T extends GeoJSONStoreGeometries>(\n mode: string,\n featureType: Feature<T>[\"geometry\"][\"type\"],\n features: Feature<T>[]\n ) {\n const id = `${mode}-${featureType.toLowerCase()}`;\n (this._map.getSource(id) as any).setData({\n type: \"FeatureCollection\",\n features: features,\n });\n }\n register(callbacks: TerraDrawCallbacks) {\n this._onClickListener = (event) => {\n event.preventDefault();\n\n callbacks.onClick({\n lng: limitPrecision(event.lngLat.lng, this._coordinatePrecision),\n lat: limitPrecision(event.lngLat.lat, this._coordinatePrecision),\n containerX:\n event.originalEvent.clientX - this._map.getContainer().offsetLeft,\n containerY:\n event.originalEvent.clientY - this._map.getContainer().offsetTop,\n });\n };\n this._map.on(\"click\", this._onClickListener);\n\n this._onMouseMoveListener = (event) => {\n event.preventDefault();\n\n callbacks.onMouseMove({\n lng: limitPrecision(event.lngLat.lng, this._coordinatePrecision),\n lat: limitPrecision(event.lngLat.lat, this._coordinatePrecision),\n containerX:\n event.originalEvent.clientX - this._map.getContainer().offsetLeft,\n containerY:\n event.originalEvent.clientY - this._map.getContainer().offsetTop,\n });\n };\n this._map.on(\"mousemove\", this._onMouseMoveListener);\n\n // map has no keypress event, so we add one to the canvas itself\n this._onKeyPressListener = (event: KeyboardEvent) => {\n event.preventDefault();\n\n callbacks.onKeyPress({ key: event.key });\n };\n this._map.getCanvas().addEventListener(\"keyup\", this._onKeyPressListener);\n }\n\n unregister() {\n if (this._onClickListener) {\n this._map.off(\"click\", this._onClickListener);\n this._onClickListener = undefined;\n }\n if (this._onMouseMoveListener) {\n this._map.off(\"mousemove\", this._onMouseMoveListener);\n this._onMouseMoveListener = undefined;\n }\n\n if (this._onKeyPressListener) {\n this._map\n .getCanvas()\n .removeEventListener(\"keypress\", this._onKeyPressListener);\n }\n }\n\n render(\n features: GeoJSONStoreFeatures[],\n styling: { [mode: string]: TerraDrawAdapterStyling }\n ) {\n const getFeatureOfType = <T extends GeoJSONStoreGeometries>(\n type: T[\"type\"],\n features: GeoJSONStoreFeatures[]\n ) => {\n return features.filter((f) => f.geometry.type === type) as Feature<T>[];\n };\n\n const createUpdateGeoJSONLayers = (method: \"create\" | \"update\") => {\n Object.keys(styling).forEach((mode) => {\n const styles = styling[mode];\n\n const modeFeatures = features.filter((f) => f.properties.mode === mode);\n\n const points = getFeatureOfType<Point>(\"Point\", modeFeatures);\n\n points.forEach((feature) => {\n if (feature.properties.selected) {\n feature.properties.selectedStyle = styles.selectedColor;\n } else {\n feature.properties.selectedStyle = styles.pointColor;\n }\n });\n\n const lines = getFeatureOfType<LineString>(\"LineString\", modeFeatures);\n\n lines.forEach((feature) => {\n if (feature.properties.selected) {\n feature.properties.selectedStyle = styles.selectedColor;\n } else {\n feature.properties.selectedStyle = styles.lineStringColor;\n }\n });\n\n const polygons = getFeatureOfType<Polygon>(\"Polygon\", modeFeatures);\n\n polygons.forEach((feature) => {\n if (feature.properties.selected) {\n feature.properties.selectedStyle = styles.selectedColor;\n } else {\n feature.properties.selectedStyle = styles.polygonFillColor;\n }\n });\n\n if (method === \"create\") {\n this._addGeoJSONLayer<Point>(mode, \"Point\", points, styles);\n this._addGeoJSONLayer<LineString>(mode, \"LineString\", lines, styles);\n this._addGeoJSONLayer<Polygon>(mode, \"Polygon\", polygons, styles);\n } else if (method === \"update\") {\n this._setGeoJSONLayerData<Point>(mode, \"Point\", points);\n this._setGeoJSONLayerData<LineString>(mode, \"LineString\", lines);\n this._setGeoJSONLayerData<Polygon>(mode, \"Polygon\", polygons);\n }\n });\n };\n\n if (!this._rendered) {\n createUpdateGeoJSONLayers(\"create\");\n this._rendered = true;\n } else {\n createUpdateGeoJSONLayers(\"update\");\n }\n }\n}\n","import { Feature, Polygon } from \"geojson\";\n\n// Based on Turf.js Circl module\n// https://github.com/Turfjs/turf/blob/master/packages/turf-circle/index.ts\n\nfunction degreesToRadians(degrees: number): number {\n const radians = degrees % 360;\n return (radians * Math.PI) / 180;\n}\n\nfunction lengthToRadians(distance: number): number {\n const earthRadius = 6371008.8;\n const factor = earthRadius / 1000;\n return distance / factor;\n}\n\nfunction radiansToDegrees(radians: number): number {\n const degrees = radians % (2 * Math.PI);\n return (degrees * 180) / Math.PI;\n}\n\nfunction destination(\n origin: [lng: number, lat: number],\n distance: number,\n bearing: number\n): [number, number] {\n const longitude1 = degreesToRadians(origin[0]);\n const latitude1 = degreesToRadians(origin[1]);\n const bearingRad = degreesToRadians(bearing);\n const radians = lengthToRadians(distance);\n\n // Main\n const latitude2 = Math.asin(\n Math.sin(latitude1) * Math.cos(radians) +\n Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad)\n );\n const longitude2 =\n longitude1 +\n Math.atan2(\n Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),\n Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2)\n );\n const lng = radiansToDegrees(longitude2);\n const lat = radiansToDegrees(latitude2);\n\n return [lng, lat];\n}\n\nexport function circle(options: {\n center: [number, number];\n radiusKilometers: number;\n steps?: number;\n}): Feature<Polygon> {\n const { center, radiusKilometers } = options;\n const steps = options.steps ? options.steps : 64;\n\n const coordinates: [number, number][] = [];\n for (let i = 0; i < steps; i++) {\n coordinates.push(destination(center, radiusKilometers, (i * -360) / steps));\n }\n coordinates.push(coordinates[0]);\n\n return {\n type: \"Feature\",\n geometry: { type: \"Polygon\", coordinates: [coordinates] },\n properties: {},\n };\n}\n","import { TerraDrawAdapterStyling } from \"../common\";\n\nexport const getDefaultStyling = (): TerraDrawAdapterStyling => {\n return {\n polygonFillColor: \"#3f97e0\",\n polygonOutlineColor: \"#3f97e0\",\n polygonOutlineWidth: 4,\n polygonFillOpacity: 0.3,\n pointColor: \"#3f97e0\",\n pointOutlineColor: \"#3f97e0\",\n pointWidth: 6,\n lineStringColor: \"#3f97e0\",\n lineStringWidth: 4,\n selectedColor: \"#26a9c8\",\n };\n};\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n} from \"../common\";\nimport { circle } from \"../geometry/create-circle\";\nimport { haversineDistanceKilometers } from \"../geometry/haversine-distance\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawCircleMode implements TerraDrawMode {\n mode = \"circle\";\n\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n private center: [number, number];\n private clickCount: number = 0;\n private currentCircleId: string;\n\n constructor(options?: { styling?: Partial<TerraDrawAdapterStyling> }) {\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (this.clickCount === 0) {\n this.center = [event.lng, event.lat];\n const startingCircle = circle({\n center: this.center,\n radiusKilometers: 0.00001,\n });\n\n this.currentCircleId = this.store.create(startingCircle.geometry, {\n mode: this.mode,\n });\n\n this.clickCount++;\n } else {\n // Finish drawing\n this.center = undefined;\n this.currentCircleId = undefined;\n this.clickCount = 0;\n }\n }\n onMouseMove(event: TerraDrawMouseEvent) {\n if (this.clickCount === 1) {\n const distanceKm = haversineDistanceKilometers(this.center, [\n event.lng,\n event.lat,\n ]);\n\n const updatedCircle = circle({\n center: this.center,\n radiusKilometers: distanceKm,\n });\n\n this.store.updateGeometry(this.currentCircleId, updatedCircle.geometry);\n }\n }\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n cleanUp() {\n try {\n this.store.delete(this.currentCircleId);\n } catch (error) {}\n this.center = undefined;\n this.currentCircleId = undefined;\n this.clickCount = 0;\n }\n}\n","export function haversineDistanceKilometers(\n pointOne: [lng: number, lat: number],\n pointTwo: [lng: number, lat: number]\n) {\n const toRadians = (latOrLng: number) => (latOrLng * Math.PI) / 180;\n\n const phiOne = toRadians(pointOne[1]);\n const lambdaOne = toRadians(pointOne[0]);\n const phiTwo = toRadians(pointTwo[1]);\n const lambdaTwo = toRadians(pointTwo[0]);\n const deltaPhi = phiTwo - phiOne;\n const deltalambda = lambdaTwo - lambdaOne;\n\n const a =\n Math.sin(deltaPhi / 2) * Math.sin(deltaPhi / 2) +\n Math.cos(phiOne) *\n Math.cos(phiTwo) *\n Math.sin(deltalambda / 2) *\n Math.sin(deltalambda / 2);\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\n const radius = 6371e3;\n const distance = radius * c;\n\n return distance / 1000;\n}\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { Polygon } from \"geojson\";\n\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawFreehandMode implements TerraDrawMode {\n mode = \"freehand\";\n\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n\n private startingClick = false;\n private currentId: string;\n\n private skip: number = 0;\n private everyNthMouseEvent: number;\n\n constructor(options?: {\n styling?: Partial<TerraDrawAdapterStyling>;\n everyNthMouseEvent?: number;\n }) {\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n this.everyNthMouseEvent = (options && options.everyNthMouseEvent) || 10;\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n }\n\n onMouseMove(event: TerraDrawMouseEvent) {\n if (!this.currentId || this.startingClick === false) {\n return;\n }\n\n if (this.skip > this.everyNthMouseEvent) {\n this.skip = 0;\n const currentLineGeometry = this.store.getGeometryCopy<Polygon>(\n this.currentId\n );\n\n currentLineGeometry.coordinates[0].pop();\n\n this.store.updateGeometry(this.currentId, {\n type: \"Polygon\",\n coordinates: [\n [\n ...currentLineGeometry.coordinates[0],\n [event.lng, event.lat],\n currentLineGeometry.coordinates[0][0],\n ],\n ],\n });\n }\n\n this.skip++;\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (this.startingClick === false) {\n this.currentId = this.store.create(\n {\n type: \"Polygon\",\n coordinates: [\n [\n [event.lng, event.lat],\n [event.lng, event.lat],\n [event.lng, event.lat],\n [event.lng, event.lat],\n ],\n ],\n },\n { mode: this.mode }\n );\n\n this.startingClick = true;\n return;\n }\n\n this.startingClick = false;\n this.currentId = undefined;\n }\n\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n\n cleanUp() {\n try {\n this.store.delete(this.currentId);\n } catch (error) {}\n this.currentId = undefined;\n this.startingClick = false;\n }\n}\n","import { Feature, LineString, Polygon } from \"geojson\";\n// import * as rbush from \"rbush\";\n\ntype SelfIntersectsOptions = {\n epsilon: number;\n // reportVertexOnVertex: boolean;\n // reportVertexOnEdge: boolean;\n};\n\nexport function selfIntersects(\n feature: Feature<Polygon> | Feature<LineString>\n): boolean {\n let options: SelfIntersectsOptions = {\n epsilon: 0,\n // reportVertexOnVertex: false,\n // reportVertexOnEdge: false,\n };\n\n let coord: number[][][];\n\n if (feature.geometry.type === \"Polygon\") {\n coord = feature.geometry.coordinates;\n } else if (feature.geometry.type === \"LineString\") {\n coord = [feature.geometry.coordinates];\n }\n\n var output: number[][] = [];\n var seen: { [key: string]: boolean } = {};\n\n for (let ring0 = 0; ring0 < coord.length; ring0++) {\n for (let edge0 = 0; edge0 < coord[ring0].length - 1; edge0++) {\n for (let ring1 = 0; ring1 < coord.length; ring1++) {\n for (let edge1 = 0; edge1 < coord[ring1].length - 1; edge1++) {\n // TODO: speedup possible if only interested in unique: start last two loops at ring0 and edge0+1\n ifInteresctionAddToOutput(ring0, edge0, ring1, edge1);\n }\n }\n }\n }\n\n return output.length > 0;\n\n // true if frac is (almost) 1.0 or 0.0\n // function isBoundaryCase(frac: number) {\n // const e2 = options.epsilon * options.epsilon;\n // return e2 >= (frac - 1) * (frac - 1) || e2 >= frac * frac;\n // }\n\n function isOutside(frac: number) {\n return frac < 0 - options.epsilon || frac > 1 + options.epsilon;\n }\n // Function to check if two edges intersect and add the intersection to the output\n function ifInteresctionAddToOutput(\n ring0: number,\n edge0: number,\n ring1: number,\n edge1: number\n ) {\n const start0 = coord[ring0][edge0] as [number, number];\n const end0 = coord[ring0][edge0 + 1] as [number, number];\n const start1 = coord[ring1][edge1] as [number, number];\n const end1 = coord[ring1][edge1 + 1] as [number, number];\n\n const intersection = intersect(start0, end0, start1, end1);\n\n if (intersection === null) {\n return; // discard parallels and coincidence\n }\n\n let frac0;\n let frac1;\n\n if (end0[0] !== start0[0]) {\n frac0 = (intersection[0] - start0[0]) / (end0[0] - start0[0]);\n } else {\n frac0 = (intersection[1] - start0[1]) / (end0[1] - start0[1]);\n }\n if (end1[0] !== start1[0]) {\n frac1 = (intersection[0] - start1[0]) / (end1[0] - start1[0]);\n } else {\n frac1 = (intersection[1] - start1[1]) / (end1[1] - start1[1]);\n }\n\n // There are roughly three cases we need to deal with.\n // 1. If at least one of the fracs lies outside [0,1], there is no intersection.\n if (isOutside(frac0) || isOutside(frac1)) {\n return; // require segment intersection\n }\n\n // 2. If both are either exactly 0 or exactly 1, this is not an intersection but just\n // two edge segments sharing a common vertex.\n // if (isBoundaryCase(frac0) && isBoundaryCase(frac1)) {\n // if (!options.reportVertexOnVertex) {\n // return;\n // }\n // }\n\n // // 3. If only one of the fractions is exactly 0 or 1, this is\n // // a vertex-on-edge situation.\n // if (isBoundaryCase(frac0) || isBoundaryCase(frac1)) {\n // if (!options.reportVertexOnEdge) {\n // return;\n // }\n // }\n\n var key = intersection.toString();\n var unique = !seen[key];\n if (unique) {\n seen[key] = true;\n }\n\n output.push(intersection);\n }\n}\n\nfunction equalArrays(array1: [number, number], array2: [number, number]) {\n return array1[0] === array2[0] && array1[1] === array2[1];\n}\n\n// Function to compute where two lines (not segments) intersect. From https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection\nfunction intersect(\n start0: [number, number],\n end0: [number, number],\n start1: [number, number],\n end1: [number, number]\n) {\n if (\n equalArrays(start0, start1) ||\n equalArrays(start0, end1) ||\n equalArrays(end0, start1) ||\n equalArrays(end1, start1)\n ) {\n return null;\n }\n\n let x0 = start0[0],\n y0 = start0[1],\n x1 = end0[0],\n y1 = end0[1],\n x2 = start1[0],\n y2 = start1[1],\n x3 = end1[0],\n y3 = end1[1];\n\n const denom = (x0 - x1) * (y2 - y3) - (y0 - y1) * (x2 - x3);\n if (denom === 0) {\n return null;\n }\n\n const x4 =\n ((x0 * y1 - y0 * x1) * (x2 - x3) - (x0 - x1) * (x2 * y3 - y2 * x3)) / denom;\n\n const y4 =\n ((x0 * y1 - y0 * x1) * (y2 - y3) - (y0 - y1) * (x2 * y3 - y2 * x3)) / denom;\n\n return [x4, y4];\n}\n","export const getPixelDistance = (\n pointOne: { x: number; y: number },\n pointTwo: { x: number; y: number }\n) => {\n const { x: x1, y: y1 } = pointOne;\n const { x: x2, y: y2 } = pointTwo;\n const y = x2 - x1;\n const x = y2 - y1;\n return Math.sqrt(x * x + y * y);\n};\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { LineString } from \"geojson\";\nimport { selfIntersects } from \"../geometry/self-intersects\";\nimport { getPixelDistance } from \"../geometry/get-pixel-distance\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawLineStringMode implements TerraDrawMode {\n public mode = \"linestring\";\n\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n private pointerDistance: number;\n\n private currentCoordinate = 0;\n private currentId: string;\n private allowSelfIntersections;\n\n constructor(options?: {\n allowSelfIntersections?: boolean;\n styling?: Partial<TerraDrawAdapterStyling>;\n pointerDistance?: number;\n }) {\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n\n this.pointerDistance = (options && options.pointerDistance) || 40;\n\n this.allowSelfIntersections =\n options && options.allowSelfIntersections !== undefined\n ? options.allowSelfIntersections\n : true;\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n }\n\n onMouseMove(event: TerraDrawMouseEvent) {\n if (!this.currentId || this.currentCoordinate === 0) {\n return;\n }\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n // Remove the 'live' point that changes on mouse move\n currentLineGeometry.coordinates.pop();\n\n // Update the 'live' point\n this.store.updateGeometry(this.currentId, {\n type: \"LineString\",\n coordinates: [...currentLineGeometry.coordinates, [event.lng, event.lat]],\n });\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (this.currentCoordinate === 0) {\n this.currentId = this.store.create(\n {\n type: \"LineString\",\n coordinates: [\n [event.lng, event.lat],\n [event.lng, event.lat], // This is the 'live' point that changes on mouse move\n ],\n },\n { mode: this.mode }\n );\n this.currentCoordinate++;\n } else if (this.currentCoordinate === 1) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n this.store.updateGeometry(this.currentId, {\n type: \"LineString\",\n coordinates: [\n currentLineGeometry.coordinates[0],\n [event.lng, event.lat],\n [event.lng, event.lat],\n ],\n });\n\n this.currentCoordinate++;\n } else {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n const [previousLng, previousLat] = currentLineGeometry.coordinates[\n currentLineGeometry.coordinates.length - 2\n ];\n const { x, y } = this.project(previousLng, previousLat);\n const distance = getPixelDistance(\n { x, y },\n { x: event.containerX, y: event.containerY }\n );\n\n const isClosingClick = distance < this.pointerDistance;\n\n if (isClosingClick) {\n // Finish off the drawing\n currentLineGeometry.coordinates.pop();\n this.store.updateGeometry(this.currentId, {\n type: \"LineString\",\n coordinates: [...currentLineGeometry.coordinates],\n });\n\n this.currentCoordinate = 0;\n this.currentId = undefined;\n } else {\n // If not close to the final point, keep adding points\n const newLineString = {\n type: \"LineString\",\n coordinates: [\n ...currentLineGeometry.coordinates,\n [event.lng, event.lat],\n ],\n } as LineString;\n\n if (!this.allowSelfIntersections) {\n const hasSelfIntersections = selfIntersects({\n type: \"Feature\",\n geometry: newLineString,\n properties: {},\n });\n\n if (hasSelfIntersections) {\n return;\n }\n }\n\n this.store.updateGeometry(this.currentId, newLineString);\n this.currentCoordinate++;\n }\n }\n }\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n cleanUp() {\n try {\n this.store.delete(this.currentId);\n } catch (error) {}\n\n this.currentId = undefined;\n this.currentCoordinate = 0;\n }\n}\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawPointMode implements TerraDrawMode {\n mode = \"point\";\n\n private store: GeoJSONStore;\n\n constructor(options?: { styling?: Partial<TerraDrawAdapterStyling> }) {\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (!this.store) {\n throw new Error(\"Mode must be registered first\");\n }\n\n this.store.create(\n {\n type: \"Point\",\n coordinates: [event.lng, event.lat],\n },\n { mode: this.mode }\n );\n }\n onMouseMove() {}\n onKeyPress() {}\n cleanUp() {}\n}\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { Polygon } from \"geojson\";\nimport { getPixelDistance } from \"../geometry/get-pixel-distance\";\nimport { selfIntersects } from \"../geometry/self-intersects\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawPolygonMode implements TerraDrawMode {\n mode = \"polygon\";\n\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n\n private currentCoordinate = 0;\n private currentId: string;\n private allowSelfIntersections: boolean;\n private pointerDistance: number;\n\n constructor(options?: {\n allowSelfIntersections?: boolean;\n styling?: Partial<TerraDrawAdapterStyling>;\n pointerDistance?: number;\n }) {\n this.pointerDistance = (options && options.pointerDistance) || 40;\n\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n\n this.allowSelfIntersections =\n options && options.allowSelfIntersections !== undefined\n ? options.allowSelfIntersections\n : true;\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n }\n\n onMouseMove(event: TerraDrawMouseEvent) {\n if (!this.currentId || this.currentCoordinate === 0) {\n return;\n }\n\n const currentLineCoordinates = this.store.getGeometryCopy<Polygon>(\n this.currentId\n ).coordinates[0];\n\n let updatedCoordinates;\n\n if (this.currentCoordinate === 1) {\n updatedCoordinates = [\n currentLineCoordinates[0],\n [event.lng, event.lat],\n currentLineCoordinates[0],\n currentLineCoordinates[0],\n ];\n } else if (this.currentCoordinate === 2) {\n updatedCoordinates = [\n currentLineCoordinates[0],\n currentLineCoordinates[1],\n [event.lng, event.lat],\n currentLineCoordinates[0],\n ];\n } else {\n updatedCoordinates = [\n ...currentLineCoordinates.slice(0, -2),\n [event.lng, event.lat],\n currentLineCoordinates[0],\n ];\n }\n\n this.store.updateGeometry(this.currentId, {\n type: \"Polygon\",\n coordinates: [updatedCoordinates],\n });\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (this.currentCoordinate === 0) {\n this.currentId = this.store.create(\n {\n type: \"Polygon\",\n coordinates: [\n [\n [event.lng, event.lat],\n [event.lng, event.lat],\n [event.lng, event.lat],\n [event.lng, event.lat],\n ],\n ],\n },\n { mode: this.mode }\n );\n\n this.currentCoordinate++;\n } else if (this.currentCoordinate === 1) {\n const currentPolygonGeometry = this.store.getGeometryCopy<Polygon>(\n this.currentId\n );\n\n this.store.updateGeometry(this.currentId, {\n type: \"Polygon\",\n coordinates: [\n [\n currentPolygonGeometry.coordinates[0][0],\n [event.lng, event.lat],\n [event.lng, event.lat],\n currentPolygonGeometry.coordinates[0][0],\n ],\n ],\n });\n\n this.currentCoordinate++;\n } else if (this.currentCoordinate === 2) {\n const currentPolygonGeometry = this.store.getGeometryCopy<Polygon>(\n this.currentId\n );\n\n this.store.updateGeometry(this.currentId, {\n type: \"Polygon\",\n coordinates: [\n [\n currentPolygonGeometry.coordinates[0][0],\n currentPolygonGeometry.coordinates[0][1],\n [event.lng, event.lat],\n [event.lng, event.lat],\n currentPolygonGeometry.coordinates[0][0],\n ],\n ],\n });\n this.currentCoordinate++;\n } else {\n const currentPolygonGeometry = this.store.getGeometryCopy<Polygon>(\n this.currentId\n );\n\n const [firstLng, firstLat] = currentPolygonGeometry.coordinates[0][0];\n const { x, y } = this.project(firstLng, firstLat);\n const distance = getPixelDistance(\n { x, y },\n { x: event.containerX, y: event.containerY }\n );\n\n console.log(distance, this.pointerDistance);\n\n const isClosingClick = distance < this.pointerDistance;\n\n if (isClosingClick) {\n this.currentCoordinate = 0;\n this.currentId = undefined;\n } else {\n const newPolygon = {\n type: \"Polygon\",\n coordinates: [\n [\n ...currentPolygonGeometry.coordinates[0].slice(0, -1),\n [event.lng, event.lat],\n currentPolygonGeometry.coordinates[0][0],\n ],\n ],\n } as Polygon;\n\n if (this.currentCoordinate > 2 && !this.allowSelfIntersections) {\n const hasSelfIntersections = selfIntersects({\n type: \"Feature\",\n geometry: newPolygon,\n properties: {},\n });\n\n if (hasSelfIntersections) {\n this.store.updateGeometry(this.currentId, currentPolygonGeometry);\n return;\n }\n }\n\n console.log(newPolygon);\n\n // If not close to the final point, keep adding points\n this.store.updateGeometry(this.currentId, newPolygon);\n this.currentCoordinate++;\n }\n }\n }\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n\n cleanUp() {\n try {\n this.store.delete(this.currentId);\n } catch (error) {}\n this.currentId = undefined;\n this.currentCoordinate = 0;\n }\n}\n","// Based on which-polygon\n// https://github.com/mapbox/which-polygon/blob/2eb5b8a427d018ebd964c05acd3b9166c4558b2c/index.js#L81\nexport function pointInPolygon(\n point: [number, number],\n rings: [number, number][][]\n) {\n let inside = false;\n for (let i = 0, len = rings.length; i < len; i++) {\n const ring = rings[i];\n for (let j = 0, len2 = ring.length, k = len2 - 1; j < len2; k = j++) {\n if (rayIntersect(point, ring[j], ring[k])) {\n inside = !inside;\n }\n }\n }\n return inside;\n}\n\nfunction rayIntersect(\n p: [number, number],\n p1: [number, number],\n p2: [number, number]\n) {\n return (\n p1[1] > p[1] !== p2[1] > p[1] &&\n p[0] < ((p2[0] - p1[0]) * (p[1] - p1[1])) / (p2[1] - p1[1]) + p1[0]\n );\n}\n","export const getPixelDistanceToLine = (\n point: { x: number; y: number },\n linePointOne: { x: number; y: number },\n linePointTwo: { x: number; y: number }\n) => {\n const square = (x: number) => {\n return x * x;\n };\n const dist2 = (v: { x: number; y: number }, w: { x: number; y: number }) => {\n return square(v.x - w.x) + square(v.y - w.y);\n };\n const distToSegmentSquared = (\n p: { x: number; y: number },\n v: { x: number; y: number },\n w: { x: number; y: number }\n ) => {\n const l2 = dist2(v, w);\n\n if (l2 === 0) {\n return dist2(p, v);\n }\n\n let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;\n t = Math.max(0, Math.min(1, t));\n\n return dist2(p, { x: v.x + t * (w.x - v.x), y: v.y + t * (w.y - v.y) });\n };\n\n return Math.sqrt(distToSegmentSquared(point, linePointOne, linePointTwo));\n};\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawKeyboardEvent,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { pointInPolygon } from \"../geometry/point-in-polygon\";\nimport { getPixelDistance } from \"../geometry/get-pixel-distance\";\nimport { getPixelDistanceToLine } from \"../geometry/get-pixel-distance-to-line\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawSelectMode implements TerraDrawMode {\n mode = \"select\";\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n private selected: string[] = [];\n private pointerDistance: number;\n\n constructor(options?: {\n styling?: Partial<TerraDrawAdapterStyling>;\n pointerDistance?: number;\n }) {\n this.pointerDistance = (options && options.pointerDistance) || 40;\n\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n }\n\n styling: TerraDrawAdapterStyling;\n\n onClick(event: TerraDrawMouseEvent) {\n const features = this.store.copyAll();\n\n let clickedFeatureId: string;\n let clickedFeatureDistance = Infinity;\n\n for (let i = 0; i < features.length; i++) {\n const feature = features[i];\n const geometry = feature.geometry;\n\n if (geometry.type === \"Point\") {\n const { x, y } = this.project(\n geometry.coordinates[0],\n geometry.coordinates[1]\n );\n const distance = getPixelDistance(\n { x, y },\n { x: event.containerX, y: event.containerY }\n );\n if (\n distance < this.pointerDistance &&\n distance < clickedFeatureDistance\n ) {\n clickedFeatureDistance = distance;\n clickedFeatureId = feature.id as string;\n }\n } else if (geometry.type === \"LineString\") {\n for (let i = 0; i < geometry.coordinates.length - 1; i++) {\n const coord = geometry.coordinates[i];\n const nextCoord = geometry.coordinates[i + 1];\n const distanceToLine = getPixelDistanceToLine(\n { x: event.containerX, y: event.containerY },\n this.project(coord[0], coord[1]),\n this.project(nextCoord[0], nextCoord[1])\n );\n\n if (\n distanceToLine < this.pointerDistance &&\n distanceToLine < clickedFeatureDistance\n ) {\n clickedFeatureDistance = distanceToLine;\n clickedFeatureId = feature.id as string;\n }\n }\n } else if (geometry.type === \"Polygon\") {\n const clickInsidePolygon = pointInPolygon(\n [event.lng, event.lat],\n geometry.coordinates as [number, number][][]\n );\n\n if (clickInsidePolygon) {\n clickedFeatureDistance = 0;\n clickedFeatureId = feature.id as string;\n }\n }\n }\n\n if (clickedFeatureId) {\n // TODO: Handle multi select?\n this.selected = [clickedFeatureId];\n this.onSelect(clickedFeatureId);\n } else if (this.selected.length) {\n this.selected = [];\n this.onDeselect();\n }\n }\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Delete\") {\n if (!this.selected.length) {\n return;\n }\n // Delete all selected features\n // from the store and clear selected\n this.selected.forEach((id) => {\n this.store.delete(id);\n });\n this.selected = [];\n\n // We are technically deselecting\n // because the selected feature\n // no longer exists\n this.onDeselect();\n } else if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n cleanUp() {\n if (this.selected.length) {\n this.onDeselect();\n }\n\n this.selected = [];\n }\n onMouseMove() {}\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n this.onSelect = config.onSelect;\n this.onDeselect = config.onDeselect;\n }\n onDeselect() {}\n onSelect(selectedId: string) {}\n}\n","import { TerraDrawAdapterStyling, TerraDrawMode } from \"../common\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawStaticMode implements TerraDrawMode {\n mode = \"static\";\n styling: TerraDrawAdapterStyling = getDefaultStyling();\n register() {}\n onKeyPress() {}\n onClick() {}\n onMouseMove() {}\n cleanUp() {}\n}\n","import { Feature, Point, Polygon, LineString } from \"geojson\";\nimport { uuid4 } from \"../util/id\";\n\ntype JSON = string | number | boolean | null | JSONArray | JSONObject;\n\ninterface JSONObject {\n [member: string]: JSON;\n}\ninterface JSONArray extends Array<JSON> {}\n\nexport type GeoJSONStoreGeometries = Polygon | LineString | Point;\n\nexport type GeoJSONStoreFeatures = Feature<GeoJSONStoreGeometries>;\n\nexport type StoreChangeEvents = \"delete\" | \"create\" | \"update\";\n\nexport type StoreChangeHandler = (\n id: string,\n change: StoreChangeEvents\n) => void;\n\nexport class GeoJSONStore {\n constructor(config?: { data: GeoJSONStoreFeatures[] }) {\n this.store = {};\n\n if (config && config.data) {\n config.data.forEach((feature) => {\n this.featureValidation(feature);\n this.store[feature.id] = feature;\n });\n }\n }\n\n private featureValidation(feature: any) {\n if (!feature || !feature.id) {\n throw new Error(\"Feature has no id\");\n } else if (typeof feature.id !== \"string\" || feature.id.length !== 36) {\n throw new Error(`Feature must have uuid4 ID ${feature.id}`);\n } else if (!feature.geometry) {\n throw new Error(\"Feature has no geometry\");\n } else if (!feature.properties) {\n throw new Error(\"Feature has no properties\");\n } else if (\n ![\"Polygon\", \"LineString\", \"Point\"].includes(feature.geometry.type)\n ) {\n throw new Error(\"Feature is not Point, LineString or Polygon\");\n } else if (!Array.isArray(feature.geometry.coordinates)) {\n throw new Error(\"Feature coordinates is not an array\");\n }\n }\n\n private store: {\n [key: string]: GeoJSONStoreFeatures;\n };\n\n private _onChange: StoreChangeHandler;\n\n private getId(): string {\n return uuid4();\n }\n\n registerOnChange(onChange: StoreChangeHandler) {\n this._onChange = (id, change) => {\n onChange(id, change);\n };\n }\n\n updateGeometry(id: string, geometry: GeoJSONStoreGeometries): string {\n const feature = this.store[id];\n\n if (!feature) {\n throw new Error(\"No feature with this id, can not update geometry\");\n }\n\n feature.geometry = JSON.parse(JSON.stringify(geometry));\n\n if (this._onChange) {\n this._onChange(id, \"update\");\n }\n\n return id;\n }\n\n getGeometryCopy<T>(id: string): T {\n const feature = this.store[id];\n if (!feature) {\n throw new Error(\"No feature with this id, can not get geometry copy\");\n }\n return JSON.parse(JSON.stringify(feature.geometry));\n }\n\n create(geometry: GeoJSONStoreGeometries, properties: JSON = {}): string {\n const id = this.getId();\n const feature = {\n id,\n type: \"Feature\",\n geometry,\n properties,\n } as GeoJSONStoreFeatures;\n\n this.store[id] = feature;\n\n if (this._onChange) {\n this._onChange(id, \"create\");\n }\n\n return id;\n }\n\n delete(id: string): void {\n if (this.store[id]) {\n delete this.store[id];\n if (this._onChange) {\n this._onChange(id, \"delete\");\n }\n } else {\n throw new Error(\"No feature with this id, can not delete\");\n }\n }\n\n copyAll(): GeoJSONStoreFeatures[] {\n return JSON.parse(\n JSON.stringify(Object.keys(this.store).map((id) => this.store[id]))\n );\n }\n}\n","export const uuid4 = function (): string {\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, function (c) {\n var r = (Math.random() * 16) | 0,\n v = c == \"x\" ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n","import { FeatureCollection, LineString, Point, Polygon } from \"geojson\";\nimport { flattenDiagnosticMessageText } from \"typescript\";\nimport { TerraDrawGoogleMapsAdapter } from \"./adapters/google-maps.adapter\";\nimport { TerraDrawLeafletAdapter } from \"./adapters/leaflet.adapter\";\nimport { TerraDrawMapboxGLAdapter } from \"./adapters/mapbox-gl.adapter\";\nimport {\n TerraDrawMode,\n TerraDrawAdapter,\n TerraDrawAdapterStyling,\n} from \"./common\";\nimport { TerraDrawCircleMode } from \"./modes/circle.mode\";\nimport { TerraDrawFreehandMode } from \"./modes/freehand.mode\";\nimport { TerraDrawLineStringMode } from \"./modes/line-string.mode\";\nimport { TerraDrawPointMode } from \"./modes/point.mode\";\nimport { TerraDrawPolygonMode } from \"./modes/polygon.mode\";\nimport { TerraDrawSelectMode } from \"./modes/select.mode\";\nimport { TerraDrawStaticMode } from \"./modes/static.mode\";\nimport {\n GeoJSONStore,\n GeoJSONStoreFeatures,\n GeoJSONStoreGeometries,\n StoreChangeHandler,\n} from \"./store/store\";\n\ntype ChangeListener = (id: string, type: string) => void;\ntype SelectListener = (id: string) => void;\ntype DeselectListener = () => void;\n\ninterface TerraDrawEventListeners {\n change: ChangeListener;\n select: SelectListener;\n deselect: DeselectListener;\n}\n\ntype TerraDrawEvents = keyof TerraDrawEventListeners;\n\nclass TerraDraw {\n private _modes: { [mode: string]: TerraDrawMode };\n private _mode: TerraDrawMode;\n private _adapter: TerraDrawAdapter;\n private _enabled = false;\n private _store: GeoJSONStore;\n private _eventListeners: {\n change: ChangeListener[];\n select: SelectListener[];\n deselect: DeselectListener[];\n };\n constructor(options: {\n adapter: TerraDrawAdapter;\n modes: { [mode: string]: TerraDrawMode };\n data?: GeoJSONStoreFeatures[];\n }) {\n this._adapter = options.adapter;\n this._mode = new TerraDrawStaticMode();\n this._modes = { ...options.modes, static: this._mode };\n this._eventListeners = { change: [], select: [], deselect: [] };\n\n if (options.data) {\n this._store = new GeoJSONStore({ data: options.data });\n\n // Remove all non mode features\n const initialRender = this._store.copyAll().filter((feature) => {\n if (!Object.keys(this._modes).includes(feature.properties.mode)) {\n this._store.delete(feature.id as string);\n return false;\n }\n return true;\n });\n\n this._adapter.render(initialRender, this.getModeStyles());\n } else {\n this._store = new GeoJSONStore();\n }\n\n // Register stores and callbacks\n Object.keys(this._modes).forEach((modeId) => {\n const onChange: StoreChangeHandler = (id, event) => {\n this._eventListeners.change.forEach((listener) => {\n listener(id, event);\n });\n this._adapter.render(this._store.copyAll(), this.getModeStyles());\n };\n\n const onSelect = (selectedId: string) => {\n this._eventListeners.select.forEach((listener) => {\n listener(selectedId);\n });\n\n const features = this._store.copyAll();\n features.forEach((feature) => {\n if (feature.id === selectedId) {\n feature.properties.selected = true;\n }\n });\n this._adapter.render(features, this.getModeStyles());\n };\n\n const onDeselect = () => {\n this._eventListeners.deselect.forEach((listener) => {\n listener();\n });\n\n const features = this._store.copyAll();\n this._adapter.render(features, this.getModeStyles());\n };\n\n this._modes[modeId].register({\n store: this._store,\n project: this._adapter.project,\n onChange: onChange,\n onSelect: onSelect,\n onDeselect: onDeselect,\n });\n });\n }\n\n private getModeStyles() {\n const modeStyles: { [key: string]: TerraDrawAdapterStyling } = {};\n Object.keys(this._modes).forEach((mode) => {\n modeStyles[mode] = this._modes[mode].styling;\n });\n return modeStyles;\n }\n\n getSnapshot() {\n return this._store.copyAll();\n }\n\n get enabled() {\n return this._enabled;\n }\n\n changeMode(mode: string) {\n if (this._modes[mode]) {\n // Before we swap modes we want to\n // clean up any state that has been left behind,\n // for example current drawing geometries\n // and mode state\n this._mode.cleanUp();\n\n // Swap the mode to the new mode\n this._mode = this._modes[mode];\n } else {\n // If the mode doesn't exist, we throw an error\n throw new Error(\"No mode with this name present\");\n }\n }\n\n start() {\n this._enabled = true;\n this._adapter.register({\n onClick: (event) => {\n this._mode.onClick(event);\n },\n onMouseMove: (event) => {\n this._mode.onMouseMove(event);\n },\n onKeyPress: (event) => {\n this._mode.onKeyPress(event);\n },\n });\n }\n\n stop() {\n this._enabled = false;\n this._adapter.unregister();\n }\n\n on<T extends TerraDrawEvents>(\n event: T,\n callback: TerraDrawEventListeners[T]\n ) {\n const listeners = this._eventListeners[\n event\n ] as TerraDrawEventListeners[T][];\n if (!listeners.includes(callback)) {\n listeners.push(callback);\n }\n }\n\n off<T extends TerraDrawEvents>(\n event: TerraDrawEvents,\n callback: TerraDrawEventListeners[T]\n ) {\n const listeners = this._eventListeners[\n event\n ] as TerraDrawEventListeners[T][];\n if (listeners.includes(callback)) {\n listeners.splice(listeners.indexOf(callback), 1);\n }\n }\n}\n\nexport {\n TerraDraw,\n TerraDrawSelectMode,\n TerraDrawPointMode,\n TerraDrawLineStringMode,\n TerraDrawPolygonMode,\n TerraDrawCircleMode,\n TerraDrawFreehandMode,\n TerraDrawGoogleMapsAdapter,\n TerraDrawMapboxGLAdapter,\n TerraDrawLeafletAdapter,\n};\n"],"names":["limitPrecision","num","decimalLimit","decimals","Math","pow","round","TerraDrawGoogleMapsAdapter","config","_this","this","_coordinatePrecision","_lib","_map","_onMouseMoveListener","_onMouseMoveCallback","_onClickListener","_onClickCallback","_onKeyUpListener","_layers","project","lib","map","coordinatePrecision","lng","lat","bounds","getBounds","northWest","LatLng","getNorthEast","getSouthWest","getProjection","projectedNorthWest","projection","fromLatLngToPoint","scale","getZoom","x","floor","projected","y","_proto","prototype","circlePath","cx","cy","r","register","callbacks","_this2","event","onClick","latLng","containerX","domEvent","clientX","getDiv","offsetLeft","containerY","clientY","offsetTop","addListener","onMouseMove","onKeyPress","key","addEventListener","unregister","undefined","remove","removeEventListener","render","features","styling","_this3","data","forEach","layer","console","log","addGeoJson","type","setStyle","feature","mode","getProperty","getGeometry","getType","selected","icon","path","pointWidth","fillColor","selectedColor","pointColor","fillOpacity","strokeWeight","rotation","strokeColor","lineStringColor","lineStringWidth","polygonOutlineColor","polygonOutlineWidth","polygonFillOpacity","polygonFillColor","TerraDrawLeafletAdapter","_onKeyPressListener","_layer","_this$_map$latLngToCo","latLngToContainerPoint","originalEvent","preventDefault","latlng","getContainer","on","off","removeLayer","geoJSON","pointToLayer","modeStyle","properties","circleMarker","radius","color","pointOutlineColor","weight","opacity","style","geometry","addTo","TerraDrawMapboxGLAdapter","_rendered","_this$_map$project","_addGeoJSONSource","id","addSource","_addFillLayer","addLayer","source","filter","paint","_addFillOutlineLayer","_addLineLayer","_addPointLayer","_addLayer","featureType","_addGeoJSONLayer","toLowerCase","_setGeoJSONLayerData","getSource","setData","lngLat","getCanvas","getFeatureOfType","f","createUpdateGeoJSONLayers","method","Object","keys","styles","modeFeatures","points","selectedStyle","lines","polygons","degrees","PI","radiansToDegrees","radians","circle","options","origin","distance","bearing","longitude1","latitude1","bearingRad","latitude2","center","radiusKilometers","steps","coordinates","i","push","degreesToRadians","earthRadius","lengthToRadians","asin","sin","cos","atan2","TerraDrawCircleMode","store","clickCount","currentCircleId","getDefaultStyling","registerOnChange","onChange","startingCircle","create","distanceKm","pointTwo","phiOne","toRadians","latOrLng","pointOne","lambdaOne","deltaPhi","phiTwo","a","deltalambda","sqrt","updatedCircle","updateGeometry","cleanUp","error","TerraDrawFreehandMode","startingClick","currentId","skip","everyNthMouseEvent","currentLineGeometry","getGeometryCopy","pop","concat","selfIntersects","coord","ring0","length","edge0","ring1","edge1","ifInteresctionAddToOutput","output","isOutside","frac","frac1","start1","end1","start0","end0","equalArrays","x0","y0","x1","y1","x2","y2","x3","y3","denom","intersect","intersection","toString","array1","array2","getPixelDistance","TerraDrawLineStringMode","pointerDistance","currentCoordinate","allowSelfIntersections","_currentLineGeometry$","_this$project","previousLat","newLineString","TerraDrawPointMode","_extends","Error","TerraDrawPolygonMode","updatedCoordinates","currentLineCoordinates","slice","currentPolygonGeometry","_currentPolygonGeometry","_currentPolygonGeomet","newPolygon","pointInPolygon","point","rings","p","p1","p2","inside","len","j","len2","ring","k","linePointOne","linePointTwo","square","dist2","v","w","l2","t","max","min","distToSegmentSquared","TerraDrawSelectMode","clickedFeatureId","copyAll","Infinity","clickedFeatureDistance","nextCoord","distanceToLine","getPixelDistanceToLine","onSelect","onDeselect","selectedId","TerraDrawStaticMode","GeoJSONStore","_onChange","featureValidation","includes","Array","isArray","getId","replace","c","random","change","JSON","parse","stringify","TerraDraw","_modes","_mode","_adapter","_enabled","_store","_eventListeners","adapter","modes","static","select","deselect","initialRender","getModeStyles","modeId","listener","modeStyles","getSnapshot","changeMode","start","stop","callback","listeners","splice","indexOf"],"mappings":"oOAAgBA,SAAAA,EAAeC,EAAaC,YAAAA,IAAAA,EAAe,GACzD,IAAcC,EAAGC,KAAKC,IAAI,GAAIH,GAC9B,OAAWE,KAACE,MAAML,EAAME,GAAYA,ECQzBI,IAAbA,eAAA,WACE,SAAYC,EAAAA,GAIX,IAAAC,EAAAC,KAAAA,KA0BOC,0BACAC,EAAAA,KAAAA,UACAC,EAAAA,KAAAA,UACAC,EAAAA,KAAAA,iCACAC,0BA9BP,EAAAL,KAmCOM,sBAnCP,EAAAN,KAoCOO,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pJ,KAAK4T,QAAQ1P,QAAQ,SAACQ,GAChCiQ,EAAWjQ,GAAQlC,EAAKoR,OAAOlP,GAAMX,UAGxC4Q,KAEDC,YAAA,WACE,YAAYZ,OAAO7B,aAOrB0C,WAAA,SAAWnQ,GACT,IAAI1E,KAAK4T,OAAOlP,GAWd,MAAM,UAAU,kCANhB1E,KAAK6T,MAAMjH,UAGX5M,KAAK6T,MAAQ7T,KAAK4T,OAAOlP,MAO7BoQ,MAAA,WACE,IAAA9Q,EAAAhE,KAAAA,KAAK+T,UAAW,EAChB/T,KAAK8T,SAASxR,SAAS,CACrBI,QAAS,SAACD,GACRuB,EAAK6P,MAAMnR,QAAQD,IAErBY,YAAa,SAACZ,GACZuB,EAAK6P,MAAMxQ,YAAYZ,IAEzBa,WAAY,SAACb,GACXuB,EAAK6P,MAAMvQ,WAAWb,SAK5BsS,KAAA,WACE/U,KAAK+T,UAAW,EAChB/T,KAAK8T,SAASrQ,cAGhB+C,EAAAA,GAAA,SACE/D,EACAuS,GAEA,IAAMC,EAAYjV,KAAKiU,gBACrBxR,GAEGwS,EAAUjC,SAASgC,IACtBC,EAAUpK,KAAKmK,MAInBvO,IAAA,SACEhE,EACAuS,GAEA,IAAMC,EAAYjV,KAAKiU,gBACrBxR,GAEEwS,EAAUjC,SAASgC,IACrBC,EAAUC,OAAOD,EAAUE,QAAQH,GAAW,+BA5DlD,WACE,OAAYjB,KAAAA,uPAlFd"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).terraDraw={})}(this,function(t){function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(t[i]=o[i])}return t},e.apply(this,arguments)}function o(t,e){void 0===e&&(e=9);var o=Math.pow(10,e);return Math.round(t*o)/o}var i=/*#__PURE__*/function(){function t(t){var e=this;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._onClickCallback=void 0,this._onKeyUpListener=void 0,this._layers=void 0,this.project=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,o){var i=e._map.getBounds(),n=new e._lib.LatLng(i.getNorthEast().lat(),i.getSouthWest().lng()),r=e._map.getProjection(),s=r.fromLatLngToPoint(n),l=r.fromLatLngToPoint({lng:t,lat:o}),a=Math.pow(2,e._map.getZoom());return{x:Math.floor((l.x-s.x)*a),y:Math.floor((l.y-s.y)*a)}}}var e=t.prototype;return e.circlePath=function(t,e,o){return"M "+t+" "+e+" m -"+o+", 0 a "+o+","+o+" 0 1,0 "+2*o+",0 a "+o+","+o+" 0 1,0 -"+2*o+",0"},e.register=function(t){var e=this;this._onClickCallback=function(i){t.onClick({lng:o(i.latLng.lng(),e._coordinatePrecision),lat:o(i.latLng.lat(),e._coordinatePrecision),containerX:i.domEvent.clientX-e._map.getDiv().offsetLeft,containerY:i.domEvent.clientY-e._map.getDiv().offsetTop})},this._onClickListener=this._map.addListener("click",this._onClickCallback),this._onMouseMoveCallback=function(i){t.onMouseMove({lng:o(i.latLng.lng(),e._coordinatePrecision),lat:o(i.latLng.lat(),e._coordinatePrecision),containerX:i.domEvent.clientX,containerY:i.domEvent.clientY})},this._onMouseMoveListener=this._map.addListener("mousemove",this._onMouseMoveCallback),this._onKeyUpListener=function(e){t.onKeyPress({key:e.key})},this._map.getDiv().addEventListener("keyup",this._onKeyUpListener)},e.unregister=function(){this._onClickListener&&(this._onClickCallback=void 0,this._onClickListener.remove(),this._onClickListener=void 0),this._onMouseMoveListener&&(this._onMouseMoveCallback=void 0,this._onMouseMoveListener.remove(),this._onMouseMoveListener=void 0),this._onKeyUpListener&&(this._map.getDiv().removeEventListener("keyup",this._onKeyUpListener),this._onKeyUpListener=void 0)},e.render=function(t,e){var o=this;this._layers?this._map.data.forEach(function(t){o._map.data.remove(t)}):(this._map.data.addListener("click",function(t){o._onClickCallback(t)}),this._map.data.addListener("mousemove",function(t){o._onMouseMoveCallback(t)})),console.log(t),this._map.data.addGeoJson({type:"FeatureCollection",features:t}),this._map.data.setStyle(function(t){var i=t.getProperty("mode"),n=t.getGeometry().getType(),r=t.getProperty("selected");switch(n){case"Point":return{icon:{path:o.circlePath(e[i].pointWidth,e[i].pointWidth,e[i].pointWidth),fillColor:r?e[i].selectedColor:e[i].pointColor,fillOpacity:1,strokeWeight:0,rotation:0,scale:1}};case"LineString":return{strokeColor:r?e[i].selectedColor:e[i].lineStringColor,strokeWeight:e[i].lineStringWidth};case"Polygon":return console.log("STYLING",e,i,e[i]),{strokeColor:e[i].polygonOutlineColor,strokeWeight:e[i].polygonOutlineWidth,fillOpacity:e[i].polygonFillOpacity,fillColor:r?e[i].selectedColor:e[i].polygonFillColor}}}),this._layers=!0},t}(),n=/*#__PURE__*/function(){function t(t){var e=this;this._lib=void 0,this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onKeyPressListener=void 0,this._layer=void 0,this.project=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,o){var i=e._map.latLngToContainerPoint({lng:t,lat:o});return{x:i.x,y:i.y}}}var e=t.prototype;return e.register=function(t){var e=this;this._onClickListener=function(i){i.originalEvent.preventDefault(),t.onClick({lng:o(i.latlng.lng,e._coordinatePrecision),lat:o(i.latlng.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-e._map.getContainer().offsetTop})},this._map.on("click",this._onClickListener),this._onMouseMoveListener=function(i){i.originalEvent.preventDefault(),t.onMouseMove({lng:o(i.latlng.lng,e._coordinatePrecision),lat:o(i.latlng.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-e._map.getContainer().offsetTop})},this._map.on("mousemove",this._onMouseMoveListener),this._onKeyPressListener=function(e){e.originalEvent.preventDefault(),t.onKeyPress({key:e.originalEvent.key})},this._map.on("keyup",this._onKeyPressListener)},e.unregister=function(){this._onClickListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0)},e.render=function(t,e){var o=this;this._layer&&this._map.removeLayer(this._layer);var i=this._lib.geoJSON({type:"FeatureCollection",features:t},{pointToLayer:function(t,i){var n=e[t.properties.mode];return o._lib.circleMarker(i,{radius:n.pointWidth,fillColor:t.properties.selected?n.selectedColor:n.pointColor,color:n.pointOutlineColor,weight:1,opacity:1,fillOpacity:.8})},style:function(t){var o=e[t.properties.mode];return"LineString"===t.geometry.type?{color:t.properties.selected?o.selectedColor:o.lineStringColor,weight:o.lineStringWidth}:"Polygon"===t.geometry.type?{fillOpacity:o.polygonFillOpacity,color:t.properties.selected?o.selectedColor:o.polygonFillColor}:void 0}});i.addTo(this._map),this._layer=i},t}(),r=/*#__PURE__*/function(){function t(t){var e=this;this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onKeyPressListener=void 0,this._rendered=!1,this.project=void 0,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=function(t,o){var i=e._map.project({lng:t,lat:o});return{x:i.x,y:i.y}}}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,o){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","selectedStyle"],"fill-opacity":o.polygonFillOpacity}})},e._addFillOutlineLayer=function(t,e,o){return 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":o.polygonOutlineWidth,"line-color":["get","selectedStyle"]}})},e._addLineLayer=function(t,e,o){return 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":o.lineStringWidth,"line-color":["get","selectedStyle"]}})},e._addPointLayer=function(t,e,o){return 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-radius":o.pointWidth,"circle-color":["get","selectedStyle"]}})},e._addLayer=function(t,e,o,i){"Point"===o&&this._addPointLayer(t,e,i),"LineString"===o&&this._addLineLayer(t,e,i),"Polygon"===o&&(this._addFillLayer(t,e,i),this._addFillOutlineLayer(t,e,i))},e._addGeoJSONLayer=function(t,e,o,i){var n=t+"-"+e.toLowerCase();this._addGeoJSONSource(n,o),this._addLayer(n,t,e,i)},e._setGeoJSONLayerData=function(t,e,o){var i=t+"-"+e.toLowerCase();this._map.getSource(i).setData({type:"FeatureCollection",features:o})},e.register=function(t){var e=this;this._onClickListener=function(i){i.preventDefault(),t.onClick({lng:o(i.lngLat.lng,e._coordinatePrecision),lat:o(i.lngLat.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-e._map.getContainer().offsetTop})},this._map.on("click",this._onClickListener),this._onMouseMoveListener=function(i){i.preventDefault(),t.onMouseMove({lng:o(i.lngLat.lng,e._coordinatePrecision),lat:o(i.lngLat.lat,e._coordinatePrecision),containerX:i.originalEvent.clientX-e._map.getContainer().offsetLeft,containerY:i.originalEvent.clientY-e._map.getContainer().offsetTop})},this._map.on("mousemove",this._onMouseMoveListener),this._onKeyPressListener=function(e){e.preventDefault(),t.onKeyPress({key:e.key})},this._map.getCanvas().addEventListener("keyup",this._onKeyPressListener)},e.unregister=function(){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._onKeyPressListener&&this._map.getCanvas().removeEventListener("keypress",this._onKeyPressListener)},e.render=function(t,e){var o=this,i=function(t,e){return e.filter(function(e){return e.geometry.type===t})},n=function(n){Object.keys(e).forEach(function(r){var s=e[r],l=t.filter(function(t){return t.properties.mode===r}),a=i("Point",l);a.forEach(function(t){t.properties.selectedStyle=t.properties.selected?s.selectedColor:s.pointColor});var c=i("LineString",l);c.forEach(function(t){t.properties.selectedStyle=t.properties.selected?s.selectedColor:s.lineStringColor});var h=i("Polygon",l);h.forEach(function(t){t.properties.selectedStyle=t.properties.selected?s.selectedColor:s.polygonFillColor}),"create"===n?(o._addGeoJSONLayer(r,"Point",a,s),o._addGeoJSONLayer(r,"LineString",c,s),o._addGeoJSONLayer(r,"Polygon",h,s)):"update"===n&&(o._setGeoJSONLayerData(r,"Point",a),o._setGeoJSONLayerData(r,"LineString",c),o._setGeoJSONLayerData(r,"Polygon",h))})};this._rendered?n("update"):(n("create"),this._rendered=!0)},t}();function s(t){return t%360*Math.PI/180}function l(t){return t%(2*Math.PI)*180/Math.PI}function a(t){for(var e,o,i,n,r,a,c,h,d=t.center,p=t.radiusKilometers,u=t.steps?t.steps:64,y=[],g=0;g<u;g++)y.push((o=p,i=-360*g/u,n=s((e=d)[0]),r=s(e[1]),a=s(i),c=function(t){return t/6371.0088}(o),h=Math.asin(Math.sin(r)*Math.cos(c)+Math.cos(r)*Math.sin(c)*Math.cos(a)),[l(n+Math.atan2(Math.sin(a)*Math.sin(c)*Math.cos(r),Math.cos(c)-Math.sin(r)*Math.sin(h))),l(h)]));return y.push(y[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[y]},properties:{}}}var c=/*#__PURE__*/function(){function t(t){this.mode="circle",this.store=void 0,this.project=void 0,this.center=void 0,this.clickCount=0,this.currentCircleId=void 0,this.styling=void 0,this.styling=t&&t.styling?e({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},t.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var o=t.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onClick=function(t){if(0===this.clickCount){this.center=[t.lng,t.lat];var e=a({center:this.center,radiusKilometers:1e-5});this.currentCircleId=this.store.create(e.geometry,{mode:this.mode}),this.clickCount++}else this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},o.onMouseMove=function(t){if(1===this.clickCount){var e=(n=[t.lng,t.lat],s=(r=function(t){return t*Math.PI/180})((i=this.center)[1]),l=r(i[0]),h=(c=r(n[1]))-s,d=r(n[0])-l,p=Math.sin(h/2)*Math.sin(h/2)+Math.cos(s)*Math.cos(c)*Math.sin(d/2)*Math.sin(d/2),2*Math.atan2(Math.sqrt(p),Math.sqrt(1-p))*6371e3/1e3),o=a({center:this.center,radiusKilometers:e});this.store.updateGeometry(this.currentCircleId,o.geometry)}var i,n,r,s,l,c,h,d,p},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentCircleId)}catch(t){}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0},t}(),h=/*#__PURE__*/function(){function t(t){this.mode="freehand",this.store=void 0,this.project=void 0,this.startingClick=!1,this.currentId=void 0,this.skip=0,this.everyNthMouseEvent=void 0,this.styling=void 0,this.styling=t&&t.styling?e({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},t.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},this.everyNthMouseEvent=t&&t.everyNthMouseEvent||10}var o=t.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},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(this.currentId,{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)return this.currentId=this.store.create({type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},{mode:this.mode}),void(this.startingClick=!0);this.startingClick=!1,this.currentId=void 0},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentId)}catch(t){}this.currentId=void 0,this.startingClick=!1},t}();function d(t){var e;"Polygon"===t.geometry.type?e=t.geometry.coordinates:"LineString"===t.geometry.type&&(e=[t.geometry.coordinates]);for(var o=[],i=0;i<e.length;i++)for(var n=0;n<e[i].length-1;n++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)a(i,n,r,s);return o.length>0;function l(t){return t<0||t>1}function a(t,i,n,r){var s,a=e[t][i],c=e[t][i+1],h=e[n][r],d=e[n][r+1],u=function(t,e,o,i){if(p(t,o)||p(t,i)||p(e,o)||p(i,o))return null;var n=t[0],r=t[1],s=e[0],l=e[1],a=o[0],c=o[1],h=i[0],d=i[1],u=(n-s)*(c-d)-(r-l)*(a-h);return 0===u?null:[((n*l-r*s)*(a-h)-(n-s)*(a*d-c*h))/u,((n*l-r*s)*(c-d)-(r-l)*(a*d-c*h))/u]}(a,c,h,d);null!==u&&(s=d[0]!==h[0]?(u[0]-h[0])/(d[0]-h[0]):(u[1]-h[1])/(d[1]-h[1]),l(c[0]!==a[0]?(u[0]-a[0])/(c[0]-a[0]):(u[1]-a[1])/(c[1]-a[1]))||l(s)||(u.toString(),o.push(u)))}}function p(t,e){return t[0]===e[0]&&t[1]===e[1]}var u=function(t,e){var o=e.x-t.x,i=e.y-t.y;return Math.sqrt(i*i+o*o)},y=/*#__PURE__*/function(){function t(t){this.mode="linestring",this.store=void 0,this.project=void 0,this.pointerDistance=void 0,this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=void 0,this.styling=void 0,this.styling=t&&t.styling?e({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},t.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},this.pointerDistance=t&&t.pointerDistance||40,this.allowSelfIntersections=!t||void 0===t.allowSelfIntersections||t.allowSelfIntersections}var o=t.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onMouseMove=function(t){if(this.currentId&&0!==this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);e.coordinates.pop(),this.store.updateGeometry(this.currentId,{type:"LineString",coordinates:[].concat(e.coordinates,[[t.lng,t.lat]])})}},o.onClick=function(t){if(0===this.currentCoordinate)this.currentId=this.store.create({type:"LineString",coordinates:[[t.lng,t.lat],[t.lng,t.lat]]},{mode:this.mode}),this.currentCoordinate++;else if(1===this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry(this.currentId,{type:"LineString",coordinates:[e.coordinates[0],[t.lng,t.lat],[t.lng,t.lat]]}),this.currentCoordinate++}else{var o=this.store.getGeometryCopy(this.currentId),i=o.coordinates[o.coordinates.length-2],n=this.project(i[0],i[1]);if(u({x:n.x,y:n.y},{x:t.containerX,y:t.containerY})<this.pointerDistance)o.coordinates.pop(),this.store.updateGeometry(this.currentId,{type:"LineString",coordinates:[].concat(o.coordinates)}),this.currentCoordinate=0,this.currentId=void 0;else{var r={type:"LineString",coordinates:[].concat(o.coordinates,[[t.lng,t.lat]])};if(!this.allowSelfIntersections&&d({type:"Feature",geometry:r,properties:{}}))return;this.store.updateGeometry(this.currentId,r),this.currentCoordinate++}}},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentId)}catch(t){}this.currentId=void 0,this.currentCoordinate=0},t}(),g=/*#__PURE__*/function(){function t(t){this.mode="point",this.store=void 0,this.styling=void 0,this.styling=t&&t.styling?e({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},t.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var o=t.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange)},o.onClick=function(t){if(!this.store)throw new Error("Mode must be registered first");this.store.create({type:"Point",coordinates:[t.lng,t.lat]},{mode:this.mode})},o.onMouseMove=function(){},o.onKeyPress=function(){},o.cleanUp=function(){},t}(),f=/*#__PURE__*/function(){function t(t){this.mode="polygon",this.store=void 0,this.project=void 0,this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=void 0,this.pointerDistance=void 0,this.styling=void 0,this.pointerDistance=t&&t.pointerDistance||40,this.styling=t&&t.styling?e({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},t.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},this.allowSelfIntersections=!t||void 0===t.allowSelfIntersections||t.allowSelfIntersections}var o=t.prototype;return o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project},o.onMouseMove=function(t){if(this.currentId&&0!==this.currentCoordinate){var e,o=this.store.getGeometryCopy(this.currentId).coordinates[0];e=1===this.currentCoordinate?[o[0],[t.lng,t.lat],o[0],o[0]]:2===this.currentCoordinate?[o[0],o[1],[t.lng,t.lat],o[0]]:[].concat(o.slice(0,-2),[[t.lng,t.lat],o[0]]),this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[e]})}},o.onClick=function(t){if(0===this.currentCoordinate)this.currentId=this.store.create({type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},{mode:this.mode}),this.currentCoordinate++;else if(1===this.currentCoordinate){var e=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[[e.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],e.coordinates[0][0]]]}),this.currentCoordinate++}else if(2===this.currentCoordinate){var o=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry(this.currentId,{type:"Polygon",coordinates:[[o.coordinates[0][0],o.coordinates[0][1],[t.lng,t.lat],[t.lng,t.lat],o.coordinates[0][0]]]}),this.currentCoordinate++}else{var i=this.store.getGeometryCopy(this.currentId),n=i.coordinates[0][0],r=this.project(n[0],n[1]),s=u({x:r.x,y:r.y},{x:t.containerX,y:t.containerY});if(console.log(s,this.pointerDistance),s<this.pointerDistance)this.currentCoordinate=0,this.currentId=void 0;else{var l={type:"Polygon",coordinates:[[].concat(i.coordinates[0].slice(0,-1),[[t.lng,t.lat],i.coordinates[0][0]])]};if(this.currentCoordinate>2&&!this.allowSelfIntersections&&d({type:"Feature",geometry:l,properties:{}}))return void this.store.updateGeometry(this.currentId,i);console.log(l),this.store.updateGeometry(this.currentId,l),this.currentCoordinate++}}},o.onKeyPress=function(t){"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){try{this.store.delete(this.currentId)}catch(t){}this.currentId=void 0,this.currentCoordinate=0},t}();function v(t,e){for(var o,i,n,r=!1,s=0,l=e.length;s<l;s++)for(var a=e[s],c=0,h=a.length,d=h-1;c<h;d=c++)(i=a[c])[1]>(o=t)[1]!=(n=a[d])[1]>o[1]&&o[0]<(n[0]-i[0])*(o[1]-i[1])/(n[1]-i[1])+i[0]&&(r=!r);return r}var C=function(t,e,o){var i=function(t){return t*t},n=function(t,e){return i(t.x-e.x)+i(t.y-e.y)};return Math.sqrt(function(t,e,o){var i=n(e,o);if(0===i)return n(t,e);var r=((t.x-e.x)*(o.x-e.x)+(t.y-e.y)*(o.y-e.y))/i;return r=Math.max(0,Math.min(1,r)),n(t,{x:e.x+r*(o.x-e.x),y:e.y+r*(o.y-e.y)})}(t,e,o))},_=/*#__PURE__*/function(){function t(t){this.mode="select",this.store=void 0,this.project=void 0,this.selected=[],this.pointerDistance=void 0,this.styling=void 0,this.pointerDistance=t&&t.pointerDistance||40,this.styling=t&&t.styling?e({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"},t.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var o=t.prototype;return o.onClick=function(t){for(var e,o=this.store.copyAll(),i=Infinity,n=0;n<o.length;n++){var r=o[n],s=r.geometry;if("Point"===s.type){var l=this.project(s.coordinates[0],s.coordinates[1]),a=u({x:l.x,y:l.y},{x:t.containerX,y:t.containerY});a<this.pointerDistance&&a<i&&(i=a,e=r.id)}else if("LineString"===s.type)for(var c=0;c<s.coordinates.length-1;c++){var h=s.coordinates[c],d=s.coordinates[c+1],p=C({x:t.containerX,y:t.containerY},this.project(h[0],h[1]),this.project(d[0],d[1]));p<this.pointerDistance&&p<i&&(i=p,e=r.id)}else"Polygon"===s.type&&v([t.lng,t.lat],s.coordinates)&&(i=0,e=r.id)}e?(this.selected=[e],this.onSelect(e)):this.selected.length&&(this.selected=[],this.onDeselect())},o.onKeyPress=function(t){var e=this;if("Delete"===t.key){if(!this.selected.length)return;this.selected.forEach(function(t){e.store.delete(t)}),this.selected=[],this.onDeselect()}else"Escape"===t.key&&this.cleanUp()},o.cleanUp=function(){this.selected.length&&this.onDeselect(),this.selected=[]},o.onMouseMove=function(){},o.register=function(t){this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect},o.onDeselect=function(){},o.onSelect=function(t){},t}(),m=/*#__PURE__*/function(){function t(){this.mode="static",this.styling={polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8"}}var e=t.prototype;return e.register=function(){},e.onKeyPress=function(){},e.onClick=function(){},e.onMouseMove=function(){},e.cleanUp=function(){},t}(),L=/*#__PURE__*/function(){function t(t){var e=this;this.store=void 0,this._onChange=void 0,this.store={},t&&t.data&&t.data.forEach(function(t){e.featureValidation(t),e.store[t.id]=t})}var e=t.prototype;return e.featureValidation=function(t){if(!t||!t.id)throw new Error("Feature has no id");if("string"!=typeof t.id||36!==t.id.length)throw new Error("Feature must have uuid4 ID "+t.id);if(!t.geometry)throw new Error("Feature has no geometry");if(!t.properties)throw new Error("Feature has no properties");if(!["Polygon","LineString","Point"].includes(t.geometry.type))throw new Error("Feature is not Point, LineString or Polygon");if(!Array.isArray(t.geometry.coordinates))throw new Error("Feature coordinates is not an array")},e.getId=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},e.registerOnChange=function(t){this._onChange=function(e,o){t(e,o)}},e.updateGeometry=function(t,e){var o=this.store[t];if(!o)throw new Error("No feature with this id, can not update geometry");return o.geometry=JSON.parse(JSON.stringify(e)),this._onChange&&this._onChange(t,"update"),t},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id, can not get geometry copy");return JSON.parse(JSON.stringify(e.geometry))},e.create=function(t,e){void 0===e&&(e={});var o=this.getId();return this.store[o]={id:o,type:"Feature",geometry:t,properties:e},this._onChange&&this._onChange(o,"create"),o},e.delete=function(t){if(!this.store[t])throw new Error("No feature with this id, can not delete");delete this.store[t],this._onChange&&this._onChange(t,"delete")},e.copyAll=function(){var t=this;return JSON.parse(JSON.stringify(Object.keys(this.store).map(function(e){return t.store[e]})))},t}();t.TerraDraw=/*#__PURE__*/function(){function t(t){var o=this;if(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 m,this._modes=e({},t.modes,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[]},t.data){this._store=new L({data:t.data});var i=this._store.copyAll().filter(function(t){return!!Object.keys(o._modes).includes(t.properties.mode)||(o._store.delete(t.id),!1)});this._adapter.render(i,this.getModeStyles())}else this._store=new L;Object.keys(this._modes).forEach(function(t){o._modes[t].register({store:o._store,project:o._adapter.project,onChange:function(t,e){o._eventListeners.change.forEach(function(o){o(t,e)}),o._adapter.render(o._store.copyAll(),o.getModeStyles())},onSelect:function(t){o._eventListeners.select.forEach(function(e){e(t)});var e=o._store.copyAll();e.forEach(function(e){e.id===t&&(e.properties.selected=!0)}),o._adapter.render(e,o.getModeStyles())},onDeselect:function(){o._eventListeners.deselect.forEach(function(t){t()});var t=o._store.copyAll();o._adapter.render(t,o.getModeStyles())}})})}var o,i,n=t.prototype;return n.getModeStyles=function(){var t=this,e={};return Object.keys(this._modes).forEach(function(o){e[o]=t._modes[o].styling}),e},n.getSnapshot=function(){return this._store.copyAll()},n.changeMode=function(t){if(!this._modes[t])throw new Error("No mode with this name present");this._mode.cleanUp(),this._mode=this._modes[t]},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)},onKeyPress:function(e){t._mode.onKeyPress(e)}})},n.stop=function(){this._enabled=!1,this._adapter.unregister()},n.on=function(t,e){var o=this._eventListeners[t];o.includes(e)||o.push(e)},n.off=function(t,e){var o=this._eventListeners[t];o.includes(e)&&o.splice(o.indexOf(e),1)},o=t,(i=[{key:"enabled",get:function(){return this._enabled}}])&&function(t,e){for(var o=0;o<e.length;o++){var i=e[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}(o.prototype,i),Object.defineProperty(o,"prototype",{writable:!1}),t}(),t.TerraDrawCircleMode=c,t.TerraDrawFreehandMode=h,t.TerraDrawGoogleMapsAdapter=i,t.TerraDrawLeafletAdapter=n,t.TerraDrawLineStringMode=y,t.TerraDrawMapboxGLAdapter=r,t.TerraDrawPointMode=g,t.TerraDrawPolygonMode=f,t.TerraDrawSelectMode=_});
|
|
2
|
+
//# sourceMappingURL=terra-draw.umd.js.map
|