-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
…es haven't been set
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
viewer
-> Viewer
Specs/Scene/CameraSpec.js
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, use camel case
Source/Scene/Camera.js
Outdated
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per our Coding Guide, these should be camel case, see https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Documentation/Contributors/CodingGuide/README.md#naming
Source/Scene/Camera.js
Outdated
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@ggetz See if this is what you had in mind. I actually think the minimumZoom problem was fixed by using |
Thanks @burn123, the code looks good to me, but there is one failing unit test now. |
@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. |
@hpinkos Did you have a chance to look at this yet? |
I'll take a look at this first thing tomorrow |
@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! |
Yes, thanks for the reminder. I'll look at this now |
Source/Scene/Camera.js
Outdated
function adjustBoundingSphereOffset(camera, boundingSphere, offset) { | ||
if (!defined(offset)) { | ||
offset = HeadingPitchRange.clone(Camera.DEFAULT_OFFSET); | ||
} | ||
|
||
var defaultZoom = 100.0; |
There was a problem hiding this comment.
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
Source/Scene/Camera.js
Outdated
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 |
@hpinkos I committed the changes! |
Thanks @burn123! This will be included in the 1.36 release, available tomorrow |
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 themaximumZoomDistance
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!