diff --git a/example1.js b/example1.js index 66be2840c..51b278a30 100644 --- a/example1.js +++ b/example1.js @@ -53,6 +53,9 @@ function upload() { // Display the navigation bar navbar: true, + // Set max tilt angle + tilt_up_max: 40, + // Resize the panorama size: { width: '100%', diff --git a/photo-sphere-viewer.js b/photo-sphere-viewer.js index 6850a7e50..012952e36 100644 --- a/photo-sphere-viewer.js +++ b/photo-sphere-viewer.js @@ -41,6 +41,8 @@ * - navbar_style (Object) (optional) ({}) Style of the navigation bar * - loading_img (string) (optional) (null) Loading image URL or path (absolute or relative) * - size (Object) (optional) (null) Final size of the panorama container (e.g. {width: 500, height: 300}) + * - tilt_up_max (number) (optional) (90) The maximum tilt up angle between 0 and 90 + * - tilt_down_max (number) (optional) (90) The maximum tilt down angle between 0 and 90 **/ var PhotoSphereViewer = function(args) { @@ -91,6 +93,21 @@ var PhotoSphereViewer = function(args) { return Math.max(min, Math.min(max, x)); } + /** + * Set maximum tilt up and down angle + * @param phi + * @returns phi + */ + + var setTiltAngle = function (phi){ + if (phi > TILT_UP_MAX) { + phi = TILT_UP_MAX; + } else if (phi < TILT_DOWN_MAX) { + phi = TILT_DOWN_MAX; + } + return phi; + }; + /** * Starts to load the panorama * @return (void) @@ -558,7 +575,7 @@ var PhotoSphereViewer = function(args) { theta -= Math.floor(theta / (2.0 * Math.PI)) * 2.0 * Math.PI; phi += (y - mouse_y) * PSV_LAT_OFFSET; phi = stayBetween(phi, -Math.PI / 2.0, Math.PI / 2.0) - + phi = setTiltAngle(phi); mouse_x = x; mouse_y = y; render(); @@ -814,6 +831,10 @@ var PhotoSphereViewer = function(args) { // Minimal and maximal fields of view in degrees var PSV_FOV_MIN = (args.min_fov !== undefined) ? stayBetween(parseFloat(args.min_fov), 1, 179) : 30; var PSV_FOV_MAX = (args.max_fov !== undefined) ? stayBetween(parseFloat(args.max_fov), 1, 179) : 90; + + // Maximum tilt up / down angle + var TILT_UP_MAX = (args.tilt_up_max !== undefined) ? (Math.PI / 180) * args.tilt_up_max : Math.PI/2.0; + var TILT_DOWN_MAX = (args.tilt_down_max !== undefined) ? -(Math.PI / 180) * args.tilt_down_max : -Math.PI/2.0; // Animation constants var PSV_FRAMES_PER_SECOND = 60;