UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 7.83 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as t}from"tslib";import{EventEmitter as e}from"../../../../../core/Evented.js";import{makeHandle as i}from"../../../../../core/handleUtils.js";import"../../../../../core/has.js";import{watch as o,initial as a}from"../../../../../core/reactiveUtils.js";import{property as n,subclass as s}from"../../../../../core/accessorSupport/decorators.js";import{containsXY as r}from"../../../../../geometry/support/aaBoundingRect.js";import{sm4d as l}from"../../../../../geometry/support/vectorStacks.js";import{calculateBoundedPlaneTranslateRotate as p,resizeNormal as h,resizeOutlineOnly as c}from"../../../analysis/Slice/sliceToolUtils.js";import{Manipulator3D as d}from"../../Manipulator3D.js";import{manipulatedObjectGeometry as u}from"../manipulatedObjectUtils.js";import{canMoveZOperations as m}from"../manipulatorUtils.js";import{createVisualElements as b}from"../visualElementUtils.js";import{ExtentMove as v}from"./extentTransform/ExtentMove.js";import{ExtentRotate as _}from"./extentTransform/ExtentRotate.js";import{ExtentScale as g}from"./extentTransform/ExtentScale.js";import{TransformBounds as f}from"./extentTransform/extentUtils.js";import{PreserveAspectRatio as y}from"./extentTransform/PreserveAspectRatio.js";import{SnapRotation as j}from"./extentTransform/SnapRotation.js";import{OutlineVisualElement as M}from"../../visualElements/OutlineVisualElement.js";import{InteractiveToolBase as R}from"../../../../interactive/InteractiveToolBase.js";import x from"../../../../interactive/sketch/SketchOptions.js";import{makeTooltip as E}from"../../../../interactive/tooltip/tooltipCommonUtils.js";let O=class extends R{get updating(){return!!this.object.updating}constructor(t){super(t),this.events=new e,this.enableZ=!0,this.enableScaling=!0,this.enableRotation=!0,this.sketchOptions=new x,this._preserveAspectRatio=new y,this._snapRotation=new j,this.grabbing=!1,this.inputState=null,this._attachmentOrigin=null,this.type="transform-3d",this._outlineVisualElement=null}initialize(){const{view:t,object:e}=this,n=this._bounds=new f(this,()=>this._updateManipulators());this._extentMove=new v(this,n,this.automaticLengthMeasurementUtils),this._extentScale=new g(this,n,()=>this._preserveAspectRatio.createDragEventPipelineStep()),this._extentRotate=new _(this,n,()=>this._snapRotation.createDragEventPipelineStep()),this.addHandles([o(()=>this.enableZ,()=>this._updateManipulatorAvailability(this._extentMove.moveZManipulator,0)),o(()=>this.enableScaling,()=>this._extentScale.forEachManipulator(t=>this._updateManipulatorAvailability(t,2))),o(()=>this.enableRotation,()=>this._updateManipulatorAvailability(this._extentRotate.rotateManipulator,3))]),this._updateManipulators(),this._updateAllManipulatorAvailability();const s=b({view:t,object:e,forEachManipulator:t=>this._forEachManipulator(t),onManipulatorsChanged:()=>i()});if(null!=s){const{visualElement:t}=s;t instanceof M&&(this._outlineVisualElement=t,this.addHandles(t.events.on("attachment-origin-changed",()=>this._bounds.updateDisplayBounds()))),this.addHandles(s)}this.addHandles([e.on("committed",()=>this._onGeometryChanged()),o(()=>this.object.visible,()=>this._updateAllManipulatorAvailability()),o(()=>this.object.isDraped,()=>this._graphicDrapedChanged(),a),o(()=>t.pointsOfInterest?.centerOnSurfaceFrequent.location,()=>n.updateDisplayBounds())]);const r=t=>{this.addHandles(t.events.on("grab-changed",()=>{this.grabbing=t.grabbing,this._updateAllManipulatorAvailability()}))};this._forEachManipulator(r);const l=(t,i)=>{this.addHandles(t.events.on("immediate-click",t=>{1===i&&this.events.emit("immediate-click",{...t,object:e}),t.stopPropagation()}))};this._forEachManipulator(l),this._initializeTooltip(),this.finishToolCreation()}destroy(){this._extentMove.destroy(),this._extentScale.destroy(),this._extentRotate.destroy(),this.tooltip.destroy(),this._set("view",null),this._set("object",null)}_initializeTooltip(){const{view:t}=this;this.tooltip=E(()=>({view:t,options:this.sketchOptions.tooltips}));const e=()=>{this.tooltip.info=this._getUpdatedTooltipInfo()};this.addHandles([o(()=>this.sketchOptions.tooltips.effectiveEnabled,e),o(()=>this.preserveAspectRatio,e)]),this._forEachManipulator(t=>{this.addHandles([t.events.on(["focus-changed","grab-changed"],e),t.events.on("drag",t=>{"cancel"===t.action?this.tooltip.clear():e()})])})}_getUpdatedTooltipInfo(){return this.sketchOptions.tooltips.effectiveEnabled?this._extentMove.getUpdatedTooltipInfo()??this._extentScale.getUpdatedTooltipInfo()??this._extentRotate.getUpdatedTooltipInfo():null}_onGeometryChanged(){this._bounds.updateDisplayBounds()}_graphicDrapedChanged(){this.removeHandles(S),this._bounds.updateDisplayBounds(),this.object.isDraped&&this.addHandles(this.view.elevationProvider.on("elevation-change",t=>{null!=this._attachmentOrigin&&r(t.extent,this._attachmentOrigin.x,this._attachmentOrigin.y)&&this._bounds.updateDisplayBounds()}),S)}_updateManipulators(){if(!this.visible)return;const t=this._bounds.displayBounds,e=p(t,l.get());this._extentMove.updateManipulators(e,t),this._extentScale.updateManipulators(e,t),this._extentRotate.updateManipulators(e,t)}_updateAllManipulatorAvailability(){this._forEachManipulator((t,e)=>this._updateManipulatorAvailability(t,e))}_updateManipulatorAvailability(t,e){const i=this.grabbing&&!t.grabbing;if(t.interactive=!i,t instanceof d){const o=this.object.visible,a=this.enableZ&&m(this.object.operations,this.object.elevationInfo);switch(e){case 3:t.available=o&&this.enableRotation;break;case 2:t.available=o&&(this.enableScaling||this.enableRotation||a),t.interactive=!i&&this.enableScaling,t.state=this.enableScaling?h:c;break;case 0:t.available=o&&a;break;default:t.available=o}}}_forEachManipulator(t){this._extentMove.forEachManipulator(t),this._extentScale.forEachManipulator(t),this._extentRotate.forEachManipulator(t)}get preserveAspectRatio(){return this._preserveAspectRatio.enabled}set preserveAspectRatio(t){this._preserveAspectRatio.enabled=t,this._set("preserveAspectRatio",t)}get snapRotation(){return this._snapRotation.enabled}set snapRotation(t){this._snapRotation.enabled=t,this._set("snapRotation",t)}get attachmentOrigin(){const t=this.object.isDraped?null:this._outlineVisualElement?.attachmentOrigin;return this._attachmentOrigin=t??this.object.origin??u(this.object)?.extent?.center,this._attachmentOrigin}reset(){}cancelDrag(){if(this.canUndo){const t=this.object.operations?.undo();t&&this._bounds.updateMapBoundsFromOperationInverse(t)}this.inputState=null}get canUndo(){return!!this.object.operations?.canUndo}undo(){if(null!=this.inputState)this.view.activeTool=null;else if(this.canUndo){const t=this.object.operations?.undo();t&&this._bounds.updateMapBoundsFromOperationInverse(t)}}get canRedo(){return!!this.object.operations?.canRedo}redo(){if(this.canRedo){const t=this.object.operations?.redo();t&&this._bounds.updateMapBoundsFromOperation(t)}}get test(){}};t([n()],O.prototype,"updating",null),t([n({constructOnly:!0,nonNullable:!0})],O.prototype,"view",void 0),t([n({constructOnly:!0})],O.prototype,"automaticLengthMeasurementUtils",void 0),t([n({constructOnly:!0,nonNullable:!0})],O.prototype,"object",void 0),t([n()],O.prototype,"enableZ",void 0),t([n()],O.prototype,"enableScaling",void 0),t([n()],O.prototype,"enableRotation",void 0),t([n({constructOnly:!0,type:x})],O.prototype,"sketchOptions",void 0),t([n()],O.prototype,"preserveAspectRatio",null),t([n()],O.prototype,"snapRotation",null),t([n()],O.prototype,"grabbing",void 0),t([n()],O.prototype,"inputState",void 0),t([n({readOnly:!0})],O.prototype,"type",void 0),t([n()],O.prototype,"tooltip",void 0),O=t([s("esri.views.3d.interactive.editingTools.transform.ExtentTransformTool")],O);const S="draped-elevation-changes";export{O as ExtentTransformTool};