]> dev.renevier.net Git - syp.git/blobdiff - js/syp.js
compute position for close button once full screen image has been correctly sized
[syp.git] / js / syp.js
index 40735c791cbb516ea273c0fe40a0e85d58ecb28b..6c59dcdd3bbe55d5a7866530ae73eb0c879a3b33 100644 (file)
--- a/js/syp.js
+++ b/js/syp.js
@@ -184,10 +184,25 @@ var SYP = {
         var popup = feature.popup;
 
         var popupPos = null;
-        if (sypSettings.popupNearfeature) {
-            popupPos = feature.geometry.getBounds().getCenterLonLat();
-        } else {
-            popupPos = SYP.Utils.brCorner(map, 8);
+        switch (sypSettings.popupPos) {
+            case 0:
+                popupPos = feature.geometry.getBounds().getCenterLonLat();
+            break;
+            case 1:
+                popupPos = SYP.Utils.tlCorner(map, 8);
+            break;
+            case 2:
+                popupPos = SYP.Utils.trCorner(map, 8);
+            break;
+            case 3:
+                popupPos = SYP.Utils.brCorner(map, 8);
+            break;
+            case 4:
+                popupPos = SYP.Utils.blCorner(map, 8);
+            break;
+            default:
+                popupPos = SYP.Utils.brCorner(map, 8);
+           break;
         }
 
         // we cannot reuse popup; we need to recreate it in order for IE
@@ -238,10 +253,6 @@ var SYP = {
         document.getElementById('bigimg').style.maxHeight = maxHeight + "px";
         document.getElementById('bigimg').style.maxWidth = maxWidth + "px";
         document.getElementById('bigimg').onload = function () {
-            var icon = document.getElementById('bigimg_close');
-            icon.style.top = this.offsetTop;
-            icon.style.left = this.offsetLeft + this.clientWidth - icon.clientWidth;
-
             var heightRatio = this.clientHeight / parseInt(this.style.maxHeight);
             var widthRatio = this.clientWidth / parseInt(this.style.maxWidth);
             if (heightRatio > 1 || widthRatio > 1) {
@@ -252,6 +263,10 @@ var SYP = {
                 }
             }
 
+            var icon = document.getElementById('bigimg_close');
+            icon.style.top = this.offsetTop;
+            icon.style.left = this.offsetLeft + this.clientWidth - icon.clientWidth;
+
         };
         document.getElementById('bigimg').src = href;
     },
@@ -263,13 +278,36 @@ var SYP = {
     },
 
     Utils: {
+        tlCorner: function(map, margin) {
+            var bounds = map.calculateBounds();
+            var corner = new OpenLayers.LonLat(bounds.left, bounds.top);
+            var cornerAsPx = map.getPixelFromLonLat(corner);
+            cornerAsPx = cornerAsPx.add( +margin, +margin);
+            return map.getLonLatFromPixel(cornerAsPx);
+        },
+
+        trCorner: function(map, margin) {
+            var bounds = map.calculateBounds();
+            var corner = new OpenLayers.LonLat(bounds.right, bounds.top);
+            var cornerAsPx = map.getPixelFromLonLat(corner);
+            cornerAsPx = cornerAsPx.add( -margin, +margin);
+            return map.getLonLatFromPixel(cornerAsPx);
+        },
+
         brCorner: function(map, margin) {
             var bounds = map.calculateBounds();
             var corner = new OpenLayers.LonLat(bounds.right, bounds.bottom);
             var cornerAsPx = map.getPixelFromLonLat(corner);
             cornerAsPx = cornerAsPx.add( -margin, -margin);
-            corner = map.getLonLatFromPixel(cornerAsPx);
-            return corner;
+            return map.getLonLatFromPixel(cornerAsPx);
+        },
+
+        blCorner: function(map, margin) {
+            var bounds = map.calculateBounds();
+            var corner = new OpenLayers.LonLat(bounds.left, bounds.bottom);
+            var cornerAsPx = map.getPixelFromLonLat(corner);
+            cornerAsPx = cornerAsPx.add( +margin, -margin);
+            return map.getLonLatFromPixel(cornerAsPx);
         },
 
         /* minimum bounds rectangle containing all feature locations.