]> git.openstreetmap.org Git - rails.git/blobdiff - app/views/export/_start.rhtml
Reflect any changes made to the bounds in the map.
[rails.git] / app / views / export / _start.rhtml
index 41fd790f2f5d539895cb337ee68b8e37f8e503f0..e63b87c565c3a763ffb6953e66d34d69fc1f4e68 100644 (file)
 
 <script type="text/javascript">
   <!--
+  var box;
+
   function startExport() {
     var vectors = new OpenLayers.Layer.Vector("Vector Layer", {
       displayInLayerSwitcher: false,
     });
     map.addLayer(vectors);
 
-    var box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, { 
+    box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, { 
       handlerOptions: {
         keyMask: OpenLayers.Handler.MOD_CTRL,
         sides: 4,
     updateRegion(map.getExtent());
   }
 
-  function setFormat(format) {
-    $("export_osm").style.display = "none";
-    $("export_mapnik").style.display = "none";
-    $("export_" + format).style.display = "inline";
+  function formatChanged() {
+    if ($("export_format_osm").checked) {
+      $("export_osm").style.display = "inline";
+    } else {
+      $("export_osm").style.display = "none";
+    }
+
+    if ($("export_format_png").checked ||
+        $("export_format_pdf").checked ||
+        $("export_format_svg").checked) {
+      $("export_mapnik").style.display = "inline";
+    } else {
+      $("export_mapnik").style.display = "none";
+    }
+  }
+
+  $("export_format_osm").onclick = function() { formatChanged() };
+  $("export_format_png").onclick = function() { formatChanged() };
+  $("export_format_pdf").onclick = function() { formatChanged() };
+  $("export_format_svg").onclick = function() { formatChanged() };
+
+  function boundsChanged() {
+    var epsg4326 = new OpenLayers.Projection("EPSG:4326");
+    var bounds = new OpenLayers.Bounds($("export_minlon").value,
+                                       $("export_minlat").value,
+                                       $("export_maxlon").value,
+                                       $("export_maxlat").value);
+    bounds.transform(epsg4326, map.getProjectionObject());
+
+    map.events.unregister("moveend", map, mapMoved);
+    map.zoomToExtent(bounds);
+
+    box.handler.clear();
+    box.handler.feature = new OpenLayers.Feature.Vector(bounds.toGeometry());
+    box.handler.layer.addFeatures([box.handler.feature], [box.handler.style]);
+    box.handler.layer.drawFeature(box.handler.feature, box.handler.style);
   }
 
-  $("export_format_osm").onclick = function() { setFormat("osm") };
-  $("export_format_png").onclick = function() { setFormat("mapnik") };
-  $("export_format_pdf").onclick = function() { setFormat("mapnik") };
-  $("export_format_svg").onclick = function() { setFormat("mapnik") };
+  $("export_maxlat").onchange = function() { boundsChanged() };
+  $("export_minlon").onchange = function() { boundsChanged() };
+  $("export_maxlon").onchange = function() { boundsChanged() };
+  $("export_minlat").onchange = function() { boundsChanged() };
 
   function mapMoved() {
     updateRegion(map.getExtent());
   }
 
   function updateRegion(bounds) {
+    var epsg4326 = new OpenLayers.Projection("EPSG:4326");
     var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
-    var bl = mercatorToLonLat(new OpenLayers.LonLat(bounds.left, bounds.bottom));
-    var tr = mercatorToLonLat(new OpenLayers.LonLat(bounds.right, bounds.top));
 
-    $("export_maxlat").value = Math.round(tr.lat * decimals) / decimals;
-    $("export_minlon").value = Math.round(bl.lon * decimals) / decimals;
-    $("export_maxlon").value = Math.round(tr.lon * decimals) / decimals;
-    $("export_minlat").value = Math.round(bl.lat * decimals) / decimals;
+    bounds.transform(map.getProjectionObject(), epsg4326);
+
+    $("export_maxlat").value = Math.round(bounds.top * decimals) / decimals;
+    $("export_minlon").value = Math.round(bounds.left * decimals) / decimals;
+    $("export_maxlon").value = Math.round(bounds.right * decimals) / decimals;
+    $("export_minlat").value = Math.round(bounds.bottom * decimals) / decimals;
+
+    if (bounds.getWidth() * bounds.getHeight() > 0.25) {
+      $("export_format_osm").disabled = true;
+      $("export_format_osm").checked = false;
+
+      formatChanged();
+    } else {
+      $("export_format_osm").disabled = false;
+    }
   }
 
   startExport();