@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.86 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../../Graphic.js";import s from"../../../../core/Accessor.js";import{makeHandle as a}from"../../../../core/handleUtils.js";import"../../../../core/has.js";import{ignoreAbortErrors as i,isAborted as r}from"../../../../core/promiseUtils.js";import{pausable as o,sync as h,watch as n,syncAndInitial as l}from"../../../../core/reactiveUtils.js";import{property as c,subclass as p}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as d}from"../../../../core/support/UpdatingHandles.js";import m from"../../../../layers/GraphicsLayer.js";import y from"../../../../symbols/SimpleFillSymbol.js";import{isPolygon as u,isPolygonGraphic as g}from"./volumeMeasurementGeometryUtils.js";import{VolumeMeasurementShiftTool as _}from"./VolumeMeasurementShiftTool.js";import{ExclusiveOperationManager as k}from"../../../analysis/ExclusiveOperationManager.js";import{makeAllLayerSnappingOptions as G}from"../../../interactive/snapping/allLayerSnapping.js";import w from"../../../../widgets/Sketch/SketchViewModel.js";let v=class extends s{constructor(e){super(e),this._updatingHandles=new d,this._operationManager=new k,this._onUndoRedo=()=>{this._updateGeometryFromSketchGraphic()}}initialize(){const{analysis:e,analysisViewData:t,view:s}=this;this._graphicsLayer=new m({listMode:"hide",internal:!0,elevationInfo:{mode:"on-the-ground"}});const a=G(s,{selfEnabled:!0,excludeInternal:!0});this._externalGeometryChangeHandle=o(()=>this.analysis.geometry,()=>this._ensureUpdatedSketchGraphic(),h),this._sketchViewModel=new w({layer:this._graphicsLayer,view:s,updateOnGraphicClick:!1,defaultUpdateOptions:{reshapeOptions:{shapeOperation:"move"},enableRotation:!1,enableScaling:!1,enableMoveAllGraphics:!1,enableZ:!1,multipleSelectionEnabled:!1,toggleToolOnClick:!1,tool:"reshape"},polygonSymbol:this._polygonSymbol,snappingOptions:a.options}),this.addHandles([this._sketchViewModel.on(["undo","redo"],this._onUndoRedo),n(()=>({map:s.map,internalGraphicsLayer:this._graphicsLayer,state:this.state}),({map:e,internalGraphicsLayer:t,state:s})=>{switch(S(e,t),s){case"idle":case"reshaping-disabled":this._operationManager.stop(),this._graphicsLayer.removeAll(),this._ensureUpdatedSketchGraphic();break;case"reshaping":i(this._startReshape());break;case"awaiting-sketch":this.analysisViewData.interactive=!0}},l),a,this._externalGeometryChangeHandle]),this._shiftTool=new _({analysis:e,view:s,analysisViewData:t}),this.addHandles(this._shiftTool.on("record-undo",e=>{const t=this._sketchViewModel.activeComponent;"reshape-3d"===t?.type&&t.recordUndo(e.apply,e.undo)})),s.tools.add(this._shiftTool),this.addHandles({remove:()=>s.tools.remove(this._shiftTool)})}destroy(){this._operationManager.destroy(),this._sketchViewModel.destroy();const e=this._graphicsLayer;this.view.map.remove(e),e.destroy()}get sketchGraphic(){return this._get("sketchGraphic")}set sketchGraphic(e){e!==this._get("sketchGraphic")&&(this._set("sketchGraphic",e),this._updateGeometryFromSketchGraphic())}get state(){const{geometry:e}=this.analysis,{interactive:t,visible:s}=this.analysisViewData;return s?this._sketchViewModel.createGraphic?this._sketchViewModel.createGraphic===this.sketchGraphic?"sketching":"awaiting-sketch":e?t?"reshaping":"reshaping-disabled":"idle":"idle"}get updating(){return this._sketchViewModel.updating||this._updatingHandles.updating}get _polygonSymbol(){return new y({color:[0,0,0,0],outline:{color:[0,0,0,0]}})}place(e){return this._operationManager.start("place",async t=>{const s=this.analysis.clone();this._ensureUpdatedSketchGraphic();const i=this._sketchViewModel.on("create",e=>{switch(e.state){case"start":this._graphicsLayer.removeAll(),this.sketchGraphic=e.graphic;break;case"active":this._updateGeometryFromSketchGraphic();break;case"complete":this._updateGeometryFromSketchGraphic(),t.stop();break;case"cancel":t.stop()}});t.handles.push(i,a(()=>(i.remove(),this._sketchViewModel.cancel(),this._updateGeometryFromSketchGraphic(),this.analysis.valid?r(e)||s.equals(this.analysis)?t.reject():void t.resolve({}):(this._clearGeometry(),t.reject())))),await this._updatingHandles.addPromise(this._sketchViewModel.create("polygon"))},e)}_startReshape(){return this._operationManager.start("reshape",async e=>{const t=()=>{const e=this._ensureUpdatedSketchGraphic();return e?(this._graphicsLayer.removeAll(),this._graphicsLayer.add(e),this._updatingHandles.addPromise(this._sketchViewModel.update(e,{tool:"reshape"}))):Promise.resolve()};if(!this._ensureUpdatedSketchGraphic())return;const s=this._sketchViewModel.on("update",s=>{this._updateGeometryFromSketchGraphic(),"complete"===s.state&&("reshaping"===this.state?i(t()):e.resolve())});e.handles.push(s,a(()=>{s.remove(),this._sketchViewModel.cancel(),e.resolve()})),await t()})}_ensureUpdatedSketchGraphic(){const{geometry:e}=this.analysis;return u(e)?(this.sketchGraphic??=new t({geometry:e,symbol:this._polygonSymbol}),this.sketchGraphic.geometry=e,this.sketchGraphic):(this.sketchGraphic=null,null)}_clearGeometry(){this.sketchGraphic=null,this.analysis.geometry=null}_updateGeometryFromSketchGraphic(){this._externalGeometryChangeHandle.pause();const e=this.sketchGraphic;this.analysis.geometry=g(e)?e.geometry:null,this._externalGeometryChangeHandle.resume()}get test(){}};function S(e,t){t&&(t.removeFromParent(),e?.add(t))}e([c({constructOnly:!0})],v.prototype,"analysisViewData",void 0),e([c({constructOnly:!0})],v.prototype,"view",void 0),e([c({constructOnly:!0})],v.prototype,"analysis",void 0),e([c()],v.prototype,"sketchGraphic",null),e([c({nonNullable:!0})],v.prototype,"state",null),e([c()],v.prototype,"updating",null),e([c()],v.prototype,"_polygonSymbol",null),v=e([p("esri.views.3d.analysis.VolumeMeasurement.VolumeMeasurementTool")],v);export{v as default};