Skip to content

Commit

Permalink
Merge pull request #7154 from AnalyticalGraphicsInc/issue7143
Browse files Browse the repository at this point in the history
Make computeFlyToLocationForRectangle always return a Cartographic
  • Loading branch information
Hannah authored Oct 16, 2018
2 parents ae98c62 + 46983f8 commit 420250e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Change Log

##### Fixes :wrench:
* Fixed an issue where `pickPosition` would return incorrect results when called after `sampleHeight` or `clampToHeight`. [#7113](https://github.com/AnalyticalGraphicsInc/cesium/pull/7113)
* Fixed a crash when using `BingMapsGeocoderService` [#7143](https://github.com/AnalyticalGraphicsInc/cesium/issues/7143)

### 1.50 - 2018-10-01

Expand Down
32 changes: 16 additions & 16 deletions Source/Scene/computeFlyToLocationForRectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,38 @@ define([
'use strict';

/**
* Computes the final camera location to view a rectangle adjusted for terrain.
* Computes the final camera location to view a rectangle adjusted for the current terrain.
* If the terrain does not support availability, the height above the ellipsoid is used.
*
* @param {Rectangle} rectangle The rectangle being zoomed to.
* @param {Scene} scene The scene being used.
*
* @returns {Cartographic|Rectangle} The location to place the camera or the original rectangle if terrain does not have availability.
* @returns {Cartographic} The optimal location to place the camera so that the entire rectangle is in view.
*
* @private
*/
function computeFlyToLocationForRectangle(rectangle, scene) {
var terrainProvider = scene.terrainProvider;
var mapProjection = scene.mapProjection;
var ellipsoid = mapProjection.ellipsoid;

var positionWithoutTerrain;
var tmp = scene.camera.getRectangleCameraCoordinates(rectangle);
if (scene.mode === SceneMode.SCENE3D) {
positionWithoutTerrain = ellipsoid.cartesianToCartographic(tmp);
} else {
positionWithoutTerrain = mapProjection.unproject(tmp);
}

if (!defined(terrainProvider)) {
return when.resolve(rectangle);
return when.resolve(positionWithoutTerrain);
}

return terrainProvider.readyPromise.then(function() {
var availability = terrainProvider.availability;

if (!defined(availability) || scene.mode === SceneMode.SCENE2D) {
return rectangle;
return positionWithoutTerrain;
}

var cartographics = [
Expand All @@ -50,18 +61,7 @@ define([
return Math.max(item.height, currentMax);
}, -Number.MAX_VALUE);

var finalPosition;

var camera = scene.camera;
var mapProjection = scene.mapProjection;
var ellipsoid = mapProjection.ellipsoid;
var tmp = camera.getRectangleCameraCoordinates(rectangle);
if (scene.mode === SceneMode.SCENE3D) {
finalPosition = ellipsoid.cartesianToCartographic(tmp);
} else {
finalPosition = mapProjection.unproject(tmp);
}

var finalPosition = positionWithoutTerrain;
finalPosition.height += maxHeight;
return finalPosition;
});
Expand Down
9 changes: 2 additions & 7 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1982,14 +1982,9 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
}

// If zoomTarget was an ImageryLayer
var isCartographic = target instanceof Cartographic;
if (target instanceof Rectangle || isCartographic) {
var destination = target;
if (isCartographic) {
destination = scene.mapProjection.ellipsoid.cartographicToCartesian(destination);
}
if (target instanceof Cartographic) {
options = {
destination : destination,
destination : scene.mapProjection.ellipsoid.cartographicToCartesian(target),
duration : zoomOptions.duration,
maximumHeight : zoomOptions.maximumHeight,
complete : function() {
Expand Down
20 changes: 12 additions & 8 deletions Specs/Scene/computeFlyToLocationForRectangleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defineSuite([
return sampleTest(SceneMode.COLUMBUS_VIEW);
});

it('returns original rectangle in 2D', function() {
it('returns height above ellipsoid when in 2D', function() {
var terrainProvider = new EllipsoidTerrainProvider();
terrainProvider.availability = {};

Expand All @@ -93,25 +93,27 @@ defineSuite([
scene.mode = SceneMode.SCENE2D;

var rectangle = new Rectangle(0.2, 0.4, 0.6, 0.8);
spyOn(computeFlyToLocationForRectangle, '_sampleTerrainMostDetailed');
var expectedResult = scene.mapProjection.unproject(scene.camera.getRectangleCameraCoordinates(rectangle));

spyOn(computeFlyToLocationForRectangle, '_sampleTerrainMostDetailed');
return computeFlyToLocationForRectangle(rectangle, scene)
.then(function(result) {
expect(result).toBe(rectangle);
expect(result).toEqual(expectedResult);
expect(computeFlyToLocationForRectangle._sampleTerrainMostDetailed).not.toHaveBeenCalled();
});
});

it('returns original rectangle when terrain not available', function() {
it('returns height above ellipsoid when terrain not available', function() {
scene.globe = new Globe();
scene.terrainProvider = new EllipsoidTerrainProvider();

var rectangle = new Rectangle(0.2, 0.4, 0.6, 0.8);
spyOn(computeFlyToLocationForRectangle, '_sampleTerrainMostDetailed');

var expectedResult = scene.mapProjection.ellipsoid.cartesianToCartographic(scene.camera.getRectangleCameraCoordinates(rectangle));
return computeFlyToLocationForRectangle(rectangle, scene)
.then(function(result) {
expect(result).toBe(rectangle);
expect(result).toEqual(expectedResult);
expect(computeFlyToLocationForRectangle._sampleTerrainMostDetailed).not.toHaveBeenCalled();
});
});
Expand All @@ -124,21 +126,23 @@ defineSuite([
scene.terrainProvider = terrainProvider;

var rectangle = new Rectangle(0.2, 0.4, 0.6, 0.8);
var expectedResult = scene.mapProjection.ellipsoid.cartesianToCartographic(scene.camera.getRectangleCameraCoordinates(rectangle));
return computeFlyToLocationForRectangle(rectangle, scene)
.then(function(result) {
expect(result).toBe(rectangle);
expect(result).toEqual(expectedResult);
expect(terrainProvider.readyPromise.then).toHaveBeenCalled();
});
});

it('returns original rectangle when terrain undefined', function() {
it('returns height above ellipsoid when terrain undefined', function() {
scene.terrainProvider = undefined;
var rectangle = new Rectangle(0.2, 0.4, 0.6, 0.8);
spyOn(computeFlyToLocationForRectangle, '_sampleTerrainMostDetailed');

var expectedResult = scene.mapProjection.ellipsoid.cartesianToCartographic(scene.camera.getRectangleCameraCoordinates(rectangle));
return computeFlyToLocationForRectangle(rectangle, scene)
.then(function(result) {
expect(result).toBe(rectangle);
expect(result).toEqual(expectedResult);
expect(computeFlyToLocationForRectangle._sampleTerrainMostDetailed).not.toHaveBeenCalled();
});
});
Expand Down

0 comments on commit 420250e

Please sign in to comment.