@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 8.03 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 i from"../../../core/Accessor.js";import{createTask as s}from"../../../core/asyncUtils.js";import a from"../../../core/Collection.js";import{makeHandle as r}from"../../../core/handleUtils.js";import{destroyMaybe as o}from"../../../core/maybe.js";import{ignoreAbortErrors as n,isAborted as h,throwIfAborted as l}from"../../../core/promiseUtils.js";import{pausable as c,sync as p,watch as y,syncAndInitial as d}from"../../../core/reactiveUtils.js";import{property as m,subclass as u}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as g}from"../../../core/support/UpdatingHandles.js";import _ from"../../../layers/GraphicsLayer.js";import k from"../../../symbols/CIMSymbol.js";import f from"../../../symbols/SimpleLineSymbol.js";import v from"../../../symbols/support/ElevationInfo.js";import{ExclusiveOperationManager as G}from"../ExclusiveOperationManager.js";import{isPolyline as b,isValidInputGraphic as w,isInternalGraphic as S}from"./elevationProfileGeometryUtils.js";import{ViewEventPriorities as M}from"../../input/InputManager.js";import{isCancelEvent as j}from"../../interactive/interactiveToolUtils.js";import{makeAllLayerSnappingOptions as L}from"../../interactive/snapping/allLayerSnapping.js";import V from"../../../widgets/Sketch/SketchViewModel.js";let O=class extends i{constructor(e){super(e),this._sketchViewModels=new a,this._updatingHandles=new g,this._operationManager=new G}initialize(){const{view:e}=this;this._allLayerSnappingOptions=L(this.view,{selfEnabled:!0,excludeInternal:!0}),this._graphicsLayer=new _({listMode:"hide",internal:!0}),this._externalGeometryChangeHandle=c(()=>this._analysis.geometry,()=>this._ensureUpdatedSketchGraphic(),p),this.addHandles([y(()=>({map:e.map,internalGraphicsLayer:this._graphicsLayer,state:this.state,geometryVisualizationVisible:this._analysis.viewOptions.geometryVisualizationVisible,visible:this.analysisViewData.visible}),({map:e,internalGraphicsLayer:t,state:i,geometryVisualizationVisible:s,visible:a})=>{I(e,t);const r=this.sketchGraphic;switch(r&&(r.visible=a),i){case"idle":case"reshaping-disabled":r&&!s&&(r.visible=!1),this._operationManager.stop(),this._ensureUpdatedSketchGraphic();break;case"reshaping":n(this._startReshape());break;case"awaiting-sketch":this.analysisViewData.interactive=!0}},d),y(()=>this._analysis.elevationInfo,e=>{this._graphicsLayer.elevationInfo=e},d),this._allLayerSnappingOptions,this._externalGeometryChangeHandle])}destroy(){this._operationManager.destroy(),this._sketchViewModels.drain(e=>o(e));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._updateAnalysisFromSketchGraphic())}get state(){const{visible:e,interactive:t}=this.analysisViewData;if(!e)return"idle";switch(this._operationManager.currentOperationType){case"place":return this._sketching?"sketching":"awaiting-sketch";case"pick-feature":return"picking";default:return this._analysis.geometry?t?"reshaping":"reshaping-disabled":"idle"}}get updating(){return this._sketchViewModels.some(e=>e.updating)||this._updatingHandles.updating}get _sketching(){return this._sketchViewModels.some(e=>e.createGraphic===this.sketchGraphic)}get _analysis(){return this.analysisViewData.analysis}get _lineSymbol(){return C(this.view.type)}place(e){return this._operationManager.start("place",async t=>{const i=this._createSketchViewModel(),s=this._analysis.clone();this._ensureUpdatedSketchGraphic();const a=this.sketchGraphic,o=this._analysis.elevationInfo,l=r(()=>{this.sketchGraphic===a&&(this._graphicsLayer.elevationInfo=o)}),c=i.on("create",e=>{switch(e.state){case"start":this._graphicsLayer.removeAll(),this.sketchGraphic=e.graphic,this._analysis.elevationInfo=this._graphicsLayer.elevationInfo;break;case"active":this._updateAnalysisFromSketchGraphic();break;case"complete":this.sketchGraphic&&(this._updateAnalysisFromSketchGraphic(),this._addSketchGraphic(this.sketchGraphic)),t.stop();break;case"cancel":t.stop()}});t.handles.push(c,r(()=>(c.remove(),i.destroy(),this._sketchViewModels.remove(i),this._updateAnalysisFromSketchGraphic(),this._analysis.valid?h(e)||s.equals(this._analysis)?t.reject():void t.resolve({}):(this._clear(),t.reject()))),l),this._graphicsLayer.elevationInfo=U,await this._updatingHandles.addPromise(n(i.create("polyline")))},e)}async pickFeature(e){return this._operationManager.start("pick-feature",async e=>{const{view:t}=this;t.closePopup();let i=null;const a=a=>{a.defer(async()=>{i?.abort(),i=s(async i=>{const{results:s}=await t.hitTest(a);l(i);let r=null;for(const e of s)if("graphic"===e.type&&w(e.graphic)&&!S(e.graphic)){r=e.graphic;break}r&&(a.preventDefault(),a.stopPropagation(),this._externalGeometryChangeHandle.pause(),this.sketchGraphic=null,this._analysis.setGeometryFromFeature(r),this._externalGeometryChangeHandle.resume(),e.resolve({feature:r}),e.stop())}),await i.promise})},o=t=>{j(t)&&(e.reject(),e.stop())};e.handles.push(t.on("immediate-click",a,M.TOOL),t.on("key-down",o,M.TOOL),t.acquireCursor("crosshair","high"),r(()=>{i?.abort(),e.reject()})),t.focus()},e)}_startReshape(){const e=this._createSketchViewModel();return this._sketchViewModels.add(e),this._operationManager.start("reshape",async t=>{const i=()=>{const t=this._ensureUpdatedSketchGraphic();return t?this._updatingHandles.addPromise(e.update(t,{tool:"reshape"})):Promise.resolve()};if(!this._ensureUpdatedSketchGraphic())return;const s=e.on("update",e=>{this._updateAnalysisFromSketchGraphic(),"complete"===e.state&&("reshaping"===this.state?n(i()):t.resolve())});t.handles.push(s,r(()=>{s.remove(),this._sketchViewModels.remove(e),e.destroy(),t.resolve()})),await i()})}_createSketchViewModel(){return new V({layer:this._graphicsLayer,view:this.view,defaultCreateOptions:{mode:"click",hasZ:!0},updateOnGraphicClick:!1,defaultUpdateOptions:{enableMoveAllGraphics:!1,enableRotation:!1,enableScaling:!1,enableZ:!1,highlightOptions:{enabled:!1},multipleSelectionEnabled:!1,reshapeOptions:{shapeOperation:"none"},toggleToolOnClick:!1,tool:"reshape"},polylineSymbol:this._lineSymbol,activeLineSymbol:this._lineSymbol,snappingOptions:this._allLayerSnappingOptions.options})}_ensureUpdatedSketchGraphic(){const{geometry:e}=this._analysis;if(!e)return this.sketchGraphic=null,this._graphicsLayer.removeAll(),null;const i=this.sketchGraphic??=new t({symbol:this._lineSymbol,geometry:e});return i.geometry=e,this._addSketchGraphic(i),i}_addSketchGraphic(e){const{graphics:t}=this._graphicsLayer;t.includes(e)||t.add(e),1!==t.length&&t.removeMany(t.filter(t=>t!==e))}_clear(){this.sketchGraphic=null,this._analysis.clear()}_updateAnalysisFromSketchGraphic(){this._externalGeometryChangeHandle.pause();let e=this.sketchGraphic?.geometry;b(e)||(e=null);const t=this._analysis;t.geometry!==e&&(t.geometry=e),this._externalGeometryChangeHandle.resume()}};function C(e){if("2d"===e){const e={type:"CIMSolidStroke",enable:!0,capStyle:"Butt",joinStyle:"Round",width:1.5};return new k({data:{type:"CIMSymbolReference",symbol:{type:"CIMLineSymbol",symbolLayers:[{...e,effects:[{type:"CIMGeometricEffectDashes",dashTemplate:[5,4],lineDashEnding:"FullGap",controlPointEnding:"NoConstraint"}],color:[0,0,0,255]},{...e,color:[255,255,255,255]}]}}})}return new f({color:[0,0,0,0]})}function I(e,t){t&&(t.removeFromParent(),e?.add(t))}e([m({constructOnly:!0})],O.prototype,"analysisViewData",void 0),e([m({constructOnly:!0})],O.prototype,"view",void 0),e([m()],O.prototype,"sketchGraphic",null),e([m({nonNullable:!0})],O.prototype,"state",null),e([m()],O.prototype,"updating",null),e([m()],O.prototype,"_sketching",null),e([m()],O.prototype,"_analysis",null),e([m()],O.prototype,"_lineSymbol",null),O=e([u("esri.views.analysis.ElevationProfile.ElevationProfileTool")],O);const U=new v({mode:"on-the-ground",offset:0});export{O as ElevationProfileTool};