@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.74 kB
JavaScript
/*
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 r from"../../../../Camera.js";import{deg2rad as i,rad2deg as s,clamp as e}from"../../../../core/mathUtils.js";import{destroyMaybe as o}from"../../../../core/maybe.js";import{property as a}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as n}from"../../../../core/accessorSupport/decorators/subclass.js";import{g as h,h as l,c as m,j as c}from"../../../../chunks/vec32.js";import{create as v}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{pixelDistanceToInteractionFactor as _,applyAll as u}from"../../camera/constraintUtils.js";import{ConstraintOptions as p}from"../../camera/constraintUtils/ConstraintOptions.js";import{ConstraintTypes as f}from"../../camera/constraintUtils/ConstraintTypes.js";import{InteractionType as d}from"../../camera/constraintUtils/InteractionType.js";import{InteractiveController as w}from"./InteractiveController.js";import{screenPixelArea as y}from"../utils/navigationUtils.js";import g from"../../../ui/Component.js";import{FovOverlay as S}from"../../../../widgets/FovOverlay.js";let j=class extends w{constructor(t){super(t),this.onStop=null,this._timeOutId=void 0,this._onReset=()=>{this._startSize=this._lastDrag=null,this._setFov(C),this.updateTimeout()},this._center=v(),this._viewForward=v(),this._constraints=new p(f.ALL,d.ZOOM)}begin(t){D(t)?this._showOverlay().fov=t.fov:(this._lastDrag=t[1],this._startSize=null,this._ensureStartSize(this.view.state.camera))}updateTimeout(){clearTimeout(this._timeOutId),this._timeOutId=setTimeout(this.onStop,1500)}update(t){if(null==this._lastDrag)return this._lastDrag=t[1],this._startSize=null,void this._ensureStartSize(this.view.state.camera);const r=-(this._lastDrag-t[1])/2;this._lastDrag=t[1],this.step(r)}step(t){if(!this.running)return void(this._startSize=this._lastDrag=null);const r=this.view.state,o=this.currentCamera.copyFrom(r.camera),a=s(o.fov)+t,n=i(e(a,O,F));n!==o.fov?this._setFov(n):this._showOverlay().fov=o.fov}finish(){this.running&&(this._startSize=this._lastDrag=null,this.finishController())}destroy(){this.hideOverlay()}onControllerEnd(t){super.onControllerEnd(t),this._startSize=this._lastDrag=null,this.hideOverlay()}_showOverlay(){return this._overlay||(this._overlay=new g({id:"esri.FovOverlay",node:new S({onReset:this._onReset})}),this.view.ui.add(this._overlay)),this._overlay.widget}hideOverlay(){this._overlay&&(this.view.ui.remove(this._overlay),this._overlay=o(this._overlay))}_setFov(t){const r=this.view.state,i=this.currentCamera.copyFrom(r.camera),s=this._ensureStartSize(i)/Math.tan(t/2),e=h(z,this._center,l(z,this._viewForward,-s));i.eye=e,i.fov=t,this._constraints.interactionStartCamera=r.camera,this._constraints.interactionFactor=_(this.currentCamera.height-r.camera.height),u(this.view,this.currentCamera,this._constraints),this.begin(i),this.commitCamera()}_ensureStartSize(t){if(null==this._startSize){m(this._viewForward,t.viewForward);const r=this.view._stage.renderView.getMinimalDepthForArea(null,t.fullWidth/t.pixelRatio*.5,t.fullHeight/t.pixelRatio*.5,t,y),i=c(t.eye,this.view.pointsOfInterest.centerOnContent.renderLocation),s=r??i;h(this._center,t.eye,l(z,this._viewForward,s)),this._startSize=s*Math.tan(t.fov/2)}return this._startSize}};t([a()],j.prototype,"onStop",void 0),j=t([n("esri.views.3d.state.controllers.FovController")],j);const C=i((new r).fov),O=10,F=150,z=v();function D(t){return!Array.isArray(t)}export{j as FovController};