ElevationProfileInteraction.js 9.3 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. 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 o from"../../core/Handles.js";import{makeHandle as a}from"../../core/handleUtils.js";import{isSome as n,destroyMaybe as r,applySome as h,unwrapOr as c,isNone as l,abortMaybe as p}from"../../core/maybe.js";import{ignoreAbortErrors as d,throwIfAborted as _}from"../../core/promiseUtils.js";import{watch as u,syncAndInitial as m,when as g}from"../../core/reactiveUtils.js";import{property as v}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as y}from"../../core/accessorSupport/decorators/subclass.js";import S from"../../layers/GraphicsLayer.js";import I from"../../symbols/CIMSymbol.js";import f from"../../symbols/SimpleLineSymbol.js";import{isPolyline as b}from"./support/geometryUtils.js";import k from"../Sketch/SketchViewModel.js";var P,w;function R(t){return"2d"===t?new I({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 f({color:[0,0,0,0]})}!function(t){t.Ready="ready",t.Creating="creating",t.Reshaping="reshaping",t.ReshapingDisabled="rehsaping-disabled",t.Selecting="selecting",t.Selected="selected"}(P||(P={})),function(t){t.View="view",t.Main="main",t.Interaction="interaction"}(w||(w={}));let G=class extends i{constructor(t){super(t),this.state=P.Ready,this._handles=new o,this._pendingStartOptions=null,this._previousInputInfo=null,this._shouldRemoveLastPoint=!1,this._sketchedGraphics=new WeakSet,this._creationToolPromise=null,this._updateToolPromise=null,this._updateDisabled=!1}initialize(){this._handles.add(u((()=>({view:this.tool.viewModel.view,visible:this.tool.visible})),(({view:t,visible:e})=>{n(t)&&e?this._attach(t):this._detach()}),m),w.View)}destroy(){this._detach(),this._handles=r(this._handles)}get canStopCreating(){const t=this._geometry,e=this._shouldRemoveLastPoint?3:2;return b(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 h(this._input,(t=>t.geometry))}get _visibleAndEditable(){return this.tool.visible&&this.tool.editable}get _view(){return this.tool.viewModel.view}get test(){return{sketchVM:this._sketchVM,toolPromise:Promise.all([c(this._creationToolPromise,Promise.resolve()),c(this._updateToolPromise,Promise.resolve())])}}start(t={mode:"sketch"}){if(!this.tool.editable)return;const e=this._view;if(!l(e)&&e.ready)switch(this._pendingStartOptions=null,this._stopInteraction(),l(this._previousInputInfo)&&this._storePreviousInput(this._input),this._setSketchedGraphic(null),t.mode){case"sketch":this._set("state",P.Creating),this._startCreationInteraction();break;case"select":this._set("state",P.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",P.Ready),this._clearPreviousInput(),this._input=null,this._pendingStartOptions=null}isSketchedGraphic(t){return n(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 S({listMode:"hide",internal:!0,elevationInfo:e});const i=R(t.type);this._sketchVM=new k({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,updatePolylineSymbol:i,activeLineSymbol:i}),this._handles.add([g((()=>t.ready),(()=>h(this._pendingStartOptions,(t=>this.start(t)))),m),u((()=>[this._input,this._visibleAndEditable]),(()=>this._update()),m),u((()=>({map:t.map,graphicsLayer:this._graphicsLayer})),(({map:t,graphicsLayer:e})=>{n(t)&&n(e)&&t.add(e),this._update()}),m)],w.Main)}_detach(){this._handles.remove(w.Main),this._sketchVM=r(this._sketchVM),this._creationToolPromise=null,this._updateToolPromise=null;const t=h(this._view,(t=>t.map)),e=this._graphicsLayer;n(t)&&n(e)&&t.remove(e),this._graphicsLayer=r(this._graphicsLayer),this._shouldRemoveLastPoint=!1,this._set("state",P.Ready)}_startCreationInteraction(){this._stopInteractionAndUpdate();const t=this._view,i=this._sketchVM;if(l(t)||l(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)}})),o=()=>{s.remove();const t=this.canStopCreating,o=h(this._geometry,(t=>t.clone()));i.cancel(),this._creationToolPromise=null,!l(o)&&t?this._shouldRemoveLastPoint&&this._setSketchedGraphic(new e({geometry:M(o)})):this._input=null};this._handles.remove(w.Interaction),this._handles.add(a(o),w.Interaction),this._creationToolPromise=d(i.create("polyline"))}_startReshapeInteraction(){this._stopInteraction();const t=this._view,e=this._sketchVM;if(l(t)||l(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._handles.remove(w.Interaction),this._handles.add(a(s),w.Interaction),h(this._input,(t=>{t.visible=!0,this._updateToolPromise=d(e.update(t,{tool:"reshape"}))}))}_startSelectionInteraction(){this._stopInteraction();const t=this._view;if(l(t))return;const e=t.cursor,i=a((()=>t.cursor=e));t.cursor="crosshair",t.popup.close();let o=null;const r=a((()=>p(o))),h=t.on("immediate-click",(e=>{e.preventDefault(),e.stopPropagation(),p(o),o=s((async i=>{const{results:s}=await t.hitTest(e);_(i);const o=s.filter((t=>"graphic"===t.type&&null!=t.graphic)).map((t=>t.graphic)).find((t=>n(t.geometry)&&"polyline"===t.geometry.type));o&&(this._input=o,this._clearPreviousInput(),this._stopInteractionAndUpdate())}))})),c=t.on("key-down",(t=>{"Escape"===t.key&&this.cancel()}));this._handles.remove(w.Interaction),this._handles.add([h,c,r,i],w.Interaction),t.ready&&t.focus()}_stopInteraction(){this._handles.remove(w.Interaction)}_stopInteractionAndUpdate(){this._handles.has(w.Interaction)&&(this._updateDisabled=!0,this._stopInteraction(),this._updateDisabled=!1,this._triggerUpdate())}_triggerUpdate(){this._set("state",P.Ready),this._update()}_update(){if(this._updateDisabled)return;const t=this.state;if(t!==P.Selecting){if(this._visibleAndEditable){if(t===P.Creating||t===P.Reshaping&&this.isSketchedGraphic(this._input))return}else this.cancel();this._set("state",this._getNextState()),this._updateVisuals()}else this.stop()}_getNextState(){return l(this._input)?P.Ready:this.isSketchedGraphic(this._input)?this.state===P.Creating?P.Creating:this._visibleAndEditable?P.Reshaping:P.ReshapingDisabled:P.Selected}_updateVisuals(){switch(this.state){case P.Creating:break;case P.Reshaping:this._startReshapeInteraction();break;case P.ReshapingDisabled:{this._stopInteractionAndUpdate();const t=this._input;n(t)&&this.isSketchedGraphic(t)&&(t.visible=!1);break}case P.Ready:case P.Selected:this._stopInteractionAndUpdate();case P.Selecting:}this._updateSketchedGraphic()}_storePreviousInput(t){this._previousInputInfo={graphic:t}}_restorePreviousInput(){const t=this._previousInputInfo;l(t)||(this._clearPreviousInput(),this._input=t.graphic,this._triggerUpdate())}_clearPreviousInput(){this._previousInputInfo=null}_updateSketchedGraphic(){const t=this._graphicsLayer;if(l(t))return;const e=t.graphics,i=this._input;if(l(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){n(t)&&this._sketchedGraphics.add(t),this._input=t,this._updateSketchedGraphic()}};function M(t){if(b(t)){const e=t.clone();return e.paths=[e.paths[0].slice(0,-1)],e}return t}t([v({nonNullable:!0})],G.prototype,"state",void 0),t([v({nonNullable:!0})],G.prototype,"tool",void 0),t([v()],G.prototype,"canStopCreating",null),t([v()],G.prototype,"_graphicsLayer",void 0),t([v()],G.prototype,"_sketchVM",void 0),t([v()],G.prototype,"_input",null),t([v()],G.prototype,"_geometry",null),t([v()],G.prototype,"_visibleAndEditable",null),t([v()],G.prototype,"_view",null),t([v()],G.prototype,"_shouldRemoveLastPoint",void 0),G=t([y("esri.widgets.ElevationProfile.ElevationProfileInteraction")],G);export{G as ElevationProfileInteraction,P as State};