@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 10.7 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import{cyclicalPI as i}from"../../../../core/Cyclical.js";import{deg2rad as e}from"../../../../core/mathUtils.js";import{createScreenPointArray as n,screenPointObjectToArray as s}from"../../../../core/screenUtils.js";import{subclass as o}from"../../../../core/accessorSupport/decorators.js";import{copy as a,distance as r}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{copy as m,negate as h,length as c,subtract as _,normalize as p,add as u,scale as l,dot as d}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as g}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as P}from"../../../../geometry/ellipsoidUtils.js";import{wrapAxisAngle as v}from"../../../../geometry/support/axisAngle.js";import{create as C,fromPositionAndNormal as w,getNormal as b}from"../../../../geometry/support/plane.js";import{Sphere as M}from"../../../../geometry/support/sphere.js";import{pixelDistanceToInteractionFactor as S,applyAll as f}from"../../camera/constraintUtils.js";import{ConstraintOptions as j}from"../../camera/constraintUtils/ConstraintOptions.js";import{ExponentialFalloff as E}from"../../input/util.js";import{InteractiveController as y}from"./InteractiveController.js";import{PanPlanarMomentumController as x}from"./momentum/PanPlanarMomentumController.js";import{PanSphericalMomentumController as A}from"./momentum/PanSphericalMomentumController.js";import{RotationMomentumController as O}from"./momentum/RotationMomentumController.js";import{ZoomPlanarMomentumController as R}from"./momentum/ZoomPlanarMomentumController.js";import{ZoomSphericalMomentumController as z}from"./momentum/ZoomSphericalMomentumController.js";import{pickPointAndInitSphere as k,excludeTerrain as F,inferNavigationMode as H,sphereOrPlanePointFromScreenPoint as D,maxPanDistanceModifier as T,minPinchAndPanCameraHeight as U,pivotSearchAreaSize as G,intersectPlaneFromScreenPointAtEye as I,applyZoomOnSphere as Z,shouldPreserveHeading as V,applyPanSphericalPreserveHeading as q,applyPanSphericalDirectRotation as B,normalizeRotationDelta as J,applyRotation as K,applyPanPlanar as L,applyZoomToPoint as N}from"../utils/navigationUtils.js";import Q from"../../webgl/RenderCamera.js";import{PanPlanarMomentumEstimator as W}from"../../../navigation/PanPlanarMomentumEstimator.js";import{PanSphericalMomentumEstimator as X}from"../../../navigation/PanSphericalMomentumEstimator.js";import{RotationMomentumEstimator as Y}from"../../../navigation/RotationMomentumEstimator.js";import{ZoomMomentumEstimator as $}from"../../../navigation/ZoomMomentumEstimator.js";let tt=class extends y{constructor(){super(...arguments),this._smoothRotation=new E(.05),this._rotationAxis=g(),this._beginAngle=0,this._beginHeading=0,this._panningPlane=C(),this._beginRadius=0,this._smoothScaling=new E(.05),this._zoomCenterScreen=n(),this._zoomMomentumEstimator=new $,this._rotationMomentumEstimator=new Y,this._panSphericalMomentumEstimator=new X,this._panPlanarMomentumEstimator=new W,this._adjustedSphere=new M,this._tmp3d=g(),this._tmpScreenPointArray=n(),this._beginScreenPoint=n(),this._beginScenePoint=g(),this._screenPickPoint=n(),this._scenePickPoint=g(),this._navigationMode=1,this._sphere=new M,this._pointerCount=0,this._tmpInteractionDirection=g(),this._beginCamera=new Q,this._constraintOptions=new j(15,0,0,this._beginCamera)}get _intersectionHelper(){return this.view.sceneIntersectionHelper}begin(t){if(!this.running)return;this._zoomMomentumEstimator.enabled=this._rotationMomentumEstimator.enabled=this._panPlanarMomentumEstimator.enabled=this._panSphericalMomentumEstimator.enabled=this.view.navigation.momentumEnabled,this._beginHeading=-i.normalize(e(this.view.camera.heading)),this._beginRadius=t.radius,this._beginAngle=t.angle,this._pointerCount=t.pointers.size,this._smoothRotation.reset(),s(t.center,this._screenPickPoint),a(this._beginScreenPoint,this._screenPickPoint);const n=k(this._intersectionHelper,this.startCamera,this._screenPickPoint,P(this.view.spatialReference).radius,1,this.view.basemapTerrain.invisible?F:{});null!=n.scenePickPoint&&(this._scenePickPoint=n.scenePickPoint,this._sphere=n.sphere,m(this._beginScenePoint,this._scenePickPoint),this._navigationMode=H(this.startCamera,this._screenPickPoint,this.view.renderCoordsHelper,this.view.viewingMode),0===this._navigationMode&&this._preparePlanarPanMode(t,n.hasGeometryIntersection),this._beginCamera.copyFrom(this.startCamera))}update(t){if(!this.running)return;this.currentCamera.copyFrom(this.startCamera);const i=t.pointers.size>1;1===this._navigationMode?(i&&this._zoomSpherical(t),this._panningSpherical(t),i&&this._rotateSpherical(t)):(i&&this._zoomPlanar(t),this._panningPlanar(t),i&&this._rotatePlanar(t)),this.commitCamera()}end(t){t.pointers.size===this._pointerCount&&this.update(t),this.finishController();const i=this.view.animationsEnabled&&this._zoomMomentumEstimator.evaluateMomentum();if(i)return 1===this._navigationMode?new z({view:this.view,momentum:i,screenCenter:this._zoomCenterScreen,sceneCenter:this._beginScenePoint,radius:this._sphere.radius}):new R({view:this.view,momentum:i,zoomCenter:this._beginScenePoint});const e=this.view.animationsEnabled&&this._rotationMomentumEstimator.evaluateMomentum();if(e)return new O({view:this.view,momentum:e,center:this._sphere.center,axis:this._rotationAxis});if(1===this._navigationMode){const t=this.view.animationsEnabled&&this._panSphericalMomentumEstimator.evaluateMomentum();if(t)return new A({view:this.view,momentum:t})}else{const t=this.view.animationsEnabled&&this._panPlanarMomentumEstimator.evaluateMomentum();if(t)return new x({view:this.view,momentum:t})}return null}_preparePlanarPanMode(t,i){const e=h(this._tmp3d,this.startCamera.viewForward);w(this._scenePickPoint,e,this._panningPlane);const o=n(this._screenPickPoint[0],0),a=g(),r=c(this.startCamera.eye);this._adjustedSphere.radius=r<this._sphere.radius?r-100:this._sphere.radius,D(this._adjustedSphere,this.startCamera,o,a);const P=g(),v=g(),C=g();_(P,this._scenePickPoint,this.currentCamera.eye);const M=c(P);p(P,P);const S=T*Math.max(Math.abs(this.view.camera.position.z),U),f=this.view.stage.renderView.getMinimalDepthForArea(null,this._screenPickPoint[0],this._screenPickPoint[1],this.view.state.camera,G);let j=null!=f?f:S;i&&(j=Math.min(j,M)),m(C,u(v,this.currentCamera.eye,l(v,P,j))),this._panningPlane[3]=-d(b(this._panningPlane),C),this.startCamera.center=u(v,this.startCamera.eye,l(v,this.startCamera.viewForward,j));const E=s(t.center,this._tmpScreenPointArray);I(this._panningPlane,this.startCamera,E,this._beginScenePoint)}_zoomSpherical(t){const i=this._beginRadius/t.radius,e=.001875*Math.min(Math.max(t.radius,40),120);this._smoothScaling.gain=e,this._smoothScaling.update(i),Z(this._sphere,this.currentCamera,this._smoothScaling.value),s(t.center,this._zoomCenterScreen),this._zoomMomentumEstimator.add(this._smoothScaling.value,.001*t.timestamp),this._constraintOptions.interactionType=1,this._constraintOptions.interactionFactor=S(t.radius-this._beginRadius),f(this.view,this.currentCamera,this._constraintOptions)}_panningSpherical(t){const i=s(t.center,this._tmpScreenPointArray);D(this._sphere,this.currentCamera,i,this._tmp3d),V(this._beginScenePoint,d(this.currentCamera.up,this._beginScenePoint),this._sphere.radius,this._beginHeading,this.view.camera.tilt,this.startCamera.aboveGround)?(q(this._sphere,this.currentCamera,this._beginScenePoint,this._tmp3d,this._beginHeading,this.view.camera.tilt,!1),this._panSphericalMomentumEstimator.addMomentumPreserveHeading(i,this._tmp3d,.001*t.timestamp,this.startCamera,this._sphere,this._beginHeading,this.view.camera.tilt)):(B(this._sphere,this.currentCamera,this._beginScenePoint,this._tmp3d,this.view.camera.tilt,!1),this._panSphericalMomentumEstimator.addMomentumDirectRotation(i,this._tmp3d,.001*t.timestamp,this.startCamera,this._sphere.radius,this.view.camera.tilt)),this._constraintOptions.interactionType=4,this._constraintOptions.interactionFactor=S(r(this._screenPickPoint,i)),f(this.view,this.currentCamera,this._constraintOptions)}_rotateSpherical(t){p(this._rotationAxis,this._scenePickPoint),this.currentCamera.aboveGround||h(this._rotationAxis,this._rotationAxis);const i=this._smoothRotation.value,e=i+J(t.angle-i),n=.00125*Math.min(Math.max(t.radius,40),120);this._smoothRotation.gain=n,this._smoothRotation.update(e);const s=this._smoothRotation.value-this._beginAngle;this._rotationMomentumEstimator.add(s,.001*t.timestamp),K(this.currentCamera,this._sphere.center,v(this._rotationAxis,s)),this._constraintOptions.interactionType=2,this._constraintOptions.interactionFactor=S(t.radius*e),f(this.view,this.currentCamera,this._constraintOptions)}_panningPlanar(t){const i=s(t.center,this._tmpScreenPointArray);I(this._panningPlane,this.currentCamera,i,this._tmp3d)&&(L(this.currentCamera,this._beginScenePoint,this._tmp3d),this._panPlanarMomentumEstimator.add(i,this._tmp3d,.001*t.timestamp),this._constraintOptions.interactionType=4,this._constraintOptions.interactionFactor=S(r(this._beginScreenPoint,i)),this._constraintOptions.interactionDirection=this.view.renderCoordsHelper.worldUpAtPosition(this.currentCamera.eye,this._tmpInteractionDirection),f(this.view,this.currentCamera,this._constraintOptions),this._constraintOptions.interactionDirection=null)}_zoomPlanar(t){const i=this._beginRadius/t.radius,e=.001875*Math.min(Math.max(t.radius,40),120);this._smoothScaling.gain=e,this._smoothScaling.update(i),this._zoomMomentumEstimator.add(this._smoothScaling.value,.001*t.timestamp),N(this.currentCamera,this._beginScenePoint,this._smoothScaling.value,this.view.state.constraints.minimumPoiDistance),this._constraintOptions.interactionType=1,this._constraintOptions.interactionFactor=S(t.radius-this._beginRadius),f(this.view,this.currentCamera,this._constraintOptions)}_rotatePlanar(t){m(this._rotationAxis,this._beginScenePoint),this.currentCamera.aboveGround||h(this._rotationAxis,this._rotationAxis);const i=this._smoothRotation.value;let e=t.angle-i;e=J(e);const n=i+e,s=.00125*Math.min(Math.max(t.radius,40),120);this._smoothRotation.gain=s,this._smoothRotation.update(n);const o=this._smoothRotation.value-this._beginAngle;this._rotationMomentumEstimator.add(o,.001*t.timestamp),K(this.currentCamera,this._sphere.center,v(this._rotationAxis,o)),this._constraintOptions.interactionType=2,this._constraintOptions.interactionFactor=S(t.radius*o),f(this.view,this.currentCamera,this._constraintOptions)}};tt=t([o("esri.views.3d.state.controllers.PinchAndPanControllerGlobal")],tt);export{tt as PinchAndPanControllerGlobal};