diff --git a/src/viewer/scene/camera/Ortho.js b/src/viewer/scene/camera/Ortho.js index 04e237c27c..c842f8e9d0 100755 --- a/src/viewer/scene/camera/Ortho.js +++ b/src/viewer/scene/camera/Ortho.js @@ -51,6 +51,7 @@ class Ortho extends Component { this.scale = cfg.scale; this.near = cfg.near; this.far = cfg.far; + this.scaleAxis = cfg.scaleAxis ?? "max"; this._onCanvasBoundary = this.scene.canvas.on("boundary", this._needUpdate, this); } @@ -74,7 +75,7 @@ class Ortho extends Component { let top; let bottom; - if (boundaryWidth > boundaryHeight) { + if (this._scaleAxis === "x" || ((this._scaleAxis === "max") && (boundaryWidth > boundaryHeight))) { left = -halfSize; right = halfSize; top = halfSize / aspect; @@ -133,6 +134,43 @@ class Ortho extends Component { return this._scale; } + /** + * Sets Ortho's scale axis. + * + * If it's not set = max scale axis is enabled. + * + * Possible values: + * + * "max" = scale would be applied for longer dimension available (either horizontal or vertical), + * + * "x" = scale is applied in horizontal dimension, + * + * "y" = scale is applied in vertical dimension. + * + * @param {String} value New scale axis value. + */ + set scaleAxis(value) { + if (value === "max" || value === "y" || value === "x") { + this._scaleAxis = value; + } + else { + console.error("Ortho.js Camera scaleAxis not recognized, setting to \"max\"."); + this._scaleAxis = "max"; + } + + this._needUpdate(0); + this.fire("scaleAxis", this._scaleAxis); + } + + /** + * Gets scale axis. + * + * @returns {String} Scale axis. + */ + get scaleAxis() { + return this._scaleAxis; + } + /** * Sets the position of the Ortho's near plane on the positive View-space Z-axis. * diff --git a/types/viewer/scene/camera/Ortho.d.ts b/types/viewer/scene/camera/Ortho.d.ts index ffa175a66e..0ed5017f88 100644 --- a/types/viewer/scene/camera/Ortho.d.ts +++ b/types/viewer/scene/camera/Ortho.d.ts @@ -37,6 +37,30 @@ export declare class Ortho extends Component { */ get scale(): number; + /** + * Sets Ortho's scale axis. + * + * If it's not set = max scale axis is enabled. + * + * Possible values: + * + * "max" = scale would be applied for longer dimension available (either horizontal or vertical), + * + * "x" = scale is applied in horizontal dimension, + * + * "y" = scale is applied in vertical dimension. + * + * @param {String} value New scale axis value. + */ + set scaleAxis(arg: string); + + /** + * Gets scale axis. + * + * @returns {String} Scale axis. + */ + get scaleAxis(): string; + /** * Sets the position of the Ortho's near plane on the positive View-space Z-axis. *