]> dev.renevier.net Git - syp.git/blobdiff - js/syp.js
option to show popup near marker or on a corner
[syp.git] / js / syp.js
index 40735c791cbb516ea273c0fe40a0e85d58ecb28b..c3613873523bb999d0e220a896c81de7d7127475 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
@@ -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.