Skip to content

Commit

Permalink
feat: deprecate Coordinates constructor with array and vector3
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Dec 20, 2024
1 parent a3fb6c5 commit efe9c58
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/jsm/OGC3DTilesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down
10 changes: 7 additions & 3 deletions src/Controls/GlobeControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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');
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/Core/Geographic/Coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -103,6 +111,7 @@ class Coordinates {
setCrs(crs) {
CRS.isValid(crs);
this.crs = crs;
return this;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Renderer/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Utils/CameraUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion utils/debug/Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit efe9c58

Please # to comment.