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
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Apps/Sandcastle/gallery/3D Tiles Adjust Height.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
    });

var boundingSphere = tileset.boundingSphere;
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius * 2));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -0.5, tileset.boundingSphere.radius * 2));
}).otherwise(function(error) {
throw(error);
});
Expand Down
4 changes: 1 addition & 3 deletions Apps/Sandcastle/gallery/3D Tiles BIM.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
}));

tileset.readyPromise.then(function() {
var boundingSphere = tileset.boundingSphere;
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.5, -0.2, boundingSphere.radius * 4.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.5, -0.2, tileset.boundingSphere.radius * 4.0));
}).otherwise(function(error) {
throw(error);
});
Expand Down
6 changes: 3 additions & 3 deletions Apps/Sandcastle/gallery/3D Tiles Batch Table Hierarchy.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
}));

tileset.readyPromise.then(function() {
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.

}).otherwise(function(error) {
throw(error);
});

var styles = [];
Expand Down
3 changes: 1 addition & 2 deletions Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@
var boundingSphere = tileset.boundingSphere;
var radius = boundingSphere.radius;

viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.5, -0.2, radius * 4.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.5, -0.2, radius * 4.0));

for (var i = 0; i < clippingPlanes.length; ++i) {
var plane = clippingPlanes[i];
Expand Down
6 changes: 2 additions & 4 deletions Apps/Sandcastle/gallery/3D Tiles Formats.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@
inspectorViewModel.tileset = tileset;
scene.primitives.add(tileset);
tileset.readyPromise.then(function(tileset) {
var boundingSphere = tileset.boundingSphere;
var range = Math.max(100.0 - boundingSphere.radius, 0.0); // Set a minimum offset of 100 meters
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0, -2.0, range));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);

viewer.zoomToTileset(tileset, new Cesium.HeadingPitchRange(0, -2.0, Math.max(100.0 - tileset.boundingSphere.radius, 0.0)));

var properties = tileset.properties;
if (Cesium.defined(properties) && Cesium.defined(properties.Height)) {
Expand Down
4 changes: 1 addition & 3 deletions Apps/Sandcastle/gallery/3D Tiles Inspector.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
}));

tileset.readyPromise.then(function() {
var boundingSphere = tileset.boundingSphere;
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius / 4.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
viewer.zoomToTileset(tileset, new Cesium.HeadingPitchRange(0.0, -0.5, tileset.boundingSphere.radius / 4.0));
}).otherwise(function(error) {
throw(error);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@

// Move the camera to view the tileset on load.
tileset.readyPromise.then(function() {
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));
}).otherwise(function(error) {
throw(error);
});
Expand Down
4 changes: 1 addition & 3 deletions Apps/Sandcastle/gallery/3D Tiles Photogrammetry.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
}));

tileset.readyPromise.then(function() {
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));
}).otherwise(function(error) {
throw(error);
});
Expand Down
4 changes: 1 addition & 3 deletions Apps/Sandcastle/gallery/3D Tiles Point Cloud.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
}));

tileset.readyPromise.then(function() {
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);
});

}).otherwise(function(error) {
throw(error);
});
Expand Down
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ 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

