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

Oneliner to Zoom to 3DTileset #6104

Merged
merged 19 commits into from
Jan 17, 2018
Merged

Conversation

hanbollar
Copy link
Contributor

Fixes #5626

Added Viewer.zoomToTileset
Updated sandcastle 3DTileset examples to use this added function

@cesium-concierge
Copy link

Please sign the CLA before we review this PR.

Welcome to the Cesium community @hanbollar!

Can you please send in a Contributor License Agreement (CLA) so that we can review and merge this pull request?


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@mramato
Copy link
Contributor

mramato commented Jan 9, 2018

Thanks @hanbollar. Is there a reason we added zoomToTileset instead of updating zoomTo and flyTo to simply handle tilesets? For consistency, I think that is the better approach, since viewer.zoomTo/flyTo is how we handle everything else (entities, imagery, etc..)

@hanbollar
Copy link
Contributor Author

Thanks for the feedback @mramato - i'll work on doing that modification

@hanbollar
Copy link
Contributor Author

@mramato - updated so that zooming to a tileset uses zoomTo and flyTo

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

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

Thanks @hanbollar! Great start, especially for your second Cesium issue! I have a few comments before we merge.

@@ -25,6 +25,8 @@ Change Log
* Only one node is supported.
* Only one mesh per node is supported.
* Only one primitive per mesh is supported.
* Updated documentation links to reflect new locations on cesiumjs.org and cesium.com.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a duplicate of line 32

@@ -1748,12 +1757,12 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
* target will be the range. The heading will be determined from the offset. If the heading cannot be
* determined from the offset, the heading will be north.</p>
*
* @param {Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Promise.<Entity|Entity[]|EntityCollection|DataSource|ImageryLayer>} target The entity, array of entities, entity collection, data source or imagery layer to view. You can also pass a promise that resolves to one of the previously mentioned types.
* @param {Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|Promise.<Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset>} target The entity, array of entities, entity collection, data source, Cesium3DTileset, or imagery layer to view. You can also pass a promise that resolves to one of the previously mentioned types.
Copy link
Contributor

Choose a reason for hiding this comment

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

You should update the description to include tilesets as well. Same applies to zoomTo.

@@ -1778,6 +1787,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
that._zoomOptions = options;

when(zoomTarget, function(zoomTarget) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove extra space.

* @param {Object} [options] Object with the following properties:
* @param {Number} [options.duration=3.0] The duration of the flight in seconds.
* @param {Number} [options.maximumHeight] The maximum height at the peak of the flight.
* @param {HeadingPitchRange} [options.offset] The offset from the target in the local east-north-up reference frame centered at the target.
* @returns {Promise.<Boolean>} A Promise that resolves to true if the flight was successful or false if the entity is not currently visualized in the scene or the flight was cancelled.
* @returns {Promise.<Boolean>} A Promise that resolves to true if the flight was successful or false if the entity is not currently visualized in the scene or the flight was cancelled. //TODO: Cleanup entity mentions
Copy link
Contributor

Choose a reason for hiding this comment

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

Resolve this TODO

Copy link
Contributor

Choose a reason for hiding this comment

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

And do the same for zoomTo

});
}

var entities = target;
Copy link
Contributor

Choose a reason for hiding this comment

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

For clarity, move this to after the check for an ImageryLayer, when we know the target is a list of entities.

url : path
});

//spyOn(viewer.camera, 'viewBoundingSphere');
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove commented code.

});
});

it('flys to target when target is Cesium3DTileset and offset is defined', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think your tests names can be a little more precise. For instance, this one can be "flyTo flies to Cesium3DTileset with offset".

"flys to when target is Cesium3DTileset and uses default offset when offset not defined in options" -> "flyTo flies to Cesium3DTileset with default offset"


});

it('flys to when target is Cesium3DTileset and uses default offset when offset not defined in options', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to make sure we're not breaking functionality, it might be best to add some tests to check zooming to entities. You should be able to duplicate this test and just pass an entity or array of entities instead of a tileset.

var options;

// If zoomTarget was Cesium3DTileset
if (defined(target.readyPromise)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

instanceof should work properly now since you fixed the error with the import.

zoomOptions.offset = new HeadingPitchRange(0.0, 0.0, 2.0 * bSphere.radius);
}

options = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure you are taking into account the following options that can be passed to the flyTo function.

      * @param {Number} [options.duration=3.0] The duration of the flight in seconds.
      * @param {Number} [options.maximumHeight] The maximum height at the peak of the flight.

Add a tests for when these are provided, they are being passed to flyToBoundingSphere.

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

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

@hanbollar Thanks for the updates! I have a few more comments.

@@ -61,9 +61,7 @@
}));

tileset.readyPromise.then(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since zoomTo now encapsulates the readyPromise, we can update these to be

viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(...))
    .otherwise(function(error) {
        throw(error);
    });

});

it('zoomTo zooms to Cesium3DTileset with default offset when offset not defined', function() {
viewer = createViewer(container);
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation looks a little off, try running the autoformatter in Webstorm.

// load the tileset then check tests
return tileset.readyPromise.then(function() {
var boundingSphere = tileset.boundingSphere;
var offset = new HeadingPitchRange(0.4, 1.2, 4 * boundingSphere.radius);
Copy link
Contributor

Choose a reason for hiding this comment

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


return viewer.zoomTo(entities, offset).then(function() {
// moved to new location
expect(viewer.camera.position).not.toEqual(camPos);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here and in the above tests, just spy on camera.flyToBoundingSphere or viewBoundingSphere and make sure it's being called with the options you expect it to be. You can also just pass a new hardcoded HeadingPitchRange with made up numbers since the function won't be called through. You don't need to iterate through all the bounding spheres in these tests

viewer.render();

return promise.then(function() {
expect(wasCompleted).toEqual(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also expect flyToBoundingSphere toHaveBeenCalledWith the proper options.

var boundingSphere = tileset.boundingSphere;
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -0.5, tileset.boundingSphere.radius));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is used most commonly, can we make this the default?

Then we can use the shorthand:

viewer.zoomTo(tileset).otherwise(function(error) {
    throw(error);
});

var boundingSphere = tileset.boundingSphere;
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.3, 0.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
viewer.zoomToTileset(tileset, new Cesium.HeadingPitchRange(0.0, -0.3, 0.0));
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is not based on the bounding sphere, so we don't need to wait for the readyPromise.

hanbollar added 2 commits January 16, 2018 15:11
…o's default offset. updated tests for zoomTo and flyTo to include entities and certain expectations
@hpinkos
Copy link
Contributor

hpinkos commented Jan 17, 2018

@hanbollar make sure to make a comment when this is ready for another look. The reviewer doesn't get notifications when you add new commits, so it's a good idea to comment to let them know.

@ggetz
Copy link
Contributor

ggetz commented Jan 17, 2018

Thanks @hanbollar !

@ggetz ggetz merged commit 4440bd9 into CesiumGS:master Jan 17, 2018
@hanbollar hanbollar deleted the zoom-to-tileset branch February 2, 2018 19:02
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.

5 participants