Browse Source

When pointing to an azimuth outside of the panorama, stick to the nearest edge of the picture

Baptiste Jonglez 9 years ago
parent
commit
26a271f108
2 changed files with 15 additions and 6 deletions
  1. 0 4
      TODO
  2. 15 2
      panorama/static/panorama/js/pano.js

+ 0 - 4
TODO

@@ -8,10 +8,6 @@ Basic functionalities:
 
 Bugfix:
 
-- when specifying a given cap and elevation (e.g. "url#zoom=X/cap=42/ele=0"
-  or using the control box), if the image does not loop and the given position
-  is outside the image, it should be cropped to the nearest image boundary.
-
 - when the image does not loop, it should be displayed only once in the
   interface (right now, it loops, which is ugly and impractical)
 

+ 15 - 2
panorama/static/panorama/js/pano.js

@@ -14,6 +14,8 @@ var ntiles = {x:228, y:9};
 var border_width = 2;
 var imageObj = new Array();
 
+// minimum and maximum azimuth
+var alpha_domain = {start:0, end:360};
 
 var fingr = 0;  // mémorisation de lécart entre doigts;
 var last  = {x:0,y:0};
@@ -505,7 +507,7 @@ function tzoom(zv) {
 	                  || image_loop && (ord_pts.length > 0);
 
 
-	    var alpha_domain = {start:0, end:360};
+	    alpha_domain = {start:0, end:360};
 	    this.pixel_y_ratio = this.im.width/360;
 	    if (is_located) {
 		    this.ref_pixels = new Array;
@@ -670,7 +672,18 @@ function tzoom(zv) {
 		    var px = this.ref_pixels[i].x + this.ref_pixels[i].ratio_x*fmodulo(cap - this.ref_pixels[i].cap, 360);
 		    var dpix = px-this.ref_pixels[i].x;
 		    var py = this.pixel_y_ratio*ele - this.ref_pixels[i].shift_y - this.ref_pixels[i].dshft_y*dpix;
-		    return {x:px, y:py};
+                    if (dcap < fmodulo(alpha_domain.end - alpha_domain.start, 360))
+                        // Position is inside the view
+		        return {x: px, y: py};
+                    else {
+                        // Position is outside the view, find out which edge is closest
+                        if (fmodulo(alpha_domain.start - cap, 360) < fmodulo(cap - alpha_domain.end, 360))
+                            // Left edge
+                            return {x: 0, y: py};
+                        else
+                            // Right edge
+                            return {x: image_width - 1, y: py};
+                    }
 		}
 	    }
 	} else {