@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 10.2 kB
JavaScript
import{_ as t}from"../../../../../chunks/tslib.es6.js";import e from"../../../../../core/Evented.js";import{HandleOwnerMixin as i}from"../../../../../core/HandleOwner.js";import{makeHandle as a}from"../../../../../core/handleUtils.js";import{isSome as o,destroyMaybe as s,isNone as n}from"../../../../../core/maybe.js";import{scale as r,zeroMeters as l}from"../../../../../core/quantityUtils.js";import{watch as p,syncAndInitial as c}from"../../../../../core/reactiveUtils.js";import{property as h}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/accessorSupport/ensureType.js";import"../../../../../core/arrayUtils.js";import{subclass as m}from"../../../../../core/accessorSupport/decorators/subclass.js";import d from"../../../../../geometry/Point.js";import{getGraphicEffectiveElevationInfo as u}from"../../../../../support/elevationInfoUtils.js";import{ViewingMode as g}from"../../../../ViewingMode.js";import{Manipulator3D as v}from"../../Manipulator3D.js";import{placeAtGraphic as _}from"../../manipulatorUtils.js";import{SnappingVisualizer3D as M}from"../../SnappingVisualizer3D.js";import{canMoveZ as f}from"../manipulatorUtils.js";import{createVisualElements as y}from"../visualElementUtils.js";import{ALIGN_ARROWS_SCALE_THRESHOLD as S}from"../manipulations/config.js";import{MoveManipulation as R,ManipulationType as b}from"../manipulations/MoveManipulation.js";import{axisConstrainedDragSign as w}from"../manipulations/moveUtils.js";import{GraphicScaleRotateTransform as j}from"./GraphicScaleRotateTransform.js";import{ScaleRotateMeshAdapter as A}from"./ScaleRotateMeshAdapter.js";import{ScaleRotateObjectSymbol3DAdapter as T}from"./ScaleRotateObjectSymbol3DAdapter.js";import{createGraphicGeometryUndoRecord as x}from"./undoRecords.js";import{GraphicState as O}from"../../../layers/graphics/GraphicState.js";import{sceneSnappingAtProjectedLocation as E}from"../../../../interactive/dragEventPipeline.js";import{InteractiveToolBase as G}from"../../../../interactive/InteractiveToolBase.js";import{EditGeometryOperations as z}from"../../../../interactive/editGeometry/EditGeometryOperations.js";import D from"../../../../interactive/sketch/SketchTooltipOptions.js";import{SnappingContext as U}from"../../../../interactive/snapping/SnappingContext.js";import{createSnapDragEventPipelineStep as I}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{Tooltip as k}from"../../../../interactive/tooltip/Tooltip.js";import{TranslateGraphicZTooltipInfo as C,TranslateGraphicXYTooltipInfo as L,TranslateGraphicTooltipInfo as Z}from"../../../../interactive/tooltip/TranslateTooltipInfos.js";import{autoHorizontalDistanceByElevationModeBetweenPoints as V}from"../../../../support/automaticLengthMeasurementUtils.js";import{verticalSignedDistanceBetweenPoints as X}from"../../../../support/euclideanLengthMeasurementUtils.js";let H=class extends(i(e.EventedMixin(G))){constructor(t){super(t),this.enableZ=!0,this.enableRotation=!0,this.enableScaling=!0,this.tooltipOptions=new D,this.type="transform-3d",this._scaleRotate=null,this._tooltip=null}initialize(){const{graphic:t,view:e}=this;this.graphicState=new O({graphic:t}),this.addHandles(p((()=>this.tooltipOptions.enabled),(t=>{this._tooltip=t?new k({view:e}):s(this._tooltip)}),c)),this._moveManipulation=new R({tool:this,view:e,snapToScene:this.snapToScene,xyAvailable:!0,xyAxisAvailable:!0,zAvailable:this.enableZ&&f(t),radius:R.radiusForSymbol(t.symbol)}),this._moveManipulation.forEachManipulator((e=>this.handles.add(e.events.on("immediate-click",(e=>{this.emit("immediate-click",{...e,graphic:t}),e.stopPropagation()})))));const i=t=>e=>{this.handles.add(e.events.on("focus-changed",(({action:e})=>{const i=this._tooltip;n(i)||("focus"===e?this._updateMoveTooltip(t):i.clear())})))};this._moveManipulation.xyManipulation.forEachManipulator(i(b.XY)),this._moveManipulation.xyAxisManipulation.forEachManipulator(i(b.XY_AXIS)),this._moveManipulation.zManipulation.forEachManipulator(i(b.Z));const r=u(t);this._moveManipulation.elevationInfo=r;const l=t.geometry;if(this._moveManipulation.createGraphicDragPipeline(((i,a,s,n,p)=>{if(o(l)&&i===b.XY){const{snappingStep:i,cancelSnapping:a}=I({snappingContext:new U({elevationInfo:r,pointer:p,editGeometryOperations:z.fromGeometry(new d({spatialReference:l.spatialReference}),e.state.viewingMode),visualizer:new M,excludeFeature:t}),snappingManager:this.snappingManager,updatingHandles:this.updatingHandles,useZ:!1});n=n.next(a),s=s.next(E(this.view,r)).next(...i)}return{steps:s=s.next((t=>(this._updateMoveTooltip(i,t),t))),cancel:n}}),this.graphicState,(t=>{const{action:e,graphic:i,dxScreen:a,dyScreen:o}=t,s={graphic:i,dxScreen:a,dyScreen:o};switch(e){case"start":this.emit("graphic-translate-start",s),this.emit("record-undo",{record:this._createGeometryUndoRecord()});break;case"update":this.emit("graphic-translate",s);break;case"end":this.emit("graphic-translate-stop",s)}})),this._moveManipulation.angle=o(this._scaleRotate)?this._scaleRotate.angle:0,this._scaleRotateAdapter=this._createScaleRotateAdapter(),this.handles.add(p((()=>this._scaleRotateAdapter.angle),(()=>this._updateMoveAngle()))),this.enableScaling||this.enableRotation){const t=this.enableScaling&&this.enableRotation?null:this.enableScaling?"scale":"rotate";this._scaleRotate=new j({tool:this,mode:t,adapter:this._scaleRotateAdapter,tooltipOptions:this.tooltipOptions}),this.handles.add(this._scaleRotate.events.on("scale-changed",(()=>this._onScaleChanged())))}this.handles.add([y({view:this.view,graphic:this.graphic,forEachManipulator:t=>this._forEachManipulator(t),onManipulatorsChanged:()=>a()}),this.graphicState.on("changed",(()=>this._onGeometryChanged())),this._hideManipulatorsForGraphicState(),p((()=>e.scale),(()=>this._updateMoveAngle()))]),this.handles.add(this.view.trackGraphicState(this.graphicState)),this._onGeometryChanged(),this._updateMoveAngle(),this._forEachManipulator((t=>{t instanceof v&&this.handles.add(t.events.on("grab-changed",(()=>this._updateManipulatorsInteractive())))})),this.finishToolCreation()}destroy(){this._tooltip=s(this._tooltip),this._moveManipulation.destroy(),this._scaleRotate=s(this._scaleRotate),this._scaleRotateAdapter=s(this._scaleRotateAdapter),this._set("view",null),this._set("graphic",null)}_updateManipulatorsInteractive(){n(this._scaleRotate)||(this._scaleRotate.interactive=!this._moveManipulation.grabbing,this._moveManipulation.interactive=!this._scaleRotate.grabbing)}_createScaleRotateAdapter(){return o(this.graphic.geometry)&&"mesh"===this.graphic.geometry.type?new A({graphic:this.graphic,geometry:this.graphic.geometry,viewingMode:this.view.state.viewingMode}):new T({graphic:this.graphic,sizeFilter:t=>this._enforceNonZeroSize(t),findLayerView:()=>this.view.allLayerViews.find((t=>t.layer===this.graphic.layer)),sizeAxis:o(this.tooltipOptions.visualVariables)&&o(this.tooltipOptions.visualVariables.size)?this.tooltipOptions.visualVariables.size.axis:null})}_forEachManipulator(t){this._moveManipulation.forEachManipulator(t),o(this._scaleRotate)&&this._scaleRotate.forEachManipulator(t)}_hideManipulatorsForGraphicState(){return p((()=>this.graphicState.displaying),(t=>{this._forEachManipulator((e=>e.available=t)),this._moveManipulation.zManipulation.available=t&&this.enableZ&&f(this.graphic)}))}_createGeometryUndoRecord(){return x(this.graphic)}set snapToScene(t){this._moveManipulation&&(this._moveManipulation.snapToScene=t),this._set("snapToScene",t)}get updating(){return this.updatingHandles.updating}set location(t){this._moveManipulation.location=t,o(this._scaleRotate)&&(this._scaleRotate.location=t)}set elevationAlignedLocation(t){this._moveManipulation.elevationAlignedLocation=t,o(this._scaleRotate)&&(this._scaleRotate.elevationAlignedLocation=t)}reset(){}onHide(){o(this._scaleRotate)&&this._scaleRotate.cancelActiveAnimation()}_onScaleChanged(){if(n(this._scaleRotate))return;const t=this._scaleRotate.getScale();this._moveManipulation.displayScale=t}_updateMoveAngle(){this.view.state.viewingMode===g.Local||this.view.scale<S?this._moveManipulation.angle=this._scaleRotateAdapter.angle:this._moveManipulation.angle=0}_onGeometryChanged(){_(this.view,this,this.graphic)}_enforceNonZeroSize(t){return t||this.view.state.camera.computeRenderPixelSizeAt(this._moveManipulation.renderLocation)}_updateMoveTooltip(t,e){const{tooltipOptions:i,_tooltip:a}=this;if(n(a))return;a.clear();const o=this.graphicState.isDraped?"on-the-ground":"absolute-height";switch(t){case b.XY:a.info=new Z({tooltipOptions:i}),this._updateMoveTooltipDistance(a.info,e,((t,e)=>V(t,e,o)));break;case b.XY_AXIS:a.info=new L({tooltipOptions:i}),this._updateMoveTooltipDistance(a.info,e,((t,i)=>{const a=V(t,i,o);return r(a,w(e))}));break;case b.Z:a.info=new C({tooltipOptions:i}),this._updateMoveTooltipDistance(a.info,e,X)}}_updateMoveTooltipDistance(t,e,i){if(o(e)&&"end"!==e.action){const{mapStart:a,mapEnd:s}=e,n=i(a,s);t.distance=o(n)?n:l}}get test(){return{discManipulator:this._moveManipulation.xyManipulation.test.discManipulator,zManipulator:this._moveManipulation.zManipulation.test.manipulator,ringManipulator:o(this._scaleRotate)?this._scaleRotate.test.ringManipulator:null,arrowManipulators:this._moveManipulation.xyAxisManipulation.test.arrowManipulators,setRingIndicatorDelayMs:t=>o(this._scaleRotate)?this._scaleRotate.test.setRingIndicatorDelayMs(t):null,scaleRotateAdapter:this._scaleRotateAdapter,scaleRotateTransform:this._scaleRotate,tooltip:this._tooltip}}};t([h({constructOnly:!0,nonNullable:!0})],H.prototype,"view",void 0),t([h({constructOnly:!0,nonNullable:!0})],H.prototype,"graphic",void 0),t([h({constructOnly:!0,nonNullable:!0})],H.prototype,"enableZ",void 0),t([h()],H.prototype,"enableRotation",void 0),t([h()],H.prototype,"enableScaling",void 0),t([h({constructOnly:!0,type:D})],H.prototype,"tooltipOptions",void 0),t([h()],H.prototype,"graphicState",void 0),t([h({value:!1})],H.prototype,"snapToScene",null),t([h({constructOnly:!0})],H.prototype,"snappingManager",void 0),t([h({readOnly:!0})],H.prototype,"type",void 0),t([h({readOnly:!0})],H.prototype,"updating",null),H=t([m("esri.views.3d.interactive.editingTools.graphicTransform3D.GraphicTransformTool")],H);export{H as GraphicTransformTool};