Skip to content

Commit

Permalink
fix(debug): update coordinates event on mouse move
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermerie authored and gchoqueux committed May 27, 2021
1 parent d9fda75 commit 9b62770
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions utils/debug/Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CameraHelper, Color, Vector3 } from 'three';
import Coordinates from 'Core/Geographic/Coordinates';
import { MAIN_LOOP_EVENTS } from 'Core/MainLoop';
import OBB from 'Renderer/OBB';
import * as THREE from 'three';
import ThreeStatsChart from './charts/ThreeStatsChart';
import { backgroundChartDiv, color_blue } from './charts/ChartConfig';
import OBBHelper from './OBBHelper';
Expand Down Expand Up @@ -99,18 +100,23 @@ function Debug(view, datDebugTool, chartDivContainer) {
let eventFolder;
const controls = view.controls;
initialPosition.crs = view.referenceCrs;
const cursorWorldPosition = new THREE.Vector3();

const getCenter = (controls && controls.getCameraTargetPosition) ? controls.getCameraTargetPosition : () => view.camera.camera3D.position;
const cameraTargetListener = () => {
initialPosition.setFromVector3(getCenter()).as('EPSG:4326', geoPosition);
state.latitude = `${geoPosition.y.toFixed(6)}`;
state.longitude = `${geoPosition.x.toFixed(6)}`;
const cameraTargetListener = (event) => {
if (view.getPickingPositionFromDepth(view.eventToViewCoords(event), cursorWorldPosition)) {
initialPosition.setFromVector3(cursorWorldPosition).as('EPSG:4326', geoPosition);
state.latitude = `${geoPosition.y.toFixed(6)}`;
state.longitude = `${geoPosition.x.toFixed(6)}`;
} else {
state.latitude = '---------';
state.longitude = '---------';
}
LatController.updateDisplay();
LongController.updateDisplay();
};

gui.add(state, 'eventsDebug').name('Debug event').onChange((() => (newValue) => {
const listeners = [];
if (newValue) {
eventFolder = gui.addFolder('Events');
eventFolder.open();
Expand All @@ -121,13 +127,9 @@ function Debug(view, datDebugTool, chartDivContainer) {
LatController = eventFolder.add(state, 'latitude');
LongController = eventFolder.add(state, 'longitude');

view.addFrameRequester(MAIN_LOOP_EVENTS.UPDATE_END, cameraTargetListener);
listeners.push({ type: MAIN_LOOP_EVENTS.UPDATE_END, stateName: 'cameraTargetUpdated', fn: cameraTargetListener });
view.domElement.addEventListener('mousemove', cameraTargetListener);
} else {
for (const listener of listeners) {
controls.removeFrameRequester(listener.type, listener.fn);
delete state[listener.stateName];
}
view.domElement.removeEventListener('mousemove', cameraTargetListener);
gui.removeFolder('Events');
}
})());
Expand Down

0 comments on commit 9b62770

Please sign in to comment.