@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 9.37 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../Graphic.js";import i from"../../core/Accessor.js";import{createTask as s}from"../../core/asyncUtils.js";import{makeHandle as o}from"../../core/handleUtils.js";import"../../core/has.js";import{destroyMaybe as n,abortMaybe as a}from"../../core/maybe.js";import{ignoreAbortErrors as r,throwIfAborted as l}from"../../core/promiseUtils.js";import{watch as h,syncAndInitial as c,when as p}from"../../core/reactiveUtils.js";import{property as d}from"../../core/accessorSupport/decorators/property.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as u}from"../../core/accessorSupport/decorators/subclass.js";import _ from"../../layers/GraphicsLayer.js";import m from"../../symbols/CIMSymbol.js";import g from"../../symbols/SimpleLineSymbol.js";import{ViewEventPriorities as v}from"../../views/input/InputManager.js";import{isPolyline as y}from"./support/geometryUtils.js";import I from"../Sketch/SketchViewModel.js";var f,S;function b(t){return"2d"===t?new m({data:{type:"CIMSymbolReference",symbol:{type:"CIMLineSymbol",symbolLayers:[{type:"CIMSolidStroke",effects:[{type:"CIMGeometricEffectDashes",dashTemplate:[5,4],lineDashEnding:"FullGap",controlPointEnding:"NoConstraint"}],enable:!0,capStyle:"Butt",joinStyle:"Round",width:1.5,color:[0,0,0,255]},{type:"CIMSolidStroke",enable:!0,capStyle:"Butt",joinStyle:"Round",width:1.5,color:[255,255,255,255]}]}}}):new g({color:[0,0,0,0]})}!function(t){t.Ready="ready",t.Creating="creating",t.Reshaping="reshaping",t.ReshapingDisabled="reshaping-disabled",t.Selecting="selecting",t.Selected="selected"}(f||(f={})),function(t){t.View="view",t.Main="main",t.Interaction="interaction"}(S||(S={}));let k=class extends i{constructor(t){super(t),this.state=f.Ready,this._pendingStartOptions=null,this._previousInputInfo=null,this._shouldRemoveLastPoint=!1,this._sketchedGraphics=new WeakSet,this._creationToolPromise=null,this._updateToolPromise=null,this._updateDisabled=!1}initialize(){this.addHandles(h((()=>({view:this.tool.viewModel.view,visible:this.tool.visible})),(({view:t,visible:e})=>{null!=t&&e?this._attach(t):this._detach()}),c),S.View)}destroy(){this._detach()}get canStopCreating(){const t=this._geometry,e=this._shouldRemoveLastPoint?3:2;return y(t)&&t.paths.length>0&&t.paths[0].length>=e}get _input(){return this.tool.viewModel.input}set _input(t){this.tool.viewModel.input=t}get _geometry(){return this._input?.geometry}get _visibleAndEditable(){return this.tool.visible&&this.tool.editable}get _view(){return this.tool.viewModel.view}get test(){}start(t={mode:"sketch"}){if(!this.tool.editable)return;const e=this._view;if(null!=e&&e.ready)switch(this._pendingStartOptions=null,this._stopInteraction(),null==this._previousInputInfo&&this._storePreviousInput(this._input),this._setSketchedGraphic(null),t.mode){case"sketch":this._set("state",f.Creating),this._startCreationInteraction();break;case"select":this._set("state",f.Selecting),this._startSelectionInteraction()}else this._pendingStartOptions=t}stop(){this._pendingStartOptions=null,this._stopInteractionAndUpdate(),this._clearPreviousInput()}cancel(){this._pendingStartOptions=null,this._stopInteractionAndUpdate(),this._restorePreviousInput()}clear(){this._stopInteractionAndUpdate(),this._set("state",f.Ready),this._clearPreviousInput(),this._input=null,this._pendingStartOptions=null}isSketchedGraphic(t){return null!=t&&this._sketchedGraphics.has(t)}_attach(t){this._detach();const e={mode:"3d"===t.type?"relative-to-ground":"on-the-ground",offset:null};this._graphicsLayer=new _({listMode:"hide",internal:!0,elevationInfo:e});const i=b(t.type);this._sketchVM=new I({layer:this._graphicsLayer,view:t,defaultCreateOptions:{mode:"click",hasZ:!1},updateOnGraphicClick:!1,defaultUpdateOptions:{reshapeOptions:{shapeOperation:"none"},enableRotation:!1,enableScaling:!1,enableMoveAllGraphics:!1,enableZ:!1,multipleSelectionEnabled:!1,toggleToolOnClick:!1,tool:"reshape"},polylineSymbol:i,activeLineSymbol:i}),this.addHandles([p((()=>t.ready),(()=>{const t=this._pendingStartOptions;t&&this.start(t)}),c),h((()=>[this._input,this._visibleAndEditable]),(()=>this._update()),c),h((()=>({map:t.map,graphicsLayer:this._graphicsLayer})),(({map:t,graphicsLayer:e})=>{null!=t&&null!=e&&t.add(e),this._update()}),c)],S.Main)}_detach(){this.removeHandles(S.Main),this._sketchVM=n(this._sketchVM),this._creationToolPromise=null,this._updateToolPromise=null;const t=this._view?.map,e=this._graphicsLayer;null!=t&&null!=e&&t.remove(e),this._graphicsLayer=n(this._graphicsLayer),this._shouldRemoveLastPoint=!1,this._set("state",f.Ready)}_startCreationInteraction(){this._stopInteractionAndUpdate();const t=this._view,i=this._sketchVM;if(null==t||null==i)return;this._shouldRemoveLastPoint=!1;const s=i.on("create",(t=>{const e=t.graphic;switch(t.state){case"complete":this._shouldRemoveLastPoint=!1,this._setSketchedGraphic(e),this._stopInteractionAndUpdate(),this._clearPreviousInput();break;case"cancel":this.cancel();break;case"active":this._setSketchedGraphic(e),"cursor-update"===t.toolEventInfo?.type&&(this._shouldRemoveLastPoint=!0);break;case"start":this._setSketchedGraphic(e)}})),n=()=>{s.remove();const t=this.canStopCreating,o=this._geometry?.clone();i.cancel(),this._creationToolPromise=null,null!=o&&t?this._shouldRemoveLastPoint&&this._setSketchedGraphic(new e({geometry:w(o)})):this._input=null};this.removeHandles(S.Interaction),this.addHandles(o(n),S.Interaction),this._creationToolPromise=r(i.create("polyline"))}_startReshapeInteraction(){this._stopInteraction();const t=this._view,e=this._sketchVM;if(null==t||null==e)return;const i=e.on("update",(t=>{const e=t.graphics[0];switch(t.state){case"complete":this._setSketchedGraphic(e),this._stopInteractionAndUpdate(),this._clearPreviousInput();break;case"active":case"start":this._setSketchedGraphic(e)}})),s=()=>{i.remove(),e.cancel(),this._updateToolPromise=null};this.removeHandles(S.Interaction),this.addHandles(o(s),S.Interaction);const n=this._input;n&&(n.visible=!0,this._updateToolPromise=r(e.update(n,{tool:"reshape"})))}_startSelectionInteraction(){this._stopInteraction();const t=this._view;if(null==t)return;const e=t.cursor,i=o((()=>t.cursor=e));t.cursor="crosshair",t.closePopup();let n=null;const r=o((()=>a(n))),h=t.on("immediate-click",(e=>{e.defer((async()=>{a(n),n=s((async i=>{const{results:s}=await t.hitTest(e);l(i);const o=s.filter((t=>"graphic"===t.type)).map((t=>t.graphic)).find((t=>null!=t.geometry&&"polyline"===t.geometry.type));o&&(e.preventDefault(),e.stopPropagation(),this._input=o,this._clearPreviousInput(),this._stopInteractionAndUpdate())})),await n.promise}))}),v.TOOL),c=t.on("key-down",(t=>{"Escape"===t.key&&this.cancel()}));this.removeHandles(S.Interaction),this.addHandles([h,c,r,i],S.Interaction),t.ready&&t.focus()}_stopInteraction(){this.removeHandles(S.Interaction)}_stopInteractionAndUpdate(){this.hasHandles(S.Interaction)&&(this._updateDisabled=!0,this._stopInteraction(),this._updateDisabled=!1,this._triggerUpdate())}_triggerUpdate(){this._set("state",f.Ready),this._update()}_update(){if(this._updateDisabled)return;const t=this.state;if(t!==f.Selecting){if(this._visibleAndEditable){if(t===f.Creating||t===f.Reshaping&&this.isSketchedGraphic(this._input))return}else this.cancel();this._set("state",this._getNextState()),this._updateVisuals()}else this.stop()}_getNextState(){return null==this._input?f.Ready:this.isSketchedGraphic(this._input)?this.state===f.Creating?f.Creating:this._visibleAndEditable?f.Reshaping:f.ReshapingDisabled:f.Selected}_updateVisuals(){switch(this.state){case f.Creating:break;case f.Reshaping:this._startReshapeInteraction();break;case f.ReshapingDisabled:{this._stopInteractionAndUpdate();const t=this._input;null!=t&&this.isSketchedGraphic(t)&&(t.visible=!1);break}case f.Ready:case f.Selected:this._stopInteractionAndUpdate();case f.Selecting:}this._updateSketchedGraphic()}_storePreviousInput(t){this._previousInputInfo={graphic:t}}_restorePreviousInput(){const t=this._previousInputInfo;null!=t&&(this._clearPreviousInput(),this._input=t.graphic,this._triggerUpdate())}_clearPreviousInput(){this._previousInputInfo=null}_updateSketchedGraphic(){const t=this._graphicsLayer;if(null==t)return;const e=t.graphics,i=this._input;if(null==i||!this.isSketchedGraphic(i))return void e.removeAll();if(-1===e.indexOf(i))e.removeAll(),e.add(i);else if(1!==e.length){const t=e.filter((t=>t!==i));e.removeMany(t)}}_setSketchedGraphic(t){null!=t&&this._sketchedGraphics.add(t),this._input=t,this._updateSketchedGraphic()}};function w(t){if(y(t)){const e=t.clone();return e.paths=[e.paths[0].slice(0,-1)],e}return t}t([d({nonNullable:!0})],k.prototype,"state",void 0),t([d({nonNullable:!0})],k.prototype,"tool",void 0),t([d()],k.prototype,"canStopCreating",null),t([d()],k.prototype,"_graphicsLayer",void 0),t([d()],k.prototype,"_sketchVM",void 0),t([d()],k.prototype,"_input",null),t([d()],k.prototype,"_geometry",null),t([d()],k.prototype,"_visibleAndEditable",null),t([d()],k.prototype,"_view",null),t([d()],k.prototype,"_shouldRemoveLastPoint",void 0),k=t([u("esri.widgets.ElevationProfile.ElevationProfileInteraction")],k);export{k as ElevationProfileInteraction,f as State};