12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Handles.js";import{isSome as s,isNone as i,unwrap as o}from"../../core/maybe.js";import{watch as r,initial as n,whenOnce as a}from"../../core/reactiveUtils.js";import{measurementAreaUnits as l}from"../../core/unitUtils.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as h}from"../../core/accessorSupport/decorators/subclass.js";import{load as p}from"../../geometry/projection.js";import{defaultUnitPropertyMetadata as d}from"../../properties/defaultUnit.js";import{isSupported as c,isProjectionEngineRequired as m,AreaMeasurement2DTool as y}from"./AreaMeasurement2DTool.js";import{InteractiveToolViewModel as f}from"../support/InteractiveToolViewModel.js";let v=class extends f{constructor(e){super(e),this.supportedViewType="2d",this.unsupportedErrorMessage="AreaMeasurement2DViewModel is only supported in 2D views.",this._handles=new t,this.geodesicDistanceThreshold=1e5}initialize(){this._handles.add([r((()=>o(this.view)?.spatialReference),(()=>this.clear())),r((()=>this.unit),(e=>{s(this.tool)&&(this.tool.unit=e)}),n),r((()=>this.geodesicDistanceThreshold),(e=>{s(this.tool)&&(this.tool.geodesicDistanceThreshold=e)}),n)])}destroy(){this._handles&&(this._handles.destroy(),this._handles=null)}get measurement(){return s(this.tool)?this.tool.measurement:null}get measurementLabel(){return s(this.tool)?this.tool.measurementLabel:null}get state(){return this.disabled||i(this.view)||!c(this.view.spatialReference)?"disabled":s(this.tool)&&this.tool.measurement?this.tool.active?"measuring":"measured":"ready"}get unit(){return this._validateUnit(this.defaultUnit)}set unit(e){this._overrideIfSome("unit",this._validateUnit(e))}get unitOptions(){return l}set unitOptions(e){this._overrideIfSome("unitOptions",this._validateUnits(e))}async start(){const e=this.view;s(e)&&(await a((()=>e.ready)),m(e.spatialReference)&&await p()),this.createTool({interactive:!0})}clear(){this.removeTool()}constructTool(){return new y({view:o(this.view),visible:this.visible,geodesicDistanceThreshold:this.geodesicDistanceThreshold,unit:this.unit})}_validateUnit(e){return this.unitOptions.includes(e)?e:this.unitOptions.includes(this.defaultUnit)?this.defaultUnit:this.unitOptions[0]}_validateUnits(e=[]){const t=e.filter((e=>l.includes(e)));return 0===t.length?l.slice():t}};e([u(d)],v.prototype,"defaultUnit",void 0),e([u({type:Number})],v.prototype,"geodesicDistanceThreshold",void 0),e([u({readOnly:!0})],v.prototype,"measurement",null),e([u({readOnly:!0})],v.prototype,"measurementLabel",null),e([u({readOnly:!0})],v.prototype,"state",null),e([u({type:String})],v.prototype,"unit",null),e([u({type:[String]})],v.prototype,"unitOptions",null),v=e([h("esri.widgets.AreaMeasurement2D.AreaMeasurement2DViewModel")],v);const g=v;export{g as default};
|