-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
872b8dc
changed zoom for tileset so 1 line call instead of 3
a28dcce
Merge remote-tracking branch 'cesium-upstream/master'
4d31962
created function that zooms to a 3DTileset
4c8a5be
updated 3DTiles files in sandcastle to use zoomToTiles
ad555b4
added update note to changes.md
01af1c7
added in missing
e11e281
modified zoomToOrFly to include target of Cesium3DTileset
d24e99f
updated sandbox 3D Tiles to use zoomTo instead of separate function
6690763
Deleted Viewer.zoomToTileset. Updated Sandbox 3Dtileset examples to u…
601e242
updated zoomTo to use options parameter to helper instead of just off…
2893507
updated CHANGED.md and removed items specified by eslint
a2a0348
Merge remote-tracking branch 'cesium-upstream/master'
9cdb975
updated CHANGES.md from merge
4e5ba70
updated typo
b1f7296
updated typos due to last typo
dfa8c2c
modified as per ggetz's recommendations and added in tests for checki…
d899c13
removed unused variable
1ca28af
updated 3d tiles sandcastle examples for some to be able to use zoomT…
254d8a4
removed commented code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.5, boundingSphere.radius); | ||
} | ||
|
||
options = { | ||
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); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is a duplicate of line 32