@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 9.1 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import{isSome as e}from"../../../../../core/arrayUtils.js";import{EventEmitter as 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,subclass as r}from"../../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as l}from"../../../../../core/support/UpdatingHandles.js";import p from"../../../../../geometry/Point.js";import{Manipulator3D as c}from"../../Manipulator3D.js";import{placeAtObject as h}from"../../manipulatorUtils.js";import{SnappingVisualizer3D as m}from"../../SnappingVisualizer3D.js";import{manipulatedObjectGeometry as d}from"../manipulatedObjectUtils.js";import{canMoveZOperations as u}from"../manipulatorUtils.js";import{meshTransformFastUpdateHandles as v}from"../meshFastUpdateUtils.js";import{connectTooltipToManipulatedObject as _}from"../tooltipUtils3D.js";import{createVisualElements as f}from"../visualElementUtils.js";import{alignArrowsScaleThreshold as g}from"../manipulations/config.js";import{MoveManipulation as b}from"../manipulations/MoveManipulation.js";import{ScaleRotateMeshAdapter as j}from"./ScaleRotateMeshAdapter.js";import{ScaleRotateObjectSymbol3DAdapter as y}from"./ScaleRotateObjectSymbol3DAdapter.js";import{ScaleRotateTransform as S}from"./ScaleRotateTransform.js";import{sceneSnappingAtProjectedLocation as M}from"../../../../interactive/dragEventPipeline.js";import{InteractiveToolBase as R}from"../../../../interactive/InteractiveToolBase.js";import{EditGeometryOperations as w}from"../../../../interactive/editGeometry/EditGeometryOperations.js";import T from"../../../../interactive/sketch/SketchOptions.js";import{SnappingContext as O}from"../../../../interactive/snapping/SnappingContext.js";import{createSnapDragEventPipelineStep as A}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{makeTooltip as x,enterInputModeIfAvailable as I}from"../../../../interactive/tooltip/tooltipCommonUtils.js";import{TransformMeshTooltipInfo as U}from"../../../../interactive/tooltip/infos/TransformMeshTooltipInfo.js";import{TransformPointTooltipInfo as k}from"../../../../interactive/tooltip/infos/TransformPointTooltipInfo.js";let E=class extends R{constructor(t){super(t),this.events=new o,this.enableZ=!0,this.enableRotation=!0,this.enableScaling=!0,this.sketchOptions=new T,this.type="transform-3d",this._updatingHandles=new l,this._scaleRotate=null}initialize(){const{events:t,object:o,view:a}=this;this.tooltip=x(()=>({view:a,options:this.sketchOptions.tooltips})),this._moveManipulation=new b({tool:this,view:a,snapToScene:this.snapToScene,xyAvailable:!0,xyAxisAvailable:!0,zAvailable:this.enableZ&&u(o.operations,o.elevationInfo),radius:b.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(v(o)),this._moveManipulation.createManipulatedObjectDragPipeline((t,e,i,n,r)=>{if(0===t){const{snappingStep:t,cancelSnapping:e}=A({snappingContext:new O({elevationInfo:s,pointer:r,editGeometryOperations:w.fromGeometry(new p({spatialReference:o.operations?.data.spatialReference}),a.state.viewingMode),visualizer:new m,excludeFeature:o.graphic}),snappingManager:this.snappingManager,updatingHandles:this._updatingHandles,useZ:!1});n=n.next(e),i=i.next(M(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 S({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 c&&this.addHandles(t.events.on("grab-changed",()=>this._updateManipulatorsInteractive()))});const r=a?.type,{sketchOptions:l}=this;this._meshTooltipInfo=new U({viewType:r,sketchOptions:l}),this._pointTooltipInfo=new k({viewType:r,sketchOptions:l});const h={object:o,dxScreen:0,dyScreen:0},d={onBeforeUpdate:()=>this.endDrag(),onMoveStart:()=>{this._emitRecordUndo(),t.emit("translate-start",{...h})},onMove:()=>t.emit("translate",{...h}),onMoveStop:()=>t.emit("translate-stop",{...h}),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:d,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&&!I(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=d(this.object);return"mesh"===t?.type?new j({object:this.object,viewingMode:this.view.state.viewingMode}):new y({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&&u(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"===d(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=2===t.state.viewingMode||t.scale<g;this._moveManipulation.angle=e?this._scaleRotateAdapter.angle:0}_onGeometryChanged(){h(this,this.object)}_enforceNonZeroSize(t){return t||this.view.state.camera.computeRenderPixelSizeAt(this._moveManipulation.renderLocation)}get test(){}};t([s({constructOnly:!0,nonNullable:!0})],E.prototype,"view",void 0),t([s({constructOnly:!0,nonNullable:!0})],E.prototype,"object",void 0),t([s({constructOnly:!0,nonNullable:!0})],E.prototype,"enableZ",void 0),t([s()],E.prototype,"enableRotation",void 0),t([s()],E.prototype,"enableScaling",void 0),t([s({constructOnly:!0,type:T})],E.prototype,"sketchOptions",void 0),t([s({value:!1})],E.prototype,"snapToScene",null),t([s({constructOnly:!0})],E.prototype,"snappingManager",void 0),t([s({readOnly:!0})],E.prototype,"type",void 0),t([s({readOnly:!0})],E.prototype,"updating",null),t([s()],E.prototype,"activeTooltipInfo",null),E=t([r("esri.views.3d.interactive.editingTools.transform.TransformTool3D")],E);export{E as TransformTool3D};