]> git.openstreetmap.org Git - rails.git/blob - app/views/export/_start.rhtml
Switch export branch to use OpenLayers 2.6-rc1 as we need irregular polygons.
[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 setFormat(format) {
71     $("export_osm").style.display = "none";
72     $("export_mapnik").style.display = "none";
73     $("export_" + format).style.display = "inline";
74   }
75
76   $("export_format_osm").onclick = function() { setFormat("osm") };
77   $("export_format_png").onclick = function() { setFormat("mapnik") };
78   $("export_format_pdf").onclick = function() { setFormat("mapnik") };
79   $("export_format_svg").onclick = function() { setFormat("mapnik") };
80
81   function mapMoved() {
82     updateRegion(map.getExtent());
83   }
84
85   function boxComplete(box) {
86     map.events.unregister("moveend", map, mapMoved);
87     updateRegion(box.getBounds());
88   }
89
90   function updateRegion(bounds) {
91     var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
92     var bl = mercatorToLonLat(new OpenLayers.LonLat(bounds.left, bounds.bottom));
93     var tr = mercatorToLonLat(new OpenLayers.LonLat(bounds.right, bounds.top));
94
95     $("export_maxlat").value = Math.round(tr.lat * decimals) / decimals;
96     $("export_minlon").value = Math.round(bl.lon * decimals) / decimals;
97     $("export_maxlon").value = Math.round(tr.lon * decimals) / decimals;
98     $("export_minlat").value = Math.round(bl.lat * decimals) / decimals;
99   }
100
101   startExport();
102   // -->
103 </script>