@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 9.43 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{isSome as e}from"../../../../../core/arrayUtils.js";import o from"../../../../../core/Evented.js";import{makeHandle as i}from"../../../../../core/handleUtils.js";import"../../../../../core/has.js";import{destroyMaybe as a}from"../../../../../core/maybe.js";import{watch as n}from"../../../../../core/reactiveUtils.js";import{property as s}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/Logger.js";import{subclass as r}from"../../../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as l}from"../../../../../core/support/UpdatingHandles.js";import p from"../../../../../geometry/Point.js";import{ViewingMode as c}from"../../../../ViewingMode.js";import{Manipulator3D as h}from"../../Manipulator3D.js";import{placeAtObject as m}from"../../manipulatorUtils.js";import{SnappingVisualizer3D as d}from"../../SnappingVisualizer3D.js";import{manipulatedObjectGeometry as u}from"../manipulatedObjectUtils.js";import{canMoveZOperations as v}from"../manipulatorUtils.js";import{meshTransformFastUpdateHandles as g}from"../meshFastUpdateUtils.js";import{connectTooltipToManipulatedObject as _}from"../tooltipUtils3D.js";import{createVisualElements as f}from"../visualElementUtils.js";import{alignArrowsScaleThreshold as b}from"../manipulations/config.js";import{MoveManipulation as j,ManipulationType as y}from"../manipulations/MoveManipulation.js";import{ScaleRotateMeshAdapter as S}from"./ScaleRotateMeshAdapter.js";import{ScaleRotateObjectSymbol3DAdapter as M}from"./ScaleRotateObjectSymbol3DAdapter.js";import{ScaleRotateTransform as R}from"./ScaleRotateTransform.js";import{sceneSnappingAtProjectedLocation as w}from"../../../../interactive/dragEventPipeline.js";import{InteractiveToolBase as T}from"../../../../interactive/InteractiveToolBase.js";import{EditGeometryOperations as O}from"../../../../interactive/editGeometry/EditGeometryOperations.js";import A from"../../../../interactive/sketch/SketchOptions.js";import{SnappingContext as x}from"../../../../interactive/snapping/SnappingContext.js";import{createSnapDragEventPipelineStep as I}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{makeTooltip as k,enterInputModeIfAvailable as U}from"../../../../interactive/tooltip/tooltipCommonUtils.js";import{TransformMeshTooltipInfo as E}from"../../../../interactive/tooltip/infos/TransformMeshTooltipInfo.js";import{TransformPointTooltipInfo as H}from"../../../../interactive/tooltip/infos/TransformPointTooltipInfo.js";let z=class extends T{constructor(t){super(t),this.events=new o,this.enableZ=!0,this.enableRotation=!0,this.enableScaling=!0,this.sketchOptions=new A,this.type="transform-3d",this._updatingHandles=new l,this._scaleRotate=null}initialize(){const{events:t,object:o,view:a}=this;this.tooltip=k((()=>({view:a,options:this.sketchOptions.tooltips}))),this._moveManipulation=new j({tool:this,view:a,snapToScene:this.snapToScene,xyAvailable:!0,xyAxisAvailable:!0,zAvailable:this.enableZ&&v(o.operations,o.elevationInfo),radius:j.radiusForSymbol(o.graphic?.symbol)}),this._moveManipulation.forEachManipulator((e=>this.addHandles(e.events.on("immediate-click",(e=>{t.emit("immediate-click",{...e,object:this.object}),e.stopPropagation()})))));const s=o.elevationInfo;if(this._moveManipulation.elevationInfo=s,this.addHandles(g(o)),this._moveManipulation.createManipulatedObjectDragPipeline(((t,e,i,n,r)=>{if(t===y.XY){const{snappingStep:t,cancelSnapping:e}=I({snappingContext:new x({elevationInfo:s,pointer:r,editGeometryOperations:O.fromGeometry(new p({spatialReference:o.operations?.data.spatialReference}),a.state.viewingMode),visualizer:new d,excludeFeature:o.graphic}),snappingManager:this.snappingManager,updatingHandles:this._updatingHandles,useZ:!1});n=n.next(e),i=i.next(w(this.view,s)).next(...t)}return{steps:i,cancel:n}}),o,(e=>{const{action:o,object:i,dxScreen:a,dyScreen:n}=e,s={object:i,dxScreen:a,dyScreen:n};switch(o){case"start":this._emitRecordUndo(),t.emit("translate-start",s);break;case"update":t.emit("translate",s);break;case"end":t.emit("translate-stop",s)}})),this._moveManipulation.angle=null!=this._scaleRotate?this._scaleRotate.angle:0,this._scaleRotateAdapter=this._createScaleRotateAdapter(),this.addHandles(n((()=>this._scaleRotateAdapter.angle),(()=>this._updateMoveAngle()))),this.enableScaling||this.enableRotation){const t=this.enableScaling&&this.enableRotation?null:this.enableScaling?"scale":"rotate";this._scaleRotate=new R({tool:this,mode:t,adapter:this._scaleRotateAdapter,sketchOptions:this.sketchOptions}),this.addHandles(this._scaleRotate.events.on("scale-changed",(()=>this._onScaleChanged())))}this.addHandles([f({view:this.view,object:o,forEachManipulator:t=>this._forEachManipulator(t),onManipulatorsChanged:()=>i()}),o.on("committed",(()=>this._onGeometryChanged())),this._hideManipulatorsForObjectState(),n((()=>a.scale),(()=>this._updateMoveAngle()))].filter(e)),this._onGeometryChanged(),this._updateMoveAngle(),this._forEachManipulator((t=>{t instanceof h&&this.addHandles(t.events.on("grab-changed",(()=>this._updateManipulatorsInteractive())))}));const r=a?.type,{sketchOptions:l}=this;this._meshTooltipInfo=new E({viewType:r,sketchOptions:l}),this._pointTooltipInfo=new H({viewType:r,sketchOptions:l});const c={object:o,dxScreen:0,dyScreen:0},m={onBeforeUpdate:()=>this.endDrag(),onMoveStart:()=>{this._emitRecordUndo(),t.emit("translate-start",{...c})},onMove:()=>t.emit("translate",{...c}),onMoveStop:()=>t.emit("translate-stop",{...c}),onRotateStart:e=>{this._emitRecordUndo(),t.emit("rotate-start",{object:o,angle:e})},onRotate:e=>t.emit("rotate",{object:o,angle:e}),onRotateStop:e=>t.emit("rotate-stop",{object:o,angle:e}),onScaleStart:(e,i)=>{this._emitRecordUndo(),t.emit("scale-start",{object:o,xScale:e,yScale:i})},onScale:(e,i)=>t.emit("scale",{object:o,xScale:e,yScale:i}),onScaleStop:(e,i)=>t.emit("scale-stop",{object:o,xScale:e,yScale:i})};this.addHandles(_(this.tooltip,this.object,(()=>({sketchOptions:this.sketchOptions,activeTooltipInfo:this.activeTooltipInfo,callbacks:m,scaleRotateTransform:this._scaleRotate})))),this.finishToolCreation()}destroy(){this.tooltip.destroy(),this._moveManipulation.destroy(),this._scaleRotate=a(this._scaleRotate),this._scaleRotateAdapter=a(this._scaleRotateAdapter),this._updatingHandles.destroy(),this._set("view",null),this._set("object",null)}onInputEvent(t){if(!this.destroyed&&!U(t,this.tooltip))return super.onInputEvent(t)}_updateManipulatorsInteractive(){null!=this._scaleRotate&&(this._scaleRotate.interactive=!this._moveManipulation.grabbing,this._moveManipulation.interactive=!this._scaleRotate.grabbing)}_createScaleRotateAdapter(){const t=u(this.object);return"mesh"===t?.type?new S({object:this.object,viewingMode:this.view.state.viewingMode}):new M({graphic:this.object.graphic,sizeFilter:t=>this._enforceNonZeroSize(t),findLayerView:()=>this.view.allLayerViews.find((t=>t.layer===this.object.graphic?.layer)),sizeAxis:this.sketchOptions?.tooltips?.visualVariables?.size?.axis??null})}_forEachManipulator(t){this._moveManipulation?.forEachManipulator(t),this._scaleRotate?.forEachManipulator(t)}_hideManipulatorsForObjectState(){return n((()=>this.object.visible),(t=>{this._forEachManipulator((e=>e.available=t)),this._moveManipulation.zManipulation.available=t&&this.enableZ&&v(this.object.operations,this.object.elevationInfo)}))}_emitRecordUndo(){this.events.emit("record-undo",{updates:[this.object.createUndoRecord()]})}set snapToScene(t){this._moveManipulation&&(this._moveManipulation.snapToScene=t),this._set("snapToScene",t)}get updating(){return this._updatingHandles.updating||!!this._scaleRotate?.updating}get activeTooltipInfo(){return"mesh"===u(this.object)?.type?this._meshTooltipInfo:this._pointTooltipInfo}set location(t){this._moveManipulation.location=t,this._scaleRotate&&(this._scaleRotate.location=t)}set elevationAlignedLocation(t){this._moveManipulation.elevationAlignedLocation=t,this._scaleRotate&&(this._scaleRotate.elevationAlignedLocation=t)}reset(){}onHide(){this._scaleRotate?.cancelActiveAnimation()}_onScaleChanged(){null!=this._scaleRotate&&(this._moveManipulation.displayScale=this._scaleRotate.getScale())}_updateMoveAngle(){const{view:t}=this,e=t.state.viewingMode===c.Local||t.scale<b;this._moveManipulation.angle=e?this._scaleRotateAdapter.angle:0}_onGeometryChanged(){m(this,this.object)}_enforceNonZeroSize(t){return t||this.view.state.camera.computeRenderPixelSizeAt(this._moveManipulation.renderLocation)}get test(){}};t([s({constructOnly:!0,nonNullable:!0})],z.prototype,"view",void 0),t([s({constructOnly:!0,nonNullable:!0})],z.prototype,"object",void 0),t([s({constructOnly:!0,nonNullable:!0})],z.prototype,"enableZ",void 0),t([s()],z.prototype,"enableRotation",void 0),t([s()],z.prototype,"enableScaling",void 0),t([s({constructOnly:!0,type:A})],z.prototype,"sketchOptions",void 0),t([s({value:!1})],z.prototype,"snapToScene",null),t([s({constructOnly:!0})],z.prototype,"snappingManager",void 0),t([s({readOnly:!0})],z.prototype,"type",void 0),t([s({readOnly:!0})],z.prototype,"updating",null),t([s()],z.prototype,"activeTooltipInfo",null),z=t([r("esri.views.3d.interactive.editingTools.transform.TransformTool3D")],z);export{z as TransformTool3D};