maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH] Validate the size of the bounding box with java


From: Gaël Utard
Subject: [Maposmatic-dev] [PATCH] Validate the size of the bounding box with javascript.
Date: Wed, 4 Aug 2010 22:30:00 +0200

Signed-off-by: Gaël Utard <address@hidden>
---
 www/media/osm_map.js              |   25 +++++++++++++++++++++++++
 www/settings_local.py-template    |    4 +++-
 www/templates/maposmatic/new.html |    3 +++
 3 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/www/media/osm_map.js b/www/media/osm_map.js
index f3f6bc1..f13a7e7 100644
--- a/www/media/osm_map.js
+++ b/www/media/osm_map.js
@@ -27,6 +27,12 @@
 
 /* OSM slippy map management. */
 
+/* Maximum length of the bounding box to be rendered. This length is
+ * checked in both directions (longitude and latitude).
+ * Note: if you change this you should probably change
+ * BBOX_MAXIMUM_LENGTH_IN_METERS in settings_local.py too. */
+const BBOX_MAXIMUM_LENGTH_IN_KM = 20
+
 var map = null;
 var update_lock = 0;
 var epsg_display_projection = new OpenLayers.Projection('EPSG:4326');
@@ -52,6 +58,25 @@ function updateFormBbox(bounds)
     getUpperLeftLon().value = bounds.left.toFixed(4);
     getBottomRightLat().value = bounds.bottom.toFixed(4);
     getBottomRightLon().value = bounds.right.toFixed(4);
+
+    upper_left   = new OpenLayers.LonLat(bounds.left, bounds.top);
+    upper_right  = new OpenLayers.LonLat(bounds.right, bounds.top);
+    bottom_right = new OpenLayers.LonLat(bounds.right, bounds.bottom);
+
+    bbox_width  = OpenLayers.Util.distVincenty(upper_left, upper_right)
+    bbox_height = OpenLayers.Util.distVincenty(upper_right, bottom_right)
+
+    if (bbox_width > BBOX_MAXIMUM_LENGTH_IN_KM ||
+        bbox_height > BBOX_MAXIMUM_LENGTH_IN_KM)
+    {
+        document.getElementById('bboxtoolarge').style.display = 'block'
+        document.getElementById('id_go_next_btn').disabled = true
+    }
+    else
+    {
+        document.getElementById('bboxtoolarge').style.display = 'none'
+        document.getElementById('id_go_next_btn').disabled = false
+    }
 }
 
 /* Update the map on form field modification. */
diff --git a/www/settings_local.py-template b/www/settings_local.py-template
index dbdbf3a..9d9705a 100644
--- a/www/settings_local.py-template
+++ b/www/settings_local.py-template
@@ -58,7 +58,9 @@ DEFAULT_MAPOSMATIC_LOG_FORMAT = "%(asctime)s - 
%(name)address@hidden(process)d - %(levelnam
 BASE_BOUNDING_BOX = (51.956, -7.838, 41.458, 11.937)
 
 # Maximum length of the bounding box to be rendered. This length is
-# checked in both directions (longitude and latitude)
+# checked in both directions (longitude and latitude).
+# Note: if you change this you should probably change
+# BBOX_MAXIMUM_LENGTH_IN_KM in osm_map.js too.
 BBOX_MAXIMUM_LENGTH_IN_METERS = 20000
 
 # Number of items displayed per page in the jobs and maps pages
diff --git a/www/templates/maposmatic/new.html 
b/www/templates/maposmatic/new.html
index a883598..0da89f8 100644
--- a/www/templates/maposmatic/new.html
+++ b/www/templates/maposmatic/new.html
@@ -94,6 +94,9 @@ map.{% endblocktrans %}
     <tr class="bybbox field"><td colspan="2">
       {{ form.bbox }}
       {{ form.bbox.errors }}
+      <ul class="errorlist" id="bboxtoolarge" style="display: none">
+        <li>{% blocktrans %}Bounding Box too large{% endblocktrans %}</li>
+      </ul>
       <p class="bbox_select_help">{% blocktrans %}Latitude and longitude of 
the top left and bottom right corners of the area to render.{% endblocktrans 
%}</p>
       <p class="bbox_select_help">{% blocktrans %}You can use 
<tt>Shift+drag</tt> to zoom on a specific area of the map. You can use 
<tt>Control+drag</tt> to draw the limits of the area to render.{% endblocktrans 
%}</p>
     </td></tr>
-- 
1.7.0.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]