]> git.openstreetmap.org Git - rails.git/blob - app/views/export/_start.rhtml
749928c124ff9d580fe07154eee933fdb060f09f
[rails.git] / app / views / export / _start.rhtml
1 <% form_tag :action => "finish" do %>
2
3   <p class="export_heading">Area to Export</p>
4
5   <div class="export_bounds">
6     <%= text_field_tag('maxlat', nil, :size => 10, :class => "export_bound") %>
7     <br/>
8     <%= text_field_tag('minlon', nil, :size => 10, :class => "export_bound") %>
9     <%= text_field_tag('maxlon', nil, :size => 10, :class => "export_bound") %>
10     <br/>
11     <%= text_field_tag('minlat', nil, :size => 10, :class => "export_bound") %>
12     <p class="export_hint">
13       Drag a box with control held down to select an area to export
14     </p>
15   </div>
16
17   <p class="export_heading">Format to Export</p>
18
19   <div class="export_details">
20     <p>
21       <%= radio_button_tag("format", "osm") %>OpenStreetMap XML Data
22       <br/>
23       <%= radio_button_tag("format", "mapnik") %>Mapnik Image
24       <br/>
25       <%= radio_button_tag("format", "osmarender") %>Osmarender Image
26     </p>
27   </div>
28
29   <div id="export_osm">
30     <p class="export_heading">Licence</p>
31
32     <div class="export_details">
33       <p>OSM license agreement blah blah blah...</p>
34     </div
35   </div>
36
37   <div id="export_mapnik">
38     <p class="export_heading">Options</p>
39
40     <div class="export_details">
41       <p>Format <%= select_tag("mapnik_format", options_for_select([["PNG", "png"], ["JPEG", "jpeg"], ["SVG", "svg"], ["PDF", "pdf"], ["Postscript", "ps"]], "png")) %></p>
42       <p>Scale 1 : <%= text_field_tag("mapnik_scale", nil, :size => 8) %> <span class="export_hint">(max 1 : <span id="max_scale"></span>)</span></p>
43     </div>
44   </div>
45
46   <div id="export_osmarender">
47     <p class="export_heading">Options</p>
48
49     <div class="export_details">
50       <p>Format <%= select_tag("osmarender_format", options_for_select([["PNG", "png"], ["JPEG", "jpeg"]], "png")) %></p>
51       <p>Zoom <%= select_tag("osmarender_zoom", options_for_select([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])) %></p>
52     </div>
53   </div>
54
55   <div class="export_buttons">
56     <p><%= submit_tag "Export", :id => "export_commit" %></p>
57   </div>
58
59 <% end %>
60
61 <script type="text/javascript">
62   <!--
63   var box;
64
65   function startExport() {
66     var vectors = new OpenLayers.Layer.Vector("Vector Layer", {
67       displayInLayerSwitcher: false,
68     });
69     map.addLayer(vectors);
70
71     box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, { 
72       handlerOptions: {
73         keyMask: OpenLayers.Handler.MOD_CTRL,
74         sides: 4,
75         snapAngle: 90,
76         irregular: true,
77         persist: true,
78         callbacks: { done: boxComplete }
79       }
80     });
81     map.addControl(box);
82
83     box.activate();
84
85     map.events.register("moveend", map, mapMoved);
86     updateRegion(map.getExtent());
87   }
88
89   function formatChanged() {
90     if ($("format_osm").checked) {
91       $("export_osm").style.display = "inline";
92     } else {
93       $("export_osm").style.display = "none";
94     }
95
96     if ($("format_mapnik").checked) {
97       $("mapnik_scale").value = roundScale(map.getScale());
98       $("export_mapnik").style.display = "inline";
99     } else {
100       $("export_mapnik").style.display = "none";
101     }
102
103     if ($("format_osmarender").checked) {
104       var zoom = Math.min(map.getZoom(), maxOsmarenderZoom());
105
106       $("osmarender_zoom").options.selectedIndex = zoom - 4;
107       $("export_osmarender").style.display = "inline";
108     } else {
109       $("export_osmarender").style.display = "none";
110     }
111   }
112
113   $("format_osm").onclick = function() { formatChanged() };
114   $("format_mapnik").onclick = function() { formatChanged() };
115   $("format_osmarender").onclick = function() { formatChanged() };
116
117   function boundsChanged() {
118     var epsg4326 = new OpenLayers.Projection("EPSG:4326");
119     var bounds = new OpenLayers.Bounds($("minlon").value,
120                                        $("minlat").value,
121                                        $("maxlon").value,
122                                        $("maxlat").value);
123  
124     bounds.transform(epsg4326, map.getProjectionObject());
125
126     map.events.unregister("moveend", map, mapMoved);
127     map.zoomToExtent(bounds);
128
129     box.handler.clear();
130     box.handler.feature = new OpenLayers.Feature.Vector(bounds.toGeometry());
131     box.handler.layer.addFeatures([box.handler.feature], [box.handler.style]);
132     box.handler.layer.drawFeature(box.handler.feature, box.handler.style);
133   }
134
135   $("maxlat").onchange = function() { boundsChanged() };
136   $("minlon").onchange = function() { boundsChanged() };
137   $("maxlon").onchange = function() { boundsChanged() };
138   $("minlat").onchange = function() { boundsChanged() };
139
140   function mapMoved() {
141     updateRegion(map.getExtent());
142   }
143
144   function boxComplete(box) {
145     map.events.unregister("moveend", map, mapMoved);
146     updateRegion(box.getBounds());
147   }
148
149   function updateRegion(bounds) {
150     var epsg4326 = new OpenLayers.Projection("EPSG:4326");
151     var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
152
153     bounds.transform(map.getProjectionObject(), epsg4326);
154
155     $("minlon").value = Math.round(bounds.left * decimals) / decimals;
156     $("minlat").value = Math.round(bounds.bottom * decimals) / decimals;
157     $("maxlon").value = Math.round(bounds.right * decimals) / decimals;
158     $("maxlat").value = Math.round(bounds.top * decimals) / decimals;
159
160     if (bounds.getWidth() * bounds.getHeight() > 0.25) {
161       $("format_osm").disabled = true;
162       $("format_osm").checked = false;
163
164       formatChanged();
165     } else {
166       $("format_osm").disabled = false;
167     }
168     
169     var max_zoom = maxOsmarenderZoom();
170     var max_scale = maxMapnikScale();
171
172     $("max_scale").innerHTML = roundScale(max_scale);
173
174     for (var o = 0; o < $("osmarender_zoom").options.length; o++) {
175       var option = $("osmarender_zoom").options[o];
176
177       if (option.value > max_zoom) {
178         option.disabled = true;
179       } else {
180         option.disabled = false;
181       }
182     }
183
184     if ($("osmarender_zoom").options.selectedIndex + 4 > max_zoom) {
185       $("osmarender_zoom").options.selectedIndex = max_zoom - 4;
186     }
187   }
188
189   function maxMapnikScale() {
190     var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
191     var epsg4326 = new OpenLayers.Projection("EPSG:4326");
192     var epsg900913 = new OpenLayers.Projection("EPSG:900913");
193
194     bounds.transform(epsg4326, epsg900913);
195
196     return Math.floor(Math.sqrt(bounds.getWidth() * bounds.getHeight() / 0.3136));
197   }
198
199   function maxOsmarenderZoom() {
200     var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
201     var xzoom = Math.LOG2E * Math.log(2000 * 1.40625 / bounds.getWidth());
202     var ymin = bounds.bottom * Math.PI / 180;
203     var ymax = bounds.top * Math.PI / 180;
204     var yzoom = Math.LOG2E * (Math.log(2000 * 2 * Math.PI) - Math.log(Math.log((Math.tan(ymax) + 1 / Math.cos(ymax)) / (Math.tan(ymin) + 1 / Math.cos(ymin)))))
205
206     return Math.floor(Math.min(xzoom, yzoom));
207   }
208
209   function roundScale(scale) {
210     var precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2);
211
212     return precision * Math.ceil(scale / precision);
213   }
214
215   function validateScale() {
216     if ($("mapnik_scale").value < maxMapnikScale()) {
217       $("export_commit").disabled = true;
218     } else {
219       $("export_commit").disabled = false;
220     }
221   }
222
223   $("mapnik_scale").onchange = function() { validateScale() };
224
225   startExport();
226   // -->
227 </script>