-
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
Oneliner to Zoom to 3DTileset #6104
Changes from 17 commits
872b8dc
a28dcce
4d31962
4c8a5be
ad555b4
01af1c7
e11e281
d24e99f
6690763
601e242
2893507
a2a0348
9cdb975
4e5ba70
b1f7296
dfa8c2c
d899c13
1ca28af
254d8a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = []; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
}).otherwise(function(error) { | ||
throw(error); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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', | ||
|
@@ -9,6 +10,7 @@ define([ | |
'../../Core/DeveloperError', | ||
'../../Core/Event', | ||
'../../Core/EventHelper', | ||
'../../Core/HeadingPitchRange', | ||
'../../Core/isArray', | ||
'../../Core/Matrix4', | ||
'../../Core/Rectangle', | ||
|
@@ -20,6 +22,7 @@ define([ | |
'../../DataSources/Entity', | ||
'../../DataSources/EntityView', | ||
'../../DataSources/Property', | ||
'../../Scene/Cesium3DTileset', | ||
'../../Scene/ImageryLayer', | ||
'../../Scene/SceneMode', | ||
'../../ThirdParty/knockout', | ||
|
@@ -46,6 +49,7 @@ define([ | |
], function( | ||
BoundingSphere, | ||
Cartesian3, | ||
Check, | ||
Clock, | ||
defaultValue, | ||
defined, | ||
|
@@ -54,6 +58,7 @@ define([ | |
DeveloperError, | ||
Event, | ||
EventHelper, | ||
HeadingPitchRange, | ||
isArray, | ||
Matrix4, | ||
Rectangle, | ||
|
@@ -65,6 +70,7 @@ define([ | |
Entity, | ||
EntityView, | ||
Property, | ||
Cesium3DTileset, | ||
ImageryLayer, | ||
SceneMode, | ||
knockout, | ||
|
@@ -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)) { | ||
|
@@ -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 | ||
|
@@ -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, | ||
|
@@ -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. | ||
|
@@ -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); | ||
}; | ||
|
||
/** | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
* @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); | ||
|
@@ -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() { | ||
|
@@ -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 { | ||
|
@@ -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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Add a tests for when these are provided, they are being passed to |
||
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() { | ||
|
@@ -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); | ||
|
@@ -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); | ||
|
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.
Since
zoomTo
now encapsulates the readyPromise, we can update these to be