Skip to content

Commit

Permalink
Keep map scale by adopting field of view on view port resize
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed Sep 29, 2022
1 parent 163aa21 commit 1fcbab5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/BasicWorldWindowController.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ define([
// Clamp tilt to between 0 and +90 to prevent the viewer from going upside down.
lookAt.tilt = WWMath.clamp(lookAt.tilt, 0, 90);

// Normalize heading to between -180 and +180.
// Normalize roll to between -180 and +180.
lookAt.roll = Angle.normalizedDegrees(lookAt.roll);

// Apply 2D limits when the globe is 2D.
Expand Down
15 changes: 12 additions & 3 deletions src/WorldWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ define([
* @type {Rectangle}
* @readonly
*/
this.viewport = new Rectangle(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
this.viewport = new Rectangle(0, 0, 0, 0);

/**
* The globe displayed.
Expand Down Expand Up @@ -811,13 +811,22 @@ define([
width = gl.canvas.clientWidth * this.pixelScale,
height = gl.canvas.clientHeight * this.pixelScale;

if (gl.canvas.width != width ||
gl.canvas.height != height) {
if (gl.canvas.width != width || gl.canvas.height != height
|| this.viewport.width === 0 || this.viewport.height === 0) {

// Make the canvas drawing buffer size match its screen size.
gl.canvas.width = width;
gl.canvas.height = height;

// Keep map scale by adopting field of view on view port resize
if (this.viewport.height !== 0) {
try {
this.camera.fieldOfView *= height / this.viewport.height;
} catch (ignore) {
// Keep original field of view in case new one does not fit requirements
}
}

// Set the WebGL viewport to match the canvas drawing buffer size.
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
this.viewport = new Rectangle(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
Expand Down
23 changes: 21 additions & 2 deletions src/geom/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ define([

/**
* Camera tilt, in degrees.
* @type {Number}
* @default 0
*/
this.tilt = 0;
Expand All @@ -53,13 +54,31 @@ define([
*/
this.roll = 0;

// Intentionally not documented
this._fieldOfView = 45;
};

Object.defineProperties(Camera.prototype, {
/**
* Camera vertical field of view, in degrees
* @type {Number}
* @default 45
* @throws {ArgumentError} If the specified field of view is out of range.
*/
this.fieldOfView = 45;
};
fieldOfView: {
get: function () {
return this._fieldOfView;
},
set: function (value) {
if (value <= 0 || value => 180) {
throw new ArgumentError(
Logger.logMessage(Logger.LEVEL_SEVERE, "Camera", "setFieldOfView", "Invalid field of view")
);
}
this._fieldOfView = value;
}
}
});

/**
* Indicates whether the components of this object are equal to those of a specified object.
Expand Down

0 comments on commit 1fcbab5

Please sign in to comment.