Skip to content

Commit 1fcbab5

Browse files
committed
Keep map scale by adopting field of view on view port resize
1 parent 163aa21 commit 1fcbab5

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

src/BasicWorldWindowController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ define([
457457
// Clamp tilt to between 0 and +90 to prevent the viewer from going upside down.
458458
lookAt.tilt = WWMath.clamp(lookAt.tilt, 0, 90);
459459

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

463463
// Apply 2D limits when the globe is 2D.

src/WorldWindow.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ define([
175175
* @type {Rectangle}
176176
* @readonly
177177
*/
178-
this.viewport = new Rectangle(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
178+
this.viewport = new Rectangle(0, 0, 0, 0);
179179

180180
/**
181181
* The globe displayed.
@@ -811,13 +811,22 @@ define([
811811
width = gl.canvas.clientWidth * this.pixelScale,
812812
height = gl.canvas.clientHeight * this.pixelScale;
813813

814-
if (gl.canvas.width != width ||
815-
gl.canvas.height != height) {
814+
if (gl.canvas.width != width || gl.canvas.height != height
815+
|| this.viewport.width === 0 || this.viewport.height === 0) {
816816

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

821+
// Keep map scale by adopting field of view on view port resize
822+
if (this.viewport.height !== 0) {
823+
try {
824+
this.camera.fieldOfView *= height / this.viewport.height;
825+
} catch (ignore) {
826+
// Keep original field of view in case new one does not fit requirements
827+
}
828+
}
829+
821830
// Set the WebGL viewport to match the canvas drawing buffer size.
822831
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
823832
this.viewport = new Rectangle(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);

src/geom/Camera.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ define([
4242

4343
/**
4444
* Camera tilt, in degrees.
45+
* @type {Number}
4546
* @default 0
4647
*/
4748
this.tilt = 0;
@@ -53,13 +54,31 @@ define([
5354
*/
5455
this.roll = 0;
5556

57+
// Intentionally not documented
58+
this._fieldOfView = 45;
59+
};
60+
61+
Object.defineProperties(Camera.prototype, {
5662
/**
5763
* Camera vertical field of view, in degrees
5864
* @type {Number}
5965
* @default 45
66+
* @throws {ArgumentError} If the specified field of view is out of range.
6067
*/
61-
this.fieldOfView = 45;
62-
};
68+
fieldOfView: {
69+
get: function () {
70+
return this._fieldOfView;
71+
},
72+
set: function (value) {
73+
if (value <= 0 || value => 180) {
74+
throw new ArgumentError(
75+
Logger.logMessage(Logger.LEVEL_SEVERE, "Camera", "setFieldOfView", "Invalid field of view")
76+
);
77+
}
78+
this._fieldOfView = value;
79+
}
80+
}
81+
});
6382

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

0 commit comments

Comments
 (0)