1 <% form_tag :action => "finish" do %>
3 <p class="export_heading">Area to Export</p>
5 <div class="export_bounds">
6 <%= text_field_tag('maxlat', nil, :size => 10, :class => "export_bound") %>
8 <%= text_field_tag('minlon', nil, :size => 10, :class => "export_bound") %>
9 <%= text_field_tag('maxlon', nil, :size => 10, :class => "export_bound") %>
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
17 <p class="export_heading">Format to Export</p>
19 <div class="export_details">
21 <%= radio_button_tag("format", "osm") %>OpenStreetMap XML Data
23 <%= radio_button_tag("format", "mapnik") %>Mapnik Image
25 <%= radio_button_tag("format", "osmarender") %>Osmarender Image
30 <p class="export_heading">Licence</p>
32 <div class="export_details">
33 <p>OSM license agreement blah blah blah...</p>
37 <div id="export_mapnik">
38 <p class="export_heading">Options</p>
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>
46 <div id="export_osmarender">
47 <p class="export_heading">Options</p>
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>
55 <div class="export_buttons">
56 <p><%= submit_tag "Export", :id => "export_commit" %></p>
61 <script type="text/javascript">
66 function startExport() {
67 vectors = new OpenLayers.Layer.Vector("Vector Layer", {
68 displayInLayerSwitcher: false,
70 map.addLayer(vectors);
72 box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, {
74 keyMask: OpenLayers.Handler.MOD_CTRL,
79 callbacks: { done: boxComplete }
86 map.events.register("moveend", map, mapMoved);
88 $("viewanchor").className = "";
89 $("exportanchor").className = "active";
91 openSidebar({ onclose: stopExport });
93 updateRegion(map.getExtent());
96 function stopExport() {
97 $("viewanchor").className = "active";
98 $("exportanchor").className = "";
100 map.events.unregister("moveend", map, mapMoved);
102 map.removeLayer(vectors);
105 function formatChanged() {
106 if ($("format_osm").checked) {
107 $("export_osm").style.display = "inline";
109 $("export_osm").style.display = "none";
112 if ($("format_mapnik").checked) {
113 $("mapnik_scale").value = roundScale(map.getScale());
114 $("export_mapnik").style.display = "inline";
116 $("export_mapnik").style.display = "none";
119 if ($("format_osmarender").checked) {
120 var zoom = Math.min(map.getZoom(), maxOsmarenderZoom());
122 $("osmarender_zoom").options.selectedIndex = zoom - 4;
123 $("export_osmarender").style.display = "inline";
125 $("export_osmarender").style.display = "none";
129 $("format_osm").onclick = function() { formatChanged() };
130 $("format_mapnik").onclick = function() { formatChanged() };
131 $("format_osmarender").onclick = function() { formatChanged() };
133 function boundsChanged() {
134 var epsg4326 = new OpenLayers.Projection("EPSG:4326");
135 var bounds = new OpenLayers.Bounds($("minlon").value,
140 bounds.transform(epsg4326, map.getProjectionObject());
142 map.events.unregister("moveend", map, mapMoved);
143 map.zoomToExtent(bounds);
146 box.handler.feature = new OpenLayers.Feature.Vector(bounds.toGeometry());
147 box.handler.layer.addFeatures([box.handler.feature], [box.handler.style]);
148 box.handler.layer.drawFeature(box.handler.feature, box.handler.style);
151 $("maxlat").onchange = function() { boundsChanged() };
152 $("minlon").onchange = function() { boundsChanged() };
153 $("maxlon").onchange = function() { boundsChanged() };
154 $("minlat").onchange = function() { boundsChanged() };
156 function mapMoved() {
157 updateRegion(map.getExtent());
160 function boxComplete(box) {
161 map.events.unregister("moveend", map, mapMoved);
162 updateRegion(box.getBounds());
165 function updateRegion(bounds) {
166 var epsg4326 = new OpenLayers.Projection("EPSG:4326");
167 var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
169 bounds.transform(map.getProjectionObject(), epsg4326);
171 $("minlon").value = Math.round(bounds.left * decimals) / decimals;
172 $("minlat").value = Math.round(bounds.bottom * decimals) / decimals;
173 $("maxlon").value = Math.round(bounds.right * decimals) / decimals;
174 $("maxlat").value = Math.round(bounds.top * decimals) / decimals;
176 if (bounds.getWidth() * bounds.getHeight() > 0.25) {
177 $("format_osm").disabled = true;
178 $("format_osm").checked = false;
182 $("format_osm").disabled = false;
185 var max_zoom = maxOsmarenderZoom();
186 var max_scale = maxMapnikScale();
188 $("max_scale").innerHTML = roundScale(max_scale);
190 for (var o = 0; o < $("osmarender_zoom").options.length; o++) {
191 var option = $("osmarender_zoom").options[o];
193 if (option.value > max_zoom) {
194 option.disabled = true;
196 option.disabled = false;
200 if ($("osmarender_zoom").options.selectedIndex + 4 > max_zoom) {
201 $("osmarender_zoom").options.selectedIndex = max_zoom - 4;
205 function maxMapnikScale() {
206 var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
207 var epsg4326 = new OpenLayers.Projection("EPSG:4326");
208 var epsg900913 = new OpenLayers.Projection("EPSG:900913");
210 bounds.transform(epsg4326, epsg900913);
212 return Math.floor(Math.sqrt(bounds.getWidth() * bounds.getHeight() / 0.3136));
215 function maxOsmarenderZoom() {
216 var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
217 var xzoom = Math.LOG2E * Math.log(2000 * 1.40625 / bounds.getWidth());
218 var ymin = bounds.bottom * Math.PI / 180;
219 var ymax = bounds.top * Math.PI / 180;
220 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)))))
222 return Math.floor(Math.min(xzoom, yzoom));
225 function roundScale(scale) {
226 var precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2);
228 return precision * Math.ceil(scale / precision);
231 function validateScale() {
232 if ($("mapnik_scale").value < maxMapnikScale()) {
233 $("export_commit").disabled = true;
235 $("export_commit").disabled = false;
239 $("mapnik_scale").onchange = function() { validateScale() };