@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.88 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import{prefersReducedMotion as t}from"../../../core/a11yUtils.js";import r from"../../../core/Accessor.js";import{EventEmitter as o}from"../../../core/Evented.js";import{destroyMaybe as a}from"../../../core/maybe.js";import{when as i}from"../../../core/reactiveUtils.js";import{property as n,subclass as s}from"../../../core/accessorSupport/decorators.js";import{afterDispatch as l}from"../../../core/accessorSupport/watch.js";import{fromValues as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as c}from"../../../geometry/ellipsoidUtils.js";import m from"../../ViewAnimation.js";import{viewingModeFromString as h}from"../../ViewingMode.js";import{Constraints as d}from"./Constraints.js";import{HUDOccludedFragmentOpacity as u}from"./HUDOccludedFragmentOpacity.js";import{AnimationController as g}from"./controllers/AnimationController.js";import y from"../webgl/RenderCamera.js";import{DepthRange as C}from"../webgl-engine/lib/DepthRange.js";import{maximumHighlights as f}from"../../support/HighlightDefaults.js";import{PropertiesPool as w}from"../../support/PropertiesPool.js";let v=class extends r{constructor(e){super(e),this._propertiesPool=new w({camera:()=>new y},this),this._lastSeenCameraProjectionValues=new y,this.mode=0,this._cssCamera=new y,this._camera=new y,this.rasterPixelRatio=1,this.contentPixelRatio=1,this.constraints=new d({state:this}),this.events=new o,this.fading=!1,this._cameraChanged=!1,this._updateQueue=new Array,this._processingUpdates=!1}reset(){this.cameraController=null,this._propertiesPool.destroy(),this._propertiesPool=new w({camera:()=>new y},this)}destroy(){this.cameraController=null,this._propertiesPool=a(this._propertiesPool)}createInitialCamera(){if(1===this.viewingMode){const e=c(this.spatialReference).radius;this.camera=new y({eye:p(4*e,0,0),center:p(e,0,0),up:p(0,0,1)})}else this.camera=new y({eye:p(0,0,100),center:p(0,0,0),up:p(0,1,0)})}get animation(){return this.cameraController instanceof g&&null!=this.cameraController.viewAnimation?this.cameraController.viewAnimation:null}get cssCamera(){const e=this._cssCamera.copyFrom(this.camera),{height:t,width:r,pixelRatio:o}=this.camera;return e.pixelRatio=1,e.height=Math.round(t/o),e.width=Math.round(r/o),e}get camera(){return this._camera}set camera(e){e!==O&&O.copyFrom(e),O.computeUp(this.viewingMode),this.events.emit("before-camera-change",{camera:O});const t=this._camera;if(j(this._lastSeenCameraProjectionValues,O)&&(this._lastSeenCameraProjectionValues.copyFrom(O),this.events.emit("camera-projection-changed",this._lastSeenCameraProjectionValues)),!t.equals(O)&&(this._camera=this._propertiesPool.get("camera").copyFrom(O),this._cameraChanged=!t.almostEquals(O),this._cameraChanged)){const e=l(()=>{this._cameraChanged=!1,e.remove()})}}get pixelRatio(){return this.camera.pixelRatio}get alignPixelEnabled(){return this.pixelRatio===this.rasterPixelRatio&&2===this.mode}get updating(){return 2!==this.mode}get contentCamera(){return this._contentCamera??this.camera}set contentCamera(e){if(null==e)return void(this._contentCamera=null);const t=e.clone();this.events.emit("before-camera-change",{camera:t,sceneDepthRange:C.Infinite}),this._contentCamera=t}get fixedContentCamera(){return null!=this._contentCamera}get isGlobal(){return 1===this.viewingMode}get isLocal(){return 2===this.viewingMode}get viewingMode(){return h(this.view.viewingMode)}get spatialReference(){return this.view.spatialReference}ensureOccludedFragmentOpacity(){return this.occludedFragmentOpacity??=new u({requestRender:()=>this.view.stage?.renderView.requestRender(2)}),this.occludedFragmentOpacity}get highlights(){const e=this.view.highlights.items.slice(0,f);for(let t=0;t<e.length;){const r=e[t],o=e.findIndex(e=>e.name===r.name);o>=0&&t>o?e.splice(t,1):++t}return e}get highlightOrderMap(){return new Map(this.highlights.map(({name:e},t)=>[e,t]))}get animationsEnabled(){return this.view.animationsEnabled&&!t()}get navigating(){return!!this.cameraController?.isInteractive}get stationary(){return!this._cameraChanged&&!this.navigating}get cameraController(){return this._get("cameraController")}set cameraController(e){this.stopActiveCameraController()?(this.removeHandles(x),this.cameraController?.destroy(),e&&(this.addHandles(i(()=>4===e.state||3===e.state,()=>{this.updateCamera(t=>e.onControllerEnd(t)),this.cameraController===e&&(this._set("cameraController",null),e.destroy())},{sync:!0,once:!0}),x),e.onControllerStart(this.camera)),this._set("cameraController",e)):e&&(e.state=1)}switchCameraController(e){this.cameraController=e}stopActiveCameraController(){return!this.cameraController||this.cameraController.stopController()}updateCamera(e){this._updateQueue.push(e),this._processUpdateQueue()}_processUpdateQueue(){if(0===this._updateQueue.length||this._processingUpdates)return;this._processingUpdates=!0;const e=this._updateQueue.shift();O.copyFrom(this.camera),e(O),this.camera=O,this._processingUpdates=!1,this._processUpdateQueue()}static cleanupViewstate(){O=new y}};e([n({constructOnly:!0})],v.prototype,"view",void 0),e([n()],v.prototype,"mode",void 0),e([n({readOnly:!0,type:m})],v.prototype,"animation",null),e([n({type:y})],v.prototype,"cssCamera",null),e([n()],v.prototype,"_cssCamera",void 0),e([n({type:y})],v.prototype,"camera",null),e([n()],v.prototype,"_camera",void 0),e([n({readOnly:!0})],v.prototype,"pixelRatio",null),e([n()],v.prototype,"rasterPixelRatio",void 0),e([n()],v.prototype,"contentPixelRatio",void 0),e([n({readOnly:!0})],v.prototype,"alignPixelEnabled",null),e([n({readOnly:!0})],v.prototype,"updating",null),e([n({})],v.prototype,"_contentCamera",void 0),e([n({type:y})],v.prototype,"contentCamera",null),e([n({readOnly:!0})],v.prototype,"fixedContentCamera",null),e([n({readOnly:!0})],v.prototype,"events",void 0),e([n({readOnly:!0})],v.prototype,"isGlobal",null),e([n({readOnly:!0})],v.prototype,"isLocal",null),e([n({readOnly:!0})],v.prototype,"viewingMode",null),e([n()],v.prototype,"occludedFragmentOpacity",void 0),e([n({readOnly:!0})],v.prototype,"highlights",null),e([n({readOnly:!0})],v.prototype,"highlightOrderMap",null),e([n({readOnly:!0})],v.prototype,"navigating",null),e([n()],v.prototype,"fading",void 0),e([n({readOnly:!0})],v.prototype,"stationary",null),e([n()],v.prototype,"_cameraChanged",void 0),e([n()],v.prototype,"cameraController",null),v=e([s("esri.views.3d.state.ViewState")],v);const _=v;function j(e,t){return e.fov!==t.fov||(e.fullViewport[0]!==t.fullViewport[0]||e.fullViewport[1]!==t.fullViewport[1]||e.fullViewport[2]!==t.fullViewport[2]||e.fullViewport[3]!==t.fullViewport[3]||(e.padding[0]!==t.padding[0]||e.padding[1]!==t.padding[1]||e.padding[2]!==t.padding[2]||e.padding[3]!==t.padding[3]))}let O=new y;const x="ViewStateHandles";export{_ as default};