12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/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 s from"../../core/Handles.js";import{makeHandle as o}from"../../core/handleUtils.js";import{isSome as a,destroyMaybe as n,applySome as r,unwrapOr as h,isNone as c,abortMaybe as l}from"../../core/maybe.js";import{ignoreAbortErrors as p,createTask 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/has.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{isDOMContainer as b}from"../../views/DOMContainer.js";import{isPolyline as k}from"./support/geometryUtils.js";import P from"../Sketch/SketchViewModel.js";var w,R;function M(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"}(w||(w={})),function(t){t.View="view",t.Main="main",t.Interaction="interaction"}(R||(R={}));let G=class extends i{constructor(t){super(t),this.state=w.Ready,this._handles=new s,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})=>{a(t)&&e?this._attach(t):this._detach()}),m),R.View)}destroy(){this._detach(),this._handles=n(this._handles)}get canStopCreating(){const t=this._geometry,e=this._shouldRemoveLastPoint?3:2;return k(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 r(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([h(this._creationToolPromise,Promise.resolve()),h(this._updateToolPromise,Promise.resolve())])}}start(t={mode:"sketch"}){if(!this.tool.editable)return;const e=this._view;if(!c(e)&&e.ready)switch(this._pendingStartOptions=null,this._stopInteraction(),c(this._previousInputInfo)&&this._storePreviousInput(this._input),this._setSketchedGraphic(null),t.mode){case"sketch":this._set("state",w.Creating),this._startCreationInteraction();break;case"select":this._set("state",w.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",w.Ready),this._clearPreviousInput(),this._input=null,this._pendingStartOptions=null}isSketchedGraphic(t){return a(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=M(t.type);this._sketchVM=new P({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),(()=>r(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})=>{a(t)&&a(e)&&t.add(e),this._update()}),m)],R.Main)}_detach(){this._handles.remove(R.Main),this._sketchVM=n(this._sketchVM),this._creationToolPromise=null,this._updateToolPromise=null;const t=r(this._view,(t=>t.map)),e=this._graphicsLayer;a(t)&&a(e)&&t.remove(e),this._graphicsLayer=n(this._graphicsLayer),this._shouldRemoveLastPoint=!1,this._set("state",w.Ready)}_startCreationInteraction(){this._stopInteractionAndUpdate();const t=this._view,i=this._sketchVM;if(c(t)||c(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)}})),a=()=>{s.remove();const t=this.canStopCreating,o=r(this._geometry,(t=>t.clone()));i.cancel(),this._creationToolPromise=null,!c(o)&&t?this._shouldRemoveLastPoint&&this._setSketchedGraphic(new e({geometry:L(o)})):this._input=null};this._handles.remove(R.Interaction),this._handles.add(o(a),R.Interaction),this._creationToolPromise=p(i.create("polyline"))}_startReshapeInteraction(){this._stopInteraction();const t=this._view,e=this._sketchVM;if(c(t)||c(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(R.Interaction),this._handles.add(o(s),R.Interaction),r(this._input,(t=>{t.visible=!0,this._updateToolPromise=p(e.update(t,{tool:"reshape"}))}))}_startSelectionInteraction(){this._stopInteraction();const t=this._view;if(c(t))return;const e=t.cursor,i=o((()=>t.cursor=e));t.cursor="crosshair",t.popup.close();let s=null;const n=o((()=>l(s))),r=t.on("immediate-click",(e=>{e.preventDefault(),e.stopPropagation(),l(s),s=d((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=>a(t.geometry)&&"polyline"===t.geometry.type));o&&(this._input=o,this._clearPreviousInput(),this._stopInteractionAndUpdate())}))})),h=t.on("key-down",(t=>{"Escape"===t.key&&this.cancel()}));this._handles.remove(R.Interaction),this._handles.add([r,h,n,i],R.Interaction),t.ready&&b(t)&&t.focus()}_stopInteraction(){this._handles.remove(R.Interaction)}_stopInteractionAndUpdate(){this._handles.has(R.Interaction)&&(this._updateDisabled=!0,this._stopInteraction(),this._updateDisabled=!1,this._triggerUpdate())}_triggerUpdate(){this._set("state",w.Ready),this._update()}_update(){if(this._updateDisabled)return;const t=this.state;if(t!==w.Selecting){if(this._visibleAndEditable){if(t===w.Creating||t===w.Reshaping&&this.isSketchedGraphic(this._input))return}else this.cancel();this._set("state",this._getNextState()),this._updateVisuals()}else this.stop()}_getNextState(){return c(this._input)?w.Ready:this.isSketchedGraphic(this._input)?this.state===w.Creating?w.Creating:this._visibleAndEditable?w.Reshaping:w.ReshapingDisabled:w.Selected}_updateVisuals(){switch(this.state){case w.Creating:break;case w.Reshaping:this._startReshapeInteraction();break;case w.ReshapingDisabled:{this._stopInteractionAndUpdate();const t=this._input;a(t)&&this.isSketchedGraphic(t)&&(t.visible=!1);break}case w.Ready:case w.Selected:this._stopInteractionAndUpdate();case w.Selecting:}this._updateSketchedGraphic()}_storePreviousInput(t){this._previousInputInfo={graphic:t}}_restorePreviousInput(){const t=this._previousInputInfo;c(t)||(this._clearPreviousInput(),this._input=t.graphic,this._triggerUpdate())}_clearPreviousInput(){this._previousInputInfo=null}_updateSketchedGraphic(){const t=this._graphicsLayer;if(c(t))return;const e=t.graphics,i=this._input;if(c(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){a(t)&&this._sketchedGraphics.add(t),this._input=t,this._updateSketchedGraphic()}};function L(t){if(k(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,w as State};
|