* Updated 'Viewer.zoomTo' and 'Viewer.flyTo' to take in Cesium3DTilesets as a target and updated sandcastle 3DTileset examples to reflect this change
* Fixed a glTF animation bug that caused certain animations to jitter. [#5740](https://github.com/AnalyticalGraphicsInc/cesium/pull/5740)
* Fixed a bug when creating billboard and model entities without a globe. [#6109](https://github.com/AnalyticalGraphicsInc/cesium/pull/6109)
* Updated documentation links to reflect new locations on cesiumjs.org and cesium.com.
* Added support for vertex shader uniforms when `tileset.colorBlendMode` is `MIX` or `REPLACE`. [#5874](https://github.com/AnalyticalGraphicsInc/cesium/pull/5874)

### 1.41 - 2018-01-02
Expand Down
86 changes: 70 additions & 16 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
define([
'../../Core/BoundingSphere',
'../../Core/Cartesian3',
'../../Core/Check',
'../../Core/Clock',
'../../Core/defaultValue',
'../../Core/defined',
Expand All @@ -9,6 +10,7 @@ define([
'../../Core/DeveloperError',
'../../Core/Event',
'../../Core/EventHelper',
'../../Core/HeadingPitchRange',
'../../Core/isArray',
'../../Core/Matrix4',
'../../Core/Rectangle',
Expand All @@ -20,6 +22,7 @@ define([
'../../DataSources/Entity',
'../../DataSources/EntityView',
'../../DataSources/Property',
'../../Scene/Cesium3DTileset',
'../../Scene/ImageryLayer',
'../../Scene/SceneMode',
'../../ThirdParty/knockout',
Expand All @@ -46,6 +49,7 @@ define([
], function(
BoundingSphere,
Cartesian3,
Check,
Clock,
defaultValue,
defined,
Expand All @@ -54,6 +58,7 @@ define([
DeveloperError,
Event,
EventHelper,
HeadingPitchRange,
isArray,
Matrix4,
Rectangle,
Expand All @@ -65,6 +70,7 @@ define([
Entity,
EntityView,
Property,
Cesium3DTileset,
ImageryLayer,
SceneMode,
knockout,
Expand Down Expand Up @@ -205,13 +211,13 @@ define([
if (defined(homeButton)) {
homeButton.container.style.visibility = visibility;
}
if(defined(sceneModePicker)) {
if (defined(sceneModePicker)) {
sceneModePicker.container.style.visibility = visibility;
}
if (defined(projectionPicker)) {
projectionPicker.container.style.visibility = visibility;
}
if(defined(baseLayerPicker)) {
if (defined(baseLayerPicker)) {
baseLayerPicker.container.style.visibility = visibility;
}
if (defined(animation)) {
Expand Down Expand Up @@ -356,7 +362,7 @@ define([
options = defaultValue(options, defaultValue.EMPTY_OBJECT);

var createBaseLayerPicker = (!defined(options.globe) || options.globe !== false) &&
(!defined(options.baseLayerPicker) || options.baseLayerPicker !== false);
(!defined(options.baseLayerPicker) || options.baseLayerPicker !== false);

//>>includeStart('debug', pragmas.debug);
// If using BaseLayerPicker, imageryProvider is an invalid option
Expand Down Expand Up @@ -431,7 +437,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
targetFrameRate : options.targetFrameRate,
showRenderLoopErrors : options.showRenderLoopErrors,
creditContainer : defined(options.creditContainer) ? options.creditContainer : bottomContainer,
creditViewport: options.creditViewport,
creditViewport : options.creditViewport,
scene3DOnly : scene3DOnly,
terrainExaggeration : options.terrainExaggeration,
shadows : options.shadows,
Expand Down Expand Up @@ -491,7 +497,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
toolbar.appendChild(geocoderContainer);
geocoder = new Geocoder({
container : geocoderContainer,
geocoderServices: defined(options.geocoder) ? (isArray(options.geocoder) ? options.geocoder : [options.geocoder]) : undefined,
geocoderServices : defined(options.geocoder) ? (isArray(options.geocoder) ? options.geocoder : [options.geocoder]) : undefined,
scene : cesiumWidget.scene
});
// Subscribe to search so that we can clear the trackedEntity when it is clicked.
Expand Down Expand Up @@ -1725,12 +1731,15 @@ 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, Cesium#DTileset, or imagery layer to view. You can also pass a promise that resolves to one of the previously mentioned types.
* @param {HeadingPitchRange} [offset] The offset from the center of the entity in the local east-north-up reference frame.
* @returns {Promise.<Boolean>} A Promise that resolves to true if the zoom was successful or false if the entity is not currently visualized in the scene or the zoom was cancelled.
* @returns {Promise.<Boolean>} A Promise that resolves to true if the zoom was successful or false if the target is not currently visualized in the scene or the zoom was cancelled.
*/
Viewer.prototype.zoomTo = function(target, offset) {
return zoomToOrFly(this, target, offset, false);
var options = {
offset : offset
};
return zoomToOrFly(this, target, options, false);
};

/**
Expand All @@ -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.

* @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 target is not currently visualized in the scene or the flight was cancelled. //TODO: Cleanup entity mentions
*/
Viewer.prototype.flyTo = function(target, options) {
return zoomToOrFly(this, target, options, true);
Expand Down Expand Up @@ -1794,6 +1803,12 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
return;
}

//If the zoom target is a Cesium3DTileset
if (zoomTarget instanceof Cesium3DTileset) {
that._zoomTarget = zoomTarget;
return;
}

//If the zoom target is a data source, and it's in the middle of loading, wait for it to finish loading.
if (zoomTarget.isLoading && defined(zoomTarget.loadingEvent)) {
var removeEvent = zoomTarget.loadingEvent.addEventListener(function() {
Expand Down Expand Up @@ -1821,6 +1836,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
zoomTarget = zoomTarget.entities.values;
}

//Zoom target is already an array, just copy it and return.
if (isArray(zoomTarget)) {
that._zoomTarget = zoomTarget.slice(0);
} else {
Expand Down Expand Up @@ -1855,20 +1871,56 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
};

function updateZoomTarget(viewer) {
var entities = viewer._zoomTarget;
if (!defined(entities) || viewer.scene.mode === SceneMode.MORPHING) {
var target = viewer._zoomTarget;
if (!defined(target) || viewer.scene.mode === SceneMode.MORPHING) {
return;
}

var scene = viewer.scene;
var camera = scene.camera;
var zoomPromise = viewer._zoomPromise;
var zoomOptions = defaultValue(viewer._zoomOptions, {});
var options;

// If zoomTarget was Cesium3DTileset
if (target instanceof Cesium3DTileset) {
return target.readyPromise.then(function() {
var boundingSphere = target.boundingSphere;
// if offset was originally undefined then give it base value instead of empty object
if (!defined(zoomOptions.offset)) {
zoomOptions.offset = new HeadingPitchRange(0.0, 0.0, 2.0 * boundingSphere.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.

offset : zoomOptions.offset,
duration : zoomOptions.duration,
maximumHeight : zoomOptions.maximumHeight,
complete : function() {
zoomPromise.resolve(true);
},
cancel : function() {
zoomPromise.resolve(false);
}
};

if (viewer._zoomIsFlight) {
camera.flyToBoundingSphere(target.boundingSphere, options);
} else {
camera.viewBoundingSphere(boundingSphere, zoomOptions.offset);
camera.lookAtTransform(Matrix4.IDENTITY);

// finish the promise
zoomPromise.resolve(true);
}

clearZoom(viewer);
});
}

//If zoomTarget was an ImageryLayer
if (entities instanceof Rectangle) {
var options = {
destination : entities,
if (target instanceof Rectangle) {
options = {
destination : target,
duration : zoomOptions.duration,
maximumHeight : zoomOptions.maximumHeight,
complete : function() {
Expand All @@ -1889,6 +1941,8 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
return;
}

var entities = target;

var boundingSpheres = [];
for (var i = 0, len = entities.length; i < len; i++) {
var state = viewer._dataSourceDisplay.getBoundingSphere(entities[i], false, boundingSphereScratch);
Expand All @@ -1911,7 +1965,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
var boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres);

if (!viewer._zoomIsFlight) {
camera.viewBoundingSphere(boundingSphere, viewer._zoomOptions);
camera.viewBoundingSphere(boundingSphere, viewer._zoomOptions.offset);
camera.lookAtTransform(Matrix4.IDENTITY);
clearZoom(viewer);
zoomPromise.resolve(true);
Expand Down
Loading