diff --git a/src/Controls/GlobeControls.js b/src/Controls/GlobeControls.js index 1f689da103..9f3cd301ad 100644 --- a/src/Controls/GlobeControls.js +++ b/src/Controls/GlobeControls.js @@ -4,6 +4,7 @@ import Coordinates from 'Core/Geographic/Coordinates'; import { ellipsoidSizes } from 'Core/Math/Ellipsoid'; import CameraUtils from 'Utils/CameraUtils'; import StateControl from 'Controls/StateControl'; +import { VIEW_EVENTS } from 'Core/View'; // private members const EPS = 0.000001; @@ -38,6 +39,7 @@ let dollyScale; // Globe move const moveAroundGlobe = new THREE.Quaternion(); const cameraTarget = new THREE.Object3D(); +const coordCameraTarget = new Coordinates('EPSG:4978'); cameraTarget.matrixWorldInverse = new THREE.Matrix4(); const xyz = new Coordinates('EPSG:4978', 0, 0, 0); @@ -309,6 +311,8 @@ class GlobeControls extends THREE.EventDispatcher { } positionObject(xyz, cameraTarget); this.lookAtCoordinate(placement, false); + + coordCameraTarget.crs = this.view.referenceCrs; } get dollyInScale() { @@ -539,6 +543,14 @@ class GlobeControls extends THREE.EventDispatcher { this.player.setCallback(() => { this.update(this.states.ORBIT); }); this.player.playLater(durationDampingOrbital, 2); } + + this.view.dispatchEvent({ + type: VIEW_EVENTS.CAMERA_MOVED, + coord: coordCameraTarget.setFromVector3(cameraTarget.position), + range: spherical.radius, + heading: -THREE.MathUtils.radToDeg(spherical.theta), + tilt: 90 - THREE.MathUtils.radToDeg(spherical.phi), + }); } onStateChange(event) { diff --git a/src/Core/View.js b/src/Core/View.js index 2e4e295edd..2b5cf345e3 100644 --- a/src/Core/View.js +++ b/src/Core/View.js @@ -29,6 +29,7 @@ export const VIEW_EVENTS = { LAYER_ADDED: 'layer-added', INITIALIZED: 'initialized', COLOR_LAYERS_ORDER_CHANGED, + CAMERA_MOVED: 'camera-moved', }; /** diff --git a/src/Utils/CameraUtils.js b/src/Utils/CameraUtils.js index a4d0ed7125..fa41799095 100644 --- a/src/Utils/CameraUtils.js +++ b/src/Utils/CameraUtils.js @@ -5,6 +5,7 @@ import { MAIN_LOOP_EVENTS } from 'Core/MainLoop'; import Coordinates from 'Core/Geographic/Coordinates'; import Ellipsoid from 'Core/Math/Ellipsoid'; import OBB from 'Renderer/OBB'; +import { VIEW_EVENTS } from 'Core/View'; THREE.Object3D.DefaultUp.set(0, 0, 1); const targetPosition = new THREE.Vector3(); @@ -100,6 +101,13 @@ class CameraRig extends THREE.Object3D { } else { this.camera.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale); } + view.dispatchEvent({ + type: VIEW_EVENTS.CAMERA_MOVED, + coord: this.coord, + range: this.range, + heading: this.heading, + tilt: this.tilt, + }); } setProxy(view, camera) { diff --git a/test/unit/CameraUtils.js b/test/unit/CameraUtils.js index daf68bdef5..99adaeee3c 100644 --- a/test/unit/CameraUtils.js +++ b/test/unit/CameraUtils.js @@ -51,6 +51,7 @@ describe('Camera utils unit test', function () { view.addFrameRequester = () => {}; view.removeFrameRequester = () => {}; view.notifyChange = () => { camera.updateMatrixWorld(true); }; + view.dispatchEvent = () => {}; const range = 25000000; const coord = new Coordinates('EPSG:4326', 2.35, 48.85, 0);