Skip to content

Commit

Permalink
Find map bounds using the current projection instead of estimating them.
Browse files Browse the repository at this point in the history
  • Loading branch information
bagnell committed Jul 3, 2012
1 parent 226db25 commit 21d182f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
49 changes: 22 additions & 27 deletions Source/Scene/Camera2DController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ define([
'../Core/Ellipsoid',
'../Core/Cartesian2',
'../Core/Cartesian3',
'../Core/Cartographic3',
'./CameraEventHandler',
'./CameraEventType',
'./CameraHelpers',
Expand All @@ -22,6 +23,7 @@ define([
Ellipsoid,
Cartesian2,
Cartesian3,
Cartographic3,
CameraEventHandler,
CameraEventType,
CameraHelpers,
Expand All @@ -46,12 +48,10 @@ define([
*
* @internalConstructor
*/
var Camera2DController = function(canvas, camera, ellipsoid) {
ellipsoid = ellipsoid || Ellipsoid.WGS84;

var Camera2DController = function(canvas, camera, projection) {
this._canvas = canvas;
this._camera = camera;
this._ellipsoid = ellipsoid;
this._ellipsoid = projection.getEllipsoid();
this._zoomRate = 100000.0;
this._moveRate = 100000.0;

Expand Down Expand Up @@ -98,8 +98,7 @@ define([
this._frustum.top *= maxZoomOut;
this._frustum.bottom *= maxZoomOut;

this._cameraMaxX = this._ellipsoid.getRadii().x * Math.PI;
this._cameraMaxY = this._ellipsoid.getRadii().y * CesiumMath.PI_OVER_TWO;
this._maxCoord = projection.project(new Cartographic3(Math.PI, CesiumMath.toRadians(85.05112878)));

This comment has been minimized.

Copy link
@pjcozzi

pjcozzi Jul 3, 2012

Contributor

Does this assume mercator? Should the projection object be able to return its latitude bounds?

This comment has been minimized.

Copy link
@pjcozzi

pjcozzi Jul 3, 2012

Contributor

Take a look at this, and then this pull request is good to go from my perspective.


this._maxZoomFactor = 2.5;
this._maxTranslateFactor = 1.5;
Expand Down Expand Up @@ -236,7 +235,7 @@ define([
var newRight = frustum.right - moveRate;
var newLeft = frustum.left + moveRate;

var maxRight = this._cameraMaxX * this._maxZoomFactor;
var maxRight = this._maxCoord.x * this._maxZoomFactor;
if (newRight > maxRight) {
newRight = maxRight;
newLeft = -newRight;
Expand Down Expand Up @@ -298,16 +297,16 @@ define([
var currentPosition = camera.position;
var translatedPosition = currentPosition.clone();

if (translatedPosition.x > this._cameraMaxX) {
translatedPosition.x = this._cameraMaxX;
} else if (translatedPosition.x < -this._cameraMaxX) {
translatedPosition.x = -this._cameraMaxX;
if (translatedPosition.x > this._maxCoord.x) {
translatedPosition.x = this._maxCoord.x;
} else if (translatedPosition.x < -this._maxCoord.x) {
translatedPosition.x = -this._maxCoord.x;
}

if (translatedPosition.y > this._cameraMaxY) {
translatedPosition.y = this._cameraMaxY;
} else if (translatedPosition.y < -this._cameraMaxY) {
translatedPosition.y = -this._cameraMaxY;
if (translatedPosition.y > this._maxCoord.y) {
translatedPosition.y = this._maxCoord.y;
} else if (translatedPosition.y < -this._maxCoord.y) {
translatedPosition.y = -this._maxCoord.y;
}

var update2D = function(value) {
Expand Down Expand Up @@ -374,8 +373,8 @@ define([
}

var position = this._camera.position;
var translateX = position.x < -this._cameraMaxX || position.x > this._cameraMaxX;
var translateY = position.y < -this._cameraMaxY || position.y > this._cameraMaxY;
var translateX = position.x < -this._maxCoord.x || position.x > this._maxCoord.x;
var translateY = position.y < -this._maxCoord.y || position.y > this._maxCoord.y;
if ((translateX || translateY) && !this._lastInertiaTranslateMovement &&
!this._animationCollection.contains(this._translateAnimation)) {
this._addCorrectTranslateAnimation();
Expand All @@ -399,16 +398,12 @@ define([
var height = this._canvas.clientHeight;

var start = new Cartesian2();
start.x = (2.0 / width) * movement.startPosition.x - 1.0;
start.x = (start.x * (frustum.right - frustum.left) + frustum.right + frustum.left) * 0.5;
start.y = (2.0 / height) * (height - movement.startPosition.y) - 1.0;
start.y = (start.y * (frustum.top - frustum.bottom) + frustum.top + frustum.bottom) * 0.5;
start.x = (movement.startPosition.x / width) * (frustum.right - frustum.left) + frustum.left;
start.y = ((height - movement.startPosition.y) / height) * (frustum.top - frustum.bottom) + frustum.bottom;

var end = new Cartesian2();
end.x = (2.0 / width) * movement.endPosition.x - 1.0;
end.x = (end.x * (frustum.right - frustum.left) + frustum.right + frustum.left) * 0.5;
end.y = (2.0 / height) * (height - movement.endPosition.y) - 1.0;
end.y = (end.y * (frustum.top - frustum.bottom) + frustum.top + frustum.bottom) * 0.5;
end.x = (movement.endPosition.x / width) * (frustum.right - frustum.left) + frustum.left;
end.y = ((height - movement.endPosition.y) / height) * (frustum.top - frustum.bottom) + frustum.bottom;

var camera = this._camera;
var right = camera.right;
Expand All @@ -421,7 +416,7 @@ define([
position = camera.position;
newPosition = position.add(right.multiplyWithScalar(distance.x));

var maxX = this._cameraMaxX * this._maxTranslateFactor;
var maxX = this._maxCoord.x * this._maxTranslateFactor;
if (newPosition.x > maxX) {
newPosition.x = maxX;
}
Expand All @@ -435,7 +430,7 @@ define([
position = camera.position;
newPosition = position.add(up.multiplyWithScalar(distance.y));

var maxY = this._cameraMaxY * this._maxTranslateFactor;
var maxY = this._maxCoord.y * this._maxTranslateFactor;
if (newPosition.y > maxY) {
newPosition.y = maxY;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/CameraControllerCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ define([
* @see CameraControllerCollection#addSpindle
* @see CameraControllerCollection#addColumbusView
*/
CameraControllerCollection.prototype.add2D = function(ellipsoid) {
var twoD = new Camera2DController(this._canvas, this._camera, ellipsoid);
CameraControllerCollection.prototype.add2D = function(projection) {
var twoD = new Camera2DController(this._canvas, this._camera, projection);
this._controllers.push(twoD);
return twoD;
};
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/SceneTransitioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ define([

var controllers = camera.getControllers();
controllers.removeAll();
controllers.add2D(this._ellipsoid);
controllers.add2D(scene.scene2D.projection);

// TODO: Match incoming columbus-view or 3D position
camera.position = this._camera2D.position.clone();
Expand Down
4 changes: 0 additions & 4 deletions Specs/Scene/CameraControllerCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
defineSuite([
'Scene/CameraControllerCollection',
'Scene/Camera',
'Scene/Camera2DController',
'Scene/CameraFreeLookController',
'Scene/CameraSpindleController',
'Core/Cartographic3',
'Core/Ellipsoid'
], function(
CameraControllerCollection,
Camera,
Camera2DController,
CameraFreeLookController,
CameraSpindleController,
Cartographic3,
Ellipsoid) {
"use strict";
Expand Down

0 comments on commit 21d182f

Please sign in to comment.