// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("exports ../../chunks/tslib.es6 ../../Graphic ../../core/Accessor ../../core/asyncUtils ../../core/handleUtils ../../core/has ../../core/maybe ../../core/promiseUtils ../../core/reactiveUtils ../../core/accessorSupport/decorators/property ../../core/Logger ../../core/RandomLCG ../../core/accessorSupport/decorators/subclass ../../layers/GraphicsLayer ../../symbols/CIMSymbol ../../symbols/SimpleLineSymbol ../../views/input/InputManager ./support/geometryUtils ../Sketch/SketchViewModel".split(" "), function(b,g,v,w,x,p,H,q,r,k,h,I,J,y,z,A,B,C,u,D){b.State=void 0;(function(a){a.Ready="ready";a.Creating="creating";a.Reshaping="reshaping";a.ReshapingDisabled="reshaping-disabled";a.Selecting="selecting";a.Selected="selected"})(b.State||(b.State={}));var f;(function(a){a.View="view";a.Main="main";a.Interaction="interaction"})(f||={});b.ElevationProfileInteraction=class extends w{constructor(a){super(a);this.state=b.State.Ready;this._previousInputInfo=this._pendingStartOptions=null;this._shouldRemoveLastPoint= !1;this._sketchedGraphics=new WeakSet;this._updateToolPromise=this._creationToolPromise=null;this._updateDisabled=!1}initialize(){this.addHandles(k.watch(()=>({view:this.tool.viewModel.view,visible:this.tool.visible}),({view:a,visible:c})=>{null!=a&&c?this._attach(a):this._detach()},k.syncAndInitial),f.View)}destroy(){this._detach()}get canStopCreating(){const a=this._geometry,c=this._shouldRemoveLastPoint?3:2;return u.isPolyline(a)&&0=c}get _input(){return this.tool.viewModel.input}set _input(a){this.tool.viewModel.input= a}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(a={mode:"sketch"}){if(this.tool.editable){var c=this._view;if(null!=c&&c.ready)switch(this._pendingStartOptions=null,this._stopInteraction(),null==this._previousInputInfo&&this._storePreviousInput(this._input),this._setSketchedGraphic(null),a.mode){case "sketch":this._set("state",b.State.Creating);this._startCreationInteraction(); break;case "select":this._set("state",b.State.Selecting),this._startSelectionInteraction()}else this._pendingStartOptions=a}}stop(){this._pendingStartOptions=null;this._stopInteractionAndUpdate();this._clearPreviousInput()}cancel(){this._pendingStartOptions=null;this._stopInteractionAndUpdate();this._restorePreviousInput()}clear(){this._stopInteractionAndUpdate();this._set("state",b.State.Ready);this._clearPreviousInput();this._pendingStartOptions=this._input=null}isSketchedGraphic(a){return null!= a&&this._sketchedGraphics.has(a)}_attach(a){this._detach();this._graphicsLayer=new z({listMode:"hide",internal:!0,elevationInfo:{mode:"3d"===a.type?"relative-to-ground":"on-the-ground",offset:null}});var c="2d"===a.type?new A({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 B({color:[0,0,0,0]});this._sketchVM=new D({layer:this._graphicsLayer,view:a,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:c,activeLineSymbol:c}); this.addHandles([k.when(()=>a.ready,()=>{const e=this._pendingStartOptions;e&&this.start(e)},k.syncAndInitial),k.watch(()=>[this._input,this._visibleAndEditable],()=>this._update(),k.syncAndInitial),k.watch(()=>({map:a.map,graphicsLayer:this._graphicsLayer}),({map:e,graphicsLayer:d})=>{null!=e&&null!=d&&e.add(d);this._update()},k.syncAndInitial)],f.Main)}_detach(){this.removeHandles(f.Main);this._sketchVM=q.destroyMaybe(this._sketchVM);this._updateToolPromise=this._creationToolPromise=null;const a= this._view?.map,c=this._graphicsLayer;null!=a&&null!=c&&a.remove(c);this._graphicsLayer=q.destroyMaybe(this._graphicsLayer);this._shouldRemoveLastPoint=!1;this._set("state",b.State.Ready)}_startCreationInteraction(){this._stopInteractionAndUpdate();const a=this._sketchVM;if(null!=this._view&&null!=a){this._shouldRemoveLastPoint=!1;var c=a.on("create",e=>{const d=e.graphic;switch(e.state){case "complete":this._shouldRemoveLastPoint=!1;this._setSketchedGraphic(d);this._stopInteractionAndUpdate();this._clearPreviousInput(); break;case "cancel":this.cancel();break;case "active":this._setSketchedGraphic(d);"cursor-update"===e.toolEventInfo?.type&&(this._shouldRemoveLastPoint=!0);break;case "start":this._setSketchedGraphic(d)}});this.removeHandles(f.Interaction);this.addHandles(p.makeHandle(()=>{c.remove();var e=this.canStopCreating,d=this._geometry?.clone();a.cancel();this._creationToolPromise=null;null!=d&&e?this._shouldRemoveLastPoint&&(e=this._setSketchedGraphic,u.isPolyline(d)&&(d=d.clone(),d.paths=[d.paths[0].slice(0, -1)]),e.call(this,new v({geometry:d}))):this._input=null}),f.Interaction);this._creationToolPromise=r.ignoreAbortErrors(a.create("polyline"))}}_startReshapeInteraction(){this._stopInteraction();const a=this._sketchVM;if(null!=this._view&&null!=a){var c=a.on("update",d=>{const n=d.graphics[0];switch(d.state){case "complete":this._setSketchedGraphic(n);this._stopInteractionAndUpdate();this._clearPreviousInput();break;case "active":this._setSketchedGraphic(n);break;case "start":this._setSketchedGraphic(n)}}); this.removeHandles(f.Interaction);this.addHandles(p.makeHandle(()=>{c.remove();a.cancel();this._updateToolPromise=null}),f.Interaction);var e=this._input;e&&(e.visible=!0,this._updateToolPromise=r.ignoreAbortErrors(a.update(e,{tool:"reshape"})))}}_startSelectionInteraction(){this._stopInteraction();const a=this._view;if(null!=a){var c=a.cursor,e=p.makeHandle(()=>a.cursor=c);a.cursor="crosshair";a.closePopup();var d=null,n=p.makeHandle(()=>q.abortMaybe(d)),F=a.on("immediate-click",m=>{m.async(async()=> {q.abortMaybe(d);d=x.createTask(async t=>{const {results:E}=await a.hitTest(m);r.throwIfAborted(t);if(t=E.filter(l=>"graphic"===l.type&&null!=l.graphic).map(l=>l.graphic).find(l=>null!=l.geometry&&"polyline"===l.geometry.type))m.preventDefault(),m.stopPropagation(),this._input=t,this._clearPreviousInput(),this._stopInteractionAndUpdate()});await d.promise})},C.ViewEventPriorities.TOOL),G=a.on("key-down",m=>{"Escape"===m.key&&this.cancel()});this.removeHandles(f.Interaction);this.addHandles([F,G,n, e],f.Interaction);a.ready&&a.focus()}}_stopInteraction(){this.removeHandles(f.Interaction)}_stopInteractionAndUpdate(){this.hasHandles(f.Interaction)&&(this._updateDisabled=!0,this._stopInteraction(),this._updateDisabled=!1,this._triggerUpdate())}_triggerUpdate(){this._set("state",b.State.Ready);this._update()}_update(){if(!this._updateDisabled){var a=this.state;if(a===b.State.Selecting)this.stop();else{if(this._visibleAndEditable){if(a===b.State.Creating||a===b.State.Reshaping&&this.isSketchedGraphic(this._input))return}else this.cancel(); this._set("state",this._getNextState());this._updateVisuals()}}}_getNextState(){return null==this._input?b.State.Ready:this.isSketchedGraphic(this._input)?this.state===b.State.Creating?b.State.Creating:this._visibleAndEditable?b.State.Reshaping:b.State.ReshapingDisabled:b.State.Selected}_updateVisuals(){switch(this.state){case b.State.Reshaping:this._startReshapeInteraction();break;case b.State.ReshapingDisabled:this._stopInteractionAndUpdate();const a=this._input;null!=a&&this.isSketchedGraphic(a)&& (a.visible=!1);break;case b.State.Ready:case b.State.Selected:this._stopInteractionAndUpdate()}this._updateSketchedGraphic()}_storePreviousInput(a){this._previousInputInfo={graphic:a}}_restorePreviousInput(){const a=this._previousInputInfo;null!=a&&(this._clearPreviousInput(),this._input=a.graphic,this._triggerUpdate())}_clearPreviousInput(){this._previousInputInfo=null}_updateSketchedGraphic(){var a=this._graphicsLayer;if(null!=a){a=a.graphics;var c=this._input;if(null!=c&&this.isSketchedGraphic(c))if(-1!== a.indexOf(c)){if(1!==a.length){const e=a.filter(d=>d!==c);a.removeMany(e)}}else a.removeAll(),a.add(c);else a.removeAll()}}_setSketchedGraphic(a){null!=a&&this._sketchedGraphics.add(a);this._input=a;this._updateSketchedGraphic()}};g.__decorate([h.property({nonNullable:!0})],b.ElevationProfileInteraction.prototype,"state",void 0);g.__decorate([h.property({nonNullable:!0})],b.ElevationProfileInteraction.prototype,"tool",void 0);g.__decorate([h.property()],b.ElevationProfileInteraction.prototype,"canStopCreating", null);g.__decorate([h.property()],b.ElevationProfileInteraction.prototype,"_graphicsLayer",void 0);g.__decorate([h.property()],b.ElevationProfileInteraction.prototype,"_sketchVM",void 0);g.__decorate([h.property()],b.ElevationProfileInteraction.prototype,"_input",null);g.__decorate([h.property()],b.ElevationProfileInteraction.prototype,"_geometry",null);g.__decorate([h.property()],b.ElevationProfileInteraction.prototype,"_visibleAndEditable",null);g.__decorate([h.property()],b.ElevationProfileInteraction.prototype, "_view",null);g.__decorate([h.property()],b.ElevationProfileInteraction.prototype,"_shouldRemoveLastPoint",void 0);b.ElevationProfileInteraction=g.__decorate([y.subclass("esri.widgets.ElevationProfile.ElevationProfileInteraction")],b.ElevationProfileInteraction);Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});