don't let users select areas bigger than allowed
authorChristopher Schmidt <crschmidt@crschmidt.net>
Tue, 22 Apr 2008 11:29:24 +0000 (11:29 +0000)
committerChristopher Schmidt <crschmidt@crschmidt.net>
Tue, 22 Apr 2008 11:29:24 +0000 (11:29 +0000)
app/views/browse/start.rjs

index f2196939827d724ba8996ed7f02563f1b7367cb0..963f1c25bf0e57911d89b68a26925ae9b9c0fd6c 100644 (file)
@@ -7,19 +7,21 @@ page << <<EOJ
     OpenLayers.Feature.Vector.style['default'].cursor = "pointer";
     
     function start() {
-      openSidebar({ onclose: stopBrowse });
-      var vectors = new OpenLayers.Layer.Vector();
+        openSidebar({ onclose: stopBrowse });
+        var vectors = new OpenLayers.Layer.Vector();
     
-      box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, { 
-        handlerOptions: {
-          sides: 4,
-          snapAngle: 90,
-          irregular: true,
-          persist: true,
-          callbacks: { done: endDrag }
-        }
-      });
-      map.addControl(box);
+        box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, { 
+          handlerOptions: {
+            sides: 4,
+            snapAngle: 90,
+            irregular: true,
+            persist: true,
+            callbacks: { done: endDrag }
+          }
+        });
+        map.addControl(box);
+        map.events.register("moveend", map, validateLinks);
+        map.events.triggerEvent("moveend");
     }
     
     function stopBrowse() {
@@ -35,6 +37,7 @@ page << <<EOJ
             currentFeature.destroy(); 
             currentFeature = null; 
         } 
+        map.events.unregister("moveend", map, validateLinks);
     }
     
     function startDrag() {
@@ -59,6 +62,7 @@ page << <<EOJ
         getData(bounds);
         $("drag_box").innerHTML = "Manually select a different area";
     }
+    
     function displayFeatureWarning() {
         var div = document.createElement("div");
         var p = document.createElement("p");
@@ -106,11 +110,17 @@ page << <<EOJ
     }
 
     function getData(bounds) {
-        $("status").innerHTML = "Loading...";
         
         bounds.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
+        var size = bounds.getWidth() * bounds.getHeight(); 
+        if (size > 0.25) {
+            $("status").innerHTML = "Unable to load: Bounding box size of " + size + " is too large. (Must be smaller than 0.25)"; 
+            return;
+        }
+
         var url = "/api/0.5/map?bbox="+bounds.toBBOX();
         
+        $("status").innerHTML = "Loading...";
         if (!gml) {
             var def = OpenLayers.Feature.Vector.style['default'];
             var style = new OpenLayers.Style();
@@ -257,6 +267,15 @@ page << <<EOJ
       $("maxlon").innerHTML = Math.round(bounds.right * decimals) / decimals;
       $("maxlat").innerHTML = Math.round(bounds.top * decimals) / decimals;
     }
+    function validateLinks() {
+        var bounds = this.getExtent();
+        bounds = bounds.clone().transform(map.getProjectionObject(), epsg4326);
 
+        if (bounds.getWidth() * bounds.getHeight() > 0.25) {
+          $("use_map").style.display = "none";
+        } else {
+          $("use_map").style.display = "inline";
+        }  
+    }
     start();
 EOJ