]> git.openstreetmap.org Git - rails.git/blob - app/views/export/_start.rhtml
Disable OSM export when the area is too large.
[rails.git] / app / views / export / _start.rhtml
1 <% form_tag :action => 'next' do %>
2
3   <p class="export_heading">Area to Export</p>
4
5   <div class="export_bounds">
6     <%= text_field('export', 'maxlat', { :size => 10, :class => "export_bound" }) %>
7     <br/>
8     <%= text_field('export', 'minlon', { :size => 10, :class => "export_bound" }) %>
9     <%= text_field('export', 'maxlon', { :size => 10, :class => "export_bound" }) %>
10     <br/>
11     <%= text_field('export', 'minlat', { :size => 10, :class => "export_bound" }) %>
12   </div>
13
14   <p class="export_heading">Format to Export</p>
15
16   <div class="export_details">
17     <%= radio_button('export', 'format', 'osm' ) %>OpenStreetMap XML Data
18     <br/>
19     <%= radio_button('export', 'format', 'png' ) %>PNG Image
20     <br/>
21     <%= radio_button('export', 'format', 'pdf' ) %>PDF Document
22     <br/>
23     <%= radio_button('export', 'format', 'svg' ) %>SVG Document
24   </div>
25
26   <div id="export_osm">
27     <p class="export_heading">Licence</p>
28
29     <div class="export_details">
30       <p>OSM license agreement blah blah blah...</p>
31     </div
32   </div>
33
34   <div id="export_mapnik">
35     <p class="export_heading">Options</p>
36
37     <div class="export_details">
38       <p>Scale 1 : <%= text_field('export', 'mapnik_scale', { :size => 10 }) %></p>
39     </div>
40   </div>
41
42 <% end %>
43
44 <script type="text/javascript">
45   <!--
46   function startExport() {
47     var vectors = new OpenLayers.Layer.Vector("Vector Layer", {
48       displayInLayerSwitcher: false,
49     });
50     map.addLayer(vectors);
51
52     var box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, { 
53       handlerOptions: {
54         keyMask: OpenLayers.Handler.MOD_CTRL,
55         sides: 4,
56         snapAngle: 90,
57         irregular: true,
58         persist: true,
59         callbacks: { done: boxComplete }
60       }
61     });
62     map.addControl(box);
63
64     box.activate();
65
66     map.events.register("moveend", map, mapMoved);
67     updateRegion(map.getExtent());
68   }
69
70   function formatChanged() {
71     if ($("export_format_osm").checked) {
72       $("export_osm").style.display = "inline";
73     } else {
74       $("export_osm").style.display = "none";
75     }
76
77     if ($("export_format_png").checked ||
78         $("export_format_pdf").checked ||
79         $("export_format_svg").checked) {
80       $("export_mapnik").style.display = "inline";
81     } else {
82       $("export_mapnik").style.display = "none";
83     }
84   }
85
86   $("export_format_osm").onclick = function() { formatChanged() };
87   $("export_format_png").onclick = function() { formatChanged() };
88   $("export_format_pdf").onclick = function() { formatChanged() };
89   $("export_format_svg").onclick = function() { formatChanged() };
90
91   function mapMoved() {
92     updateRegion(map.getExtent());
93   }
94
95   function boxComplete(box) {
96     map.events.unregister("moveend", map, mapMoved);
97     updateRegion(box.getBounds());
98   }
99
100   function updateRegion(bounds) {
101     var epsg4326 = new OpenLayers.Projection("EPSG:4326");
102     var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
103
104     bounds.transform(map.getProjectionObject(), epsg4326);
105
106     $("export_maxlat").value = Math.round(bounds.top * decimals) / decimals;
107     $("export_minlon").value = Math.round(bounds.left * decimals) / decimals;
108     $("export_maxlon").value = Math.round(bounds.right * decimals) / decimals;
109     $("export_minlat").value = Math.round(bounds.bottom * decimals) / decimals;
110
111     if (bounds.getWidth() * bounds.getHeight() > 0.25) {
112       $("export_format_osm").disabled = true;
113       $("export_format_osm").checked = false;
114
115       formatChanged();
116     } else {
117       $("export_format_osm").disabled = false;
118     }
119   }
120
121   startExport();
122   // -->
123 </script>