Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix viewer.flyTo ignoring and resetting minimumZoomDistance #5668

Merged
merged 9 commits into from
Jul 31, 2017

Conversation

cguldner
Copy link
Contributor

This fixes #5573.
I might have messed something up by doing this, but here goes my best shot!

For some reason, the screenSpaceCameraController.minimumZoomDistance was being set to the radius of the bounding sphere, which happened to be always zero, when zooming to an entity or billboard. As the maximumZoomDistance is never set in this way, and this was the commit message when that block of code was added. So I figured that wasn't particularly necessary anymore.

If nothing else, you could probably keep the tests!

@cguldner cguldner closed this Jul 23, 2017
@cguldner cguldner reopened this Jul 23, 2017
@hpinkos
Copy link
Contributor

hpinkos commented Jul 24, 2017

Thanks @burn123! @ggetz can you review?

CHANGES.md Outdated
@@ -23,6 +23,7 @@ Change Log
* Fixed crash when using the `Cesium3DTilesInspectorViewModel` and removing a tileset [#5607](https://github.com/AnalyticalGraphicsInc/cesium/issues/5607)
* Fixed polygon outline in Polygon Sandcastle demo [#5642](https://github.com/AnalyticalGraphicsInc/cesium/issues/5642)
* Fixed label positioning when using `HeightReference.CLAMP_TO_GROUND` and no position [#5648](https://github.com/AnalyticalGraphicsInc/cesium/pull/5648)
* Fixed `viewer.flyTo` not respecting zoom limits, and resetting minimumZoomDistance if the camera zoomed past the minimumZoomDistance. [5573](https://github.com/AnalyticalGraphicsInc/cesium/issues/5573)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewer -> Viewer

@@ -2605,6 +2605,36 @@ defineSuite([
expect(distance).toBeLessThan(sphere.radius * 3.0);
});

it('flyToBoundingSphere does not zoom closer than minimumZoomDistance', function() {
scene.mode = SceneMode.SCENE3D;
var MIN_VALUE = 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, use camel case

function adjustBoundingSphereOffset(camera, boundingSphere, offset) {
if (!defined(offset)) {
offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET);
}

var DEFAULT_ZOOM = 100.0;
var MINIMUM_ZOOM = camera._scene.screenSpaceCameraController.minimumZoomDistance;
var MAXIMUM_ZOOM = camera._scene.screenSpaceCameraController.maximumZoomDistance;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var range = offset.range;
if (!defined(range) || range === 0.0) {
var radius = boundingSphere.radius;
if (radius === 0.0) {
// If the minimumZoomDistance hasn't been set yet, it is equal to 1,
if (radius < MINIMUM_ZOOM && MINIMUM_ZOOM > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused why we can't default to the minimum zoom always.

Also see CesiumMath.clamp, that might simplify this if/else block a little.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was taking the approach that if the radius is 0, it would go to the default zoom unless the minimum zoom had been set already. If you zoom all the way to 1, it doesn't look very good, just a bunch of grey, because it is too close to the surface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see. However checking if it's < 1 doesn't guarantee the minimumZoom hasn't been set. Would it make sense to set minimumZoom to default to a higher value? @hpinkos

@cguldner
Copy link
Contributor Author

@ggetz See if this is what you had in mind. I actually think the minimumZoom problem was fixed by using clamp

@ggetz
Copy link
Contributor

ggetz commented Jul 24, 2017

Thanks @burn123, the code looks good to me, but there is one failing unit test now.

@cguldner
Copy link
Contributor Author

@ggetz I think the only failing test is something with the 3D Tile Spec, and it says "Async callback was not invoked within timeout", which I don't believe is related to this. I think I was getting that error on master as well.

@ggetz
Copy link
Contributor

ggetz commented Jul 24, 2017

I opened #5671 for the test failure.

Other than that, this looks good to me. @hpinkos is this good to go?

@cguldner
Copy link
Contributor Author

@hpinkos Did you have a chance to look at this yet?

@hpinkos
Copy link
Contributor

hpinkos commented Jul 27, 2017

I'll take a look at this first thing tomorrow

@cguldner
Copy link
Contributor Author

@hpinkos Do you think it would be possible to get this in by the next release? Our application is built on Cesium, but there is a good chance we will stay on Cesium 1.36 for a while, so it would be very useful to have this fixed. But I know you guys are busy, so I understand if not!

@hpinkos
Copy link
Contributor

hpinkos commented Jul 28, 2017

Yes, thanks for the reminder. I'll look at this now

function adjustBoundingSphereOffset(camera, boundingSphere, offset) {
if (!defined(offset)) {
offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET);
}

var defaultZoom = 100.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this back outside of the function where it was before

var range = offset.range;
if (!defined(range) || range === 0.0) {
var radius = boundingSphere.radius;
if (radius === 0.0) {
offset.range = MINIMUM_ZOOM;
if(radius === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add back the space between if and (

@@ -317,9 +317,6 @@ define([
var hasViewFrom = defined(viewFromProperty);

if (!hasViewFrom && defined(boundingSphere)) {
var controller = scene.screenSpaceCameraController;
controller.minimumZoomDistance = Math.min(controller.minimumZoomDistance, boundingSphere.radius * 0.5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mramato do you remember why this was added?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because our default minimumZoomDistance (at least at the time) was fairly large, so it was impossible to zoom to a model because you would end up 50 meters away. What is the current default minimumZoomDistance?

Copy link
Contributor Author

@cguldner cguldner Jul 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mramato If no minimumZoom is specified, it goes to 1, and the flyTo will go to about 100 units away if the bounding sphere for that model has a radius of 0. But this problem is fixed by the clamping of the zoom to the screenSpaceCameraController minimum and maximum zoom, so now it will never go outside those bounds.

@hpinkos
Copy link
Contributor

hpinkos commented Jul 28, 2017

Other than that, everything looks fine to me. All the tests pass locally. I just want to hear from @mramato about this change in case that behavior was added for a reason

@cguldner
Copy link
Contributor Author

cguldner commented Jul 28, 2017

@hpinkos I committed the changes!

@hpinkos hpinkos requested a review from mramato July 31, 2017 14:47
@hpinkos
Copy link
Contributor

hpinkos commented Jul 31, 2017

Thanks @burn123! This will be included in the 1.36 release, available tomorrow

@hpinkos hpinkos merged commit 3dd45ba into CesiumGS:master Jul 31, 2017
@cguldner cguldner deleted the flyToZoomLimits branch August 1, 2017 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

viewer.flyTo on billboards breaks zoom limits
4 participants