UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 5.3 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as t}from"../../../../chunks/tslib.es6.js";import{acosClamped as i,clamp as s}from"../../../../core/mathUtils.js";import{createScreenPointArray as r}from"../../../../core/screenUtils.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as e}from"../../../../core/accessorSupport/decorators/subclass.js";import{fromRotation as a,rotate as n}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as h}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{copy as p}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as m}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{c,d as l,l as _,f as v,n as f,g as C,h as u,e as P,t as w}from"../../../../chunks/vec32.js";import{create as d}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{applyAll as E}from"../../camera/constraintUtils.js";import{ConstraintOptions as R}from"../../camera/constraintUtils/ConstraintOptions.js";import{ConstraintTypes as j}from"../../camera/constraintUtils/ConstraintTypes.js";import{InteractionType as g}from"../../camera/constraintUtils/InteractionType.js";import{TiltMode as T}from"../../camera/constraintUtils/TiltMode.js";import{getVoxelWasm as y}from"../../layers/VoxelWasm.js";import{TiltRange as M}from"../Constraints.js";import{InteractiveController as U}from"./InteractiveController.js";import{contentIntersectorOptions as x,normalizeCoordinate as O,rotatePivotDistanceModifier as b,rotatePivotMinDistanceModifier as D,navigationMode as A,rotateScreenPixelArea as N,NavigationMode as L}from"../utils/navigationUtils.js";var V;!function(t){t[t.CENTER=0]="CENTER",t[t.EYE=1]="EYE"}(V||(V={}));let H=class extends U{get _intersectionHelper(){return this.view.sceneIntersectionHelper}constructor(t){super(t),this.pivot=V.CENTER,this._rotScale=0,this._lastPoint=m(),this._tmpWorldUp=d(),this._tmpViewDir=d(),this._tmpRotCurPoint=m(),this._tmpTransf=h(),this._tmpAxis=d(),this._tmpPivotPoint=d(),this._pivotPos=d(),this._constraintOptions=new R(j.ALL,g.TUMBLE,0,this.startCamera)}initialize(){this._rotScale=this.pivot===V.CENTER?3:1.5}begin(t){if(this.running){switch(this.pivot){case V.EYE:c(this._pivotPos,this.startCamera.eye),this._constraintOptions.interactionType=g.LOOK_AROUND,this._constraintOptions.tiltMode=T.LOOK_AROUND,this._constraintOptions.selection=j.NONE;break;case V.CENTER:{const i=this._intersectionHelper.intersectRayFreePointFallback(this.startCamera.ray,this._pivotPos,0===this.view.map.ground.opacity?x:{});i||c(this._pivotPos,this.startCamera.center),this._constrainPivotPoint(t,i),this.startCamera.center=this._pivotPos,this._constraintOptions.interactionType=g.TUMBLE,this._constraintOptions.tiltMode=T.TUMBLE,this._constraintOptions.selection=j.ALL&~j.DISTANCE;break}}O(this.startCamera,t,this._lastPoint)}}_constrainPivotPoint(t,i){const s=this.startCamera,o=d();l(o,this._pivotPos,s.eye);const e=_(o),a=Math.abs(this.view.camera.position.z);this.view.renderCoordsHelper.worldUpAtPosition(s.eye,k);let n=Math.max(Math.min(b,1/Math.abs(v(k,s.viewForward)))*a,D);i&&(n=Math.min(e,n));const h=r(s.width/s.pixelRatio*.5,s.height/s.pixelRatio*.5),p=A(this.startCamera,h,this.view.renderCoordsHelper,this.view.viewingMode);let m=this.view._stage.renderView.getMinimalDepthForArea(y(this.view),s.fullWidth/s.pixelRatio*.5,s.fullHeight/s.pixelRatio*.5,s,2.5*N,N),P=this.view._stage.renderView.getMinimalDepthForArea(y(this.view),t[0],t[1],s,N);null==m&&null==P||(m=m??P??0,P=null==P||p===L.Horizontal?m:P,n=m>P?P:m,n=i?Math.min(n,e):n),f(o,o),c(this._pivotPos,C(this._tmpPivotPoint,s.eye,u(this._tmpPivotPoint,o,n)))}update(t){if(this.running){switch(this.pivot){case V.EYE:this.currentCamera.center=this._applyRotation(this.currentCamera,t,this.currentCamera.center,this._pivotPos);break;case V.CENTER:this.currentCamera.center=this._pivotPos,this.currentCamera.eye=this._applyRotation(this.currentCamera,t,this.currentCamera.eye,this._pivotPos)}E(this.view,this.currentCamera,this._constraintOptions),this.commitCamera()}}end(){this.running&&this.finishController()}_applyRotation(t,r,o,e){this.view.renderCoordsHelper.worldUpAtPosition(e,this._tmpWorldUp),O(t,r,this._tmpRotCurPoint);let h=(this._lastPoint[1]-this._tmpRotCurPoint[1])*this._rotScale,m=(this._tmpRotCurPoint[0]-this._lastPoint[0])*this._rotScale;l(this._tmpViewDir,o,e);const c=_(this._tmpViewDir),f=i(v(this._tmpViewDir,this._tmpWorldUp)/c);if(this.pivot===V.EYE){h*=-.5;const t=.5*Math.PI-f,i=.5*Math.PI*.99;h=t-Math.max(-i,Math.min(i,t+h))}return h=s(h+f,M.min,M.max)-f,P(this._tmpAxis,t.up,this._tmpViewDir),this.pivot===V.CENTER&&(m=-m),a(this._tmpTransf,m,this._tmpWorldUp),n(this._tmpTransf,this._tmpTransf,h,this._tmpAxis),w(this._tmpViewDir,this._tmpViewDir,this._tmpTransf),t.up=w(S,t.up,this._tmpTransf),C(S,e,this._tmpViewDir),p(this._lastPoint,this._tmpRotCurPoint),S}};t([o()],H.prototype,"pivot",void 0),H=t([e("esri.views.3d.state.controllers.RotateController")],H);const S=d(),k=d();export{V as PivotPoint,H as RotateController};