From efe9c5824a029d828f14de79c9f194a9bd3fbb6b Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Fri, 11 Oct 2024 23:32:11 +0200 Subject: [PATCH] feat: deprecate Coordinates constructor with array and vector3 --- examples/jsm/OGC3DTilesHelper.js | 2 +- src/Controls/GlobeControls.js | 10 +++++++--- src/Core/Geographic/Coordinates.js | 9 +++++++++ src/Renderer/Camera.js | 4 +++- src/Utils/CameraUtils.js | 5 ++++- utils/debug/Debug.js | 4 +++- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/examples/jsm/OGC3DTilesHelper.js b/examples/jsm/OGC3DTilesHelper.js index babf74596a..ce0306bad6 100644 --- a/examples/jsm/OGC3DTilesHelper.js +++ b/examples/jsm/OGC3DTilesHelper.js @@ -47,7 +47,7 @@ function zoomToSphere(view, tile, sphere) { const distance = radius * Math.tan(fov * 2); return { - coord: new Coordinates('EPSG:4978', center), + coord: new Coordinates('EPSG:4978').setFromVector3(center), range: distance + radius, }; } diff --git a/src/Controls/GlobeControls.js b/src/Controls/GlobeControls.js index 76b5901a2a..68ae25518d 100644 --- a/src/Controls/GlobeControls.js +++ b/src/Controls/GlobeControls.js @@ -755,7 +755,7 @@ class GlobeControls extends THREE.EventDispatcher { const range = this.getRange(point); if (point && range > this.minDistance) { return this.lookAtCoordinate({ - coord: new Coordinates('EPSG:4978', point), + coord: new Coordinates('EPSG:4978').setFromVector3(point), range: range * (event.direction === 'out' ? 1 / 0.6 : 0.6), time: 1500, }); @@ -1028,7 +1028,9 @@ class GlobeControls extends THREE.EventDispatcher { */ getCameraCoordinate() { - return new Coordinates('EPSG:4978', this.camera.position).as('EPSG:4326'); + return new Coordinates('EPSG:4978') + .setFromVector3(this.camera.position) + .as('EPSG:4326'); } /** @@ -1216,7 +1218,9 @@ class GlobeControls extends THREE.EventDispatcher { return; } - return new Coordinates('EPSG:4978', pickedPosition).as('EPSG:4326'); + return new Coordinates('EPSG:4978') + .setFromVector3(pickedPosition) + .as('EPSG:4326'); } } diff --git a/src/Core/Geographic/Coordinates.js b/src/Core/Geographic/Coordinates.js index d0934066ea..a3a7e38e5a 100644 --- a/src/Core/Geographic/Coordinates.js +++ b/src/Core/Geographic/Coordinates.js @@ -86,8 +86,16 @@ class Coordinates { this._normal = new THREE.Vector3(); if (v0.length > 0) { + console.warn( + 'Deprecated Coordinates#constructor(string, number[]),', + 'use new Coordinates(string).setFromArray(number[]) instead.', + ); this.setFromArray(v0); } else if (v0.isVector3 || v0.isCoordinates) { + console.warn( + 'Deprecated Coordinates#constructor(string, Vector3),', + 'use new Coordinates(string).setFromVector3(Vector3) instead.', + ); this.setFromVector3(v0); } else { this.setFromValues(v0, v1, v2); @@ -103,6 +111,7 @@ class Coordinates { setCrs(crs) { CRS.isValid(crs); this.crs = crs; + return this; } /** diff --git a/src/Renderer/Camera.js b/src/Renderer/Camera.js index 848936cf2b..99a29b9ee4 100644 --- a/src/Renderer/Camera.js +++ b/src/Renderer/Camera.js @@ -188,7 +188,9 @@ class Camera { * @return {Coordinates} Coordinates object holding camera's position. */ position(crs) { - return new Coordinates(this.crs, this.camera3D.position).as(crs || this.crs); + return new Coordinates(this.crs) + .setFromVector3(this.camera3D.position) + .as(crs || this.crs); } /** diff --git a/src/Utils/CameraUtils.js b/src/Utils/CameraUtils.js index 5bccc8ece6..a586a242e0 100644 --- a/src/Utils/CameraUtils.js +++ b/src/Utils/CameraUtils.js @@ -154,7 +154,10 @@ class CameraRig extends THREE.Object3D { // set rig's objects transformation from camera's position and target's position setFromPositions(view, cameraPosition) { - this.setTargetFromCoordinate(view, new Coordinates(view.referenceCrs, targetPosition)); + this.setTargetFromCoordinate( + view, + new Coordinates(view.referenceCrs).setFromVector3(targetPosition), + ); this.target.rotation.set(0, 0, 0); this.updateMatrixWorld(true); this.camera.position.copy(cameraPosition); diff --git a/utils/debug/Debug.js b/utils/debug/Debug.js index 97420a456b..55361cf5b6 100644 --- a/utils/debug/Debug.js +++ b/utils/debug/Debug.js @@ -177,7 +177,9 @@ function Debug(view, datDebugTool, chartDivContainer) { const size = { x: g.width * ratio, y: g.height * ratio }; debugCamera.aspect = size.x / size.y; const camera = view.camera3D; - const coord = new Coordinates(view.referenceCrs, camera.position).as(tileLayer.extent.crs); + const coord = new Coordinates(view.referenceCrs) + .setFromVector3(camera.position) + .as(tileLayer.extent.crs); const extent = view.tileLayer.info.displayed.extent; displayedTilesObb.setFromExtent(extent); displayedTilesObbHelper.visible = true;