// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("exports ../../chunks/tslib.es6 ../../geometry ../../Graphic ../../intl ../../symbols ../../core/colorUtils ../../core/maybe ../../core/reactiveUtils ../../core/unitFormatUtils ../../core/unitUtils ../../core/accessorSupport/decorators/property ../../core/has ../../core/Logger ../../core/RandomLCG ../../core/accessorSupport/decorators/subclass ../../core/support/UpdatingHandles ../../geometry/geometryEngine ../../geometry/projection ../../geometry/support/geodesicUtils ../../layers/GraphicsLayer ../../views/ViewingMode ../../views/2d/interactive/SnappingVisualizer2D ../../views/draw/Draw ../../views/interactive/coordinateHelper ../../views/interactive/dragEventPipeline ../../views/interactive/GraphicManipulator ../../views/interactive/InteractiveToolBase ../../views/interactive/editGeometry/EditGeometry ../../views/interactive/editGeometry/EditGeometryOperations ../../views/interactive/snapping/SnappingContext ../../views/interactive/snapping/SnappingDragPipelineStep ../../views/interactive/snapping/SnappingManagerPool ../../views/interactive/snapping/snappingUtils ../../intl/messages ../../intl/locale ../../geometry/Point ../../symbols/SimpleFillSymbol ../../symbols/SimpleLineSymbol ../../symbols/TextSymbol ../../symbols/Font ../../symbols/SimpleMarkerSymbol ../../geometry/Polyline ../../geometry/SpatialReference ../../geometry/Polygon".split(" "), function(g,p,la,x,ma,na,u,v,w,t,E,q,oa,pa,qa,O,P,l,m,h,A,F,Q,R,S,B,T,U,V,G,W,X,Y,Z,H,aa,C,ba,ca,da,ea,I,J,y,fa){function ha(a,b,f){var d={style:"circle",color:u.multiplyOpacity(b.effectiveTheme.accentColor,.5),outline:{type:"simple-line",width:0}};const e=new I({...d,size:8});d=new I({...d,size:12});a=new x({geometry:a,symbol:e});return new T.GraphicManipulator({view:b,layer:f,graphic:a,focusedSymbol:d})}function K(a,b,f){if(2===a.length)return a=new J({paths:a,spatialReference:b}),b?.isGeographic? h.isSupported(b)?b=h.geodesicDensify(a,1E5):(a=m.project(a,y.WGS84),a=h.geodesicDensify(a,1E5),b=m.project(a,b)):b?.isWebMercator?b=l.geodesicDensify(a,1E5,"meters"):l.planarLength(a,"meters")>=(f??Infinity)?(a=m.project(a,y.WGS84),a=h.geodesicDensify(a,1E5),b=m.project(a,b)):b=a,{measurement:null,fillGeometry:null,outlineGeometry:b};a.push(a[0]);var d=new J({paths:[a],spatialReference:b}),e=new fa({rings:[a],spatialReference:b});let c=a=null;if(b?.isGeographic)if(h.isSupported(b)){a=h.geodesicDensify(d, 1E5);c=h.geodesicDensify(e,1E5);c=l.simplify(c);if(!c)return null;e=h.geodesicLengths([d],"meters")[0];d=h.geodesicAreas([c],"square-meters")[0]}else{a=y.WGS84;d=m.project(d,a);e=m.project(e,a);a=h.geodesicDensify(d,1E5);c=h.geodesicDensify(e,1E5);c=l.simplify(c);if(!c)return null;e=h.geodesicLengths([d],"meters")[0];d=h.geodesicAreas([c],"square-meters")[0];a=m.project(a,b);c=m.project(c,b)}else if(b?.isWebMercator){a=l.geodesicDensify(d,1E5,"meters");c=l.geodesicDensify(e,1E5,"meters");c=l.simplify(c); if(!c)return null;e=l.geodesicLength(d,"meters");d=l.geodesicArea(c,"square-meters")}else{const n=l.planarLength(d,"meters");if(n>=(f??Infinity)){a=y.WGS84;d=m.project(d,a);e=m.project(e,a);a=h.geodesicDensify(d,1E5);c=h.geodesicDensify(e,1E5);c=l.simplify(c);if(!c)return null;e=h.geodesicLengths([d],"meters")[0];d=h.geodesicAreas([c],"square-meters")[0];a=m.project(a,b);c=m.project(c,b)}else{a=d;c=l.simplify(e);if(!c)return null;e=n;d=l.planarArea(c,"square-meters")}}return{measurement:{geometry:c, area:d,perimeter:e},fillGeometry:c,outlineGeometry:a}}function L(a){if(!a)return!1;const {isGeographic:b,isWebMercator:f,isWGS84:d}=a;return b&&!d&&!h.isSupported(a)||!b&&!f}function M(a,b,f){if(!b||!a)return null;const d={area:null,perimeter:null},{area:e,perimeter:c}=b;switch(f){case "metric":d.area=t.formatMetricArea(a,e,"square-meters");break;case "imperial":d.area=t.formatImperialArea(a,e,"square-meters");break;default:b=E.convertUnit(e,"square-meters",f),d.area=t.formatDecimal(a,b,f)}if(f=ia(f))switch(f){case "metric":d.perimeter= t.formatMetricLength(a,c,"meters");break;case "imperial":d.perimeter=t.formatImperialLength(a,c,"meters");break;default:b=E.convertUnit(c,"meters",f),d.perimeter=t.formatDecimal(a,b,f)}else d.perimeter="";return d}function ia(a){switch(a){case "metric":return"metric";case "imperial":return"imperial";case "square-inches":return"inches";case "square-feet":return"feet";case "square-yards":return"yards";case "square-miles":return"miles";case "square-us-feet":return"us-feet";case "square-meters":return"meters"; case "square-kilometers":return"kilometers";case "acres":return"imperial";case "ares":case "hectares":return"metric";case "square-millimeters":return"millimeters";case "square-centimeters":return"centimeters";case "square-decimeters":return"decimeters";default:return null}}g.AreaMeasurement2DTool=class extends U.InteractiveToolBase{constructor(a){super(a);this._drawActive=!1;this._measurementLayer=new A({internal:!0,listMode:"hide",visible:!1});this._manipulatorLayer=new A({internal:!0,listMode:"hide", visible:!1});this._snappingLayer=new A({internal:!0,listMode:"hide",visible:!1});this._updatingHandles=new P.UpdatingHandles;this._vertices=[];this.measurementLabel=this.measurement=this.geodesicDistanceThreshold=null}initialize(){H.fetchMessageBundle("esri/core/t9n/Units").then(b=>{this.messages=b});const a=this.view;this._draw=new R({view:a});a.map.addMany([this._measurementLayer,this._manipulatorLayer,this._snappingLayer]);a.focus();this._snappingManagerResult=Y.acquire(a);this.addHandles([aa.onLocaleChange(async()=> {this.messages=await H.fetchMessageBundle("esri/core/t9n/Units")}),w.watch(()=>[this.unit,this.geodesicDistanceThreshold,this.messages],()=>{this._updateGraphics()},w.initial),w.watch(()=>[this.view.effectiveTheme.accentColor,this.view.effectiveTheme.textColor],()=>{if(this._vertices.length){var b=this._vertices.map(({coord:f})=>f);for(const {handle:f}of this._vertices)f.remove();this._vertices=[];this._measurementLayer.removeAll();this._manipulatorLayer.removeAll();this._snappingLayer.removeAll(); this.manipulators.removeAll();this._updateSketch(b)}}),w.watch(()=>this.snappingOptions.featureSources,b=>{for(const f of b)if(f.layer===this._measurementLayer||f.layer===this._manipulatorLayer)f.enabled=!1},w.initial),this._snappingManagerResult]);Z.setupSnappingToggleHandles(this)}destroy(){const {map:a}=this.view;this._draw.view=null;this._draw=v.destroyMaybe(this._draw);a.removeMany([this._measurementLayer,this._manipulatorLayer,this._snappingLayer]);this._measurementLayer.removeAll();this._manipulatorLayer.removeAll(); this._snappingLayer.removeAll();this._set("measurement",null);this._set("measurementLabel",null);this._measurementLayer=v.destroyMaybe(this._measurementLayer);this._manipulatorLayer=v.destroyMaybe(this._manipulatorLayer);this._snappingLayer=v.destroyMaybe(this._snappingLayer);this._updatingHandles=v.destroyMaybe(this._updatingHandles);this._resetVertices()}get _snappingManager(){return this._snappingManagerResult.snappingManager}get cursor(){return this._drawActive?"crosshair":null}set editable(a){this._set("editable", a);a||this._draw.reset()}get snappingOptions(){return this._snappingManager.options}get updating(){return this._updatingHandles.updating||this._snappingManager.updating}onActivate(){this._drawActive||0!==this._vertices.length||this._startSketch()}onShow(){this._measurementLayer.visible=!0;this._manipulatorLayer.visible=!0;this._snappingLayer.visible=!0}onHide(){this._measurementLayer.visible=!1;this._manipulatorLayer.visible=!1;this._snappingLayer.visible=!1}reset(){this.manipulators.removeAll(); this._resetVertices();this._measurementLayer.removeAll();this._manipulatorLayer.removeAll();this._set("measurement",null);this._set("measurementLabel",null);this._draw.reset();this._drawActive=!1}_getSnappingContext(a){return new W.SnappingContext({elevationInfo:{mode:"on-the-ground",offset:0},pointer:a,editGeometryOperations:new G.EditGeometryOperations(new V.EditGeometry("point",S.createCoordinateHelper(!1,!1,this.view.spatialReference)),F.ViewingMode.Local),visualizer:new Q.SnappingVisualizer2D(this._snappingLayer)})}_resetVertices(){for(const {handle:a}of this._vertices)a.remove(); this._vertices=[]}_startSketch(){this._drawActive=!0;const a=this._draw.create("polyline",{mode:"click",snappingManager:this._snappingManager});a.on("vertex-add vertex-update vertex-remove cursor-update undo redo".split(" "),b=>this._updateSketch(b.vertices));a.on("draw-complete",()=>this._stopSketch())}_stopSketch(){3>this._vertices.length?(this.reset(),this._startSketch()):(this.manipulators.forEach(({manipulator:a})=>{a.interactive=!0}),this._drawActive=!1,this.finishToolCreation())}_updateSketch(a){const b= this.view.spatialReference;if(b&&(!L(b)||m.isLoaded())){for(;this._vertices.length>a.length;){const {handle:e,manipulator:c}=this._vertices.pop();e.remove();this.manipulators.remove(c)}for(let e=this._vertices.length;e{if(r=r.vertices.at(0))this._vertices[e].coord=[r.pos[0], r.pos[1]],this._updateGraphics()});f=B.createManipulatorDragEventPipeline(d,(r,ja,z,ka)=>{z=this._getSnappingContext(ka);({snappingStep:z}=X.createSnapDragEventPipelineStep({snappingContext:z,snappingManager:this._snappingManager,updatingHandles:this._updatingHandles}));ja.next(B.screenToMap(this.view)).next(D=>{if("start"===D.action){const N=new C(D.mapStart);r.graphic.geometry=N;k.trySetGeometry(N)}return D}).next(...z).next(B.dragManipulatedObject({operations:k})).next(()=>{r.graphic.geometry= k.data.geometry})});this._vertices.push({manipulator:d,coord:[c,n],handle:f})}if(this._vertices.length){d=this._vertices.length-1;f=this._vertices[d];const [e,c]=a[d];if(f.coord[0]!==e||f.coord[1]!==c)f.coord=[e,c],f.manipulator.graphic.geometry=new C({x:e,y:c,spatialReference:b});const n=this._drawActive?this._vertices[d].manipulator:null;this.manipulators.forEach(({manipulator:k})=>{k.interactive=null==n||k!==n})}this._updateGraphics()}}_updateGraphics(){if(2>this._vertices.length)this._measurementLayer.removeAll(); else{var a=this._vertices.map(({coord:r})=>r);if(a=K(a,this.view.spatialReference,this.geodesicDistanceThreshold)){var {measurement:b,fillGeometry:f,outlineGeometry:d}=a;this._set("measurement",b);a=b?M(this.messages,b,this.unit):null;this._set("measurementLabel",a);if(f||d){var {graphics:e}=this._measurementLayer;var c=3===e.length;({effectiveTheme:k}=this.view);if(c){c=e.at(0);var n=e.at(1);var k=e.at(2)}else c=new x({symbol:new ba({color:u.multiplyOpacity(k.accentColor,.3),outline:null})}),n=new x({symbol:new ca({color:k.accentColor, width:2})}),k=new x({symbol:new da({color:k.textColor,font:new ea({size:14,family:"sans-serif"}),haloColor:u.multiplyOpacity(u.getContrast(k.textColor,u.BrightnessThreshold.Low),.5),haloSize:2})}),e.removeAll(),e.addMany([c,n,k]);c.geometry=f;n.geometry=d;k.geometry=f?.centroid;k.symbol.text=a?.area??""}}}}};p.__decorate([q.property()],g.AreaMeasurement2DTool.prototype,"_drawActive",void 0);p.__decorate([q.property({readOnly:!0})],g.AreaMeasurement2DTool.prototype,"cursor",null);p.__decorate([q.property({value:!0})], g.AreaMeasurement2DTool.prototype,"editable",null);p.__decorate([q.property({type:Number})],g.AreaMeasurement2DTool.prototype,"geodesicDistanceThreshold",void 0);p.__decorate([q.property({readOnly:!0})],g.AreaMeasurement2DTool.prototype,"measurement",void 0);p.__decorate([q.property({readOnly:!0})],g.AreaMeasurement2DTool.prototype,"measurementLabel",void 0);p.__decorate([q.property()],g.AreaMeasurement2DTool.prototype,"messages",void 0);p.__decorate([q.property()],g.AreaMeasurement2DTool.prototype, "unit",void 0);p.__decorate([q.property()],g.AreaMeasurement2DTool.prototype,"updating",null);p.__decorate([q.property({constructOnly:!0})],g.AreaMeasurement2DTool.prototype,"view",void 0);g.AreaMeasurement2DTool=p.__decorate([O.subclass("esri.widgets.AreaMeasurement2D.AreaMeasurement2DTool")],g.AreaMeasurement2DTool);g.createAreaMeasurementInfo2D=K;g.createAreaMeasurementLabel=M;g.isProjectionEngineRequired=L;g.isSupported=function(a){return null!=a};Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});