Skip to content

Commit f0dc559

Browse files
authoredMay 31, 2023
Merge pull request #11319 from CesiumGS/tracked-entity-fix
Fix for zoom on tracked entity
2 parents b741605 + c2f7e64 commit f0dc559

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed
 

‎CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
##### Fixes :wrench:
88

9+
- Fixed tracked entity camera controls. [#11286](https://github.com/CesiumGS/cesium/issues/11286)
910
- Fixed color creation from CSS color string with modern "space-separated" syntax. [#11271](https://github.com/CesiumGS/cesium/pull/11271)
1011
- Fixed a race condition when loading cut-out terrain. [#11296](https://github.com/CesiumGS/cesium/pull/11296)
1112
- Fixed async behavior for custom terrain and imagery providers. [#11274](https://github.com/CesiumGS/cesium/issues/11274)

‎packages/engine/Source/Scene/ScreenSpaceCameraController.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ function handleZoom(
613613
object._zoomMouseStart
614614
);
615615

616+
// When camera transform is set, such as tracking an entity, object._globe will be undefined, and no position should be picked
616617
if (defined(object._globe) && mode === SceneMode.SCENE2D) {
617618
pickedPosition = camera.getPickRay(startPosition, scratchZoomPickRay)
618619
.origin;
@@ -621,7 +622,7 @@ function handleZoom(
621622
pickedPosition.z,
622623
pickedPosition.x
623624
);
624-
} else {
625+
} else if (defined(object._globe)) {
625626
pickedPosition = pickPosition(
626627
object,
627628
startPosition,

‎packages/engine/Specs/Scene/ScreenSpaceCameraControllerSpec.js

+66-2
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ describe("Scene/ScreenSpaceCameraController", function () {
929929
);
930930
});
931931

932-
it("rotates in Columus view with camera transform set", function () {
932+
it("rotates in Columbus view with camera transform set", function () {
933933
setUpCV();
934934

935935
const origin = Cartesian3.fromDegrees(-72.0, 40.0);
@@ -983,7 +983,7 @@ describe("Scene/ScreenSpaceCameraController", function () {
983983
expect(camera.position).not.toEqual(position);
984984
});
985985

986-
it("zooms in Columus view with camera transform set", function () {
986+
it("zooms in Columbus view with camera transform set", function () {
987987
setUpCV();
988988

989989
const origin = Cartesian3.fromDegrees(-72.0, 40.0);
@@ -1198,6 +1198,70 @@ describe("Scene/ScreenSpaceCameraController", function () {
11981198
);
11991199
});
12001200

1201+
it("zooms in on an object in 3D", function () {
1202+
setUp3D();
1203+
1204+
scene.globe = new MockGlobe(scene.mapProjection.ellipsoid);
1205+
1206+
updateController();
1207+
1208+
const origin = Cartesian3.fromDegrees(-72.0, 40.0, 1.0);
1209+
camera.setView({
1210+
destination: origin,
1211+
});
1212+
1213+
updateController();
1214+
1215+
scene.pickPositionSupported = true;
1216+
scene.pickPositionWorldCoordinates = () =>
1217+
Cartesian3.fromDegrees(-72.0, 40.0, -10.0);
1218+
1219+
const position = Cartesian3.clone(camera.position);
1220+
const startPosition = new Cartesian2(0, 0);
1221+
const endPosition = new Cartesian2(0, canvas.clientHeight / 2);
1222+
1223+
moveMouse(MouseButtons.RIGHT, startPosition, endPosition);
1224+
1225+
updateController();
1226+
1227+
expect(Cartesian3.magnitude(position)).toBeGreaterThan(
1228+
Cartesian3.magnitude(camera.position)
1229+
);
1230+
});
1231+
1232+
it("zooms in on an object in 3D when transform is set", function () {
1233+
setUp3D();
1234+
1235+
scene.globe = new MockGlobe(scene.mapProjection.ellipsoid);
1236+
1237+
updateController();
1238+
1239+
const origin = Cartesian3.fromDegrees(-72.0, 40.0, 1.0);
1240+
camera.lookAtTransform(Transforms.eastNorthUpToFixedFrame(origin), {
1241+
heading: 0,
1242+
pitch: 0,
1243+
range: 10,
1244+
});
1245+
1246+
updateController();
1247+
1248+
scene.pickPositionSupported = true;
1249+
scene.pickPositionWorldCoordinates = () =>
1250+
Cartesian3.fromDegrees(-72.0, 40.0, -10.0);
1251+
1252+
const position = Cartesian3.clone(camera.position);
1253+
const startPosition = new Cartesian2(0, 0);
1254+
const endPosition = new Cartesian2(0, canvas.clientHeight / 2);
1255+
1256+
moveMouse(MouseButtons.RIGHT, startPosition, endPosition);
1257+
1258+
updateController();
1259+
1260+
expect(Cartesian3.magnitude(position)).toBeGreaterThan(
1261+
Cartesian3.magnitude(camera.position)
1262+
);
1263+
});
1264+
12011265
it("zoom in 3D to point 0,0", function () {
12021266
setUp3D();
12031267
scene.globe = new MockGlobe(scene.mapProjection.ellipsoid);

0 commit comments

Comments
 (0)
Please sign in to comment.