diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 3350e733c..3ef5e753a 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -79,8 +79,9 @@ class ApiController < ApplicationController
exit!
end
- render :text => doc.to_s, :content_type => "text/xml"
+ response.headers("Content-Disposition") = "attachment; filename=\"map.osm\""
+ render :text => doc.to_s, :content_type => "text/xml"
end
def map
diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb
new file mode 100644
index 000000000..a773d4b72
--- /dev/null
+++ b/app/controllers/export_controller.rb
@@ -0,0 +1,25 @@
+class ExportController < ApplicationController
+ def start
+ end
+
+ def finish
+ bbox = BoundingBox.new(params[:minlon], params[:minlat], params[:maxlon], params[:maxlat])
+ format = params[:format]
+
+ if format == "osm"
+ redirect_to "http://api.openstreetmap.org/api/#{API_VERSION}/map?bbox=#{bbox}"
+ elsif format == "mapnik"
+ format = params[:mapnik_format]
+ scale = params[:mapnik_scale]
+
+ redirect_to "http://tile.openstreetmap.org/cgi-bin/export?bbox=#{bbox}&scale=#{scale}&format=#{format}"
+ elsif format == "osmarender"
+ format = params[:osmarender_format]
+ zoom = params[:osmarender_zoom].to_i
+ width = bbox.slippy_width(zoom).to_i
+ height = bbox.slippy_height(zoom).to_i
+
+ redirect_to "http://tah.openstreetmap.org/MapOf/index.php?long=#{bbox.centre_lon}&lat=#{bbox.centre_lat}&z=#{zoom}&w=#{width}&h=#{height}&format=#{format}"
+ end
+ end
+end
diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb
index 767220c79..4b22e46fd 100644
--- a/app/controllers/site_controller.rb
+++ b/app/controllers/site_controller.rb
@@ -2,15 +2,7 @@ class SiteController < ApplicationController
before_filter :authorize_web
before_filter :require_user, :only => [:edit]
- def goto_way
- way = Way.find(params[:id])
-
- begin
- node = way.way_nodes.first.node
- redirect_to :controller => 'site', :action => 'index', :lat => node.latitude, :lon => node.longitude, :zoom => 6
- rescue
- redirect_to :back
- end
+ def export
+ render :action => 'index'
end
-
end
diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb
new file mode 100644
index 000000000..34acf5f1a
--- /dev/null
+++ b/app/helpers/export_helper.rb
@@ -0,0 +1,2 @@
+module ExportHelper
+end
diff --git a/app/views/export/_start.rhtml b/app/views/export/_start.rhtml
new file mode 100644
index 000000000..969b8efc7
--- /dev/null
+++ b/app/views/export/_start.rhtml
@@ -0,0 +1,60 @@
+<% form_tag :action => "finish" do %>
+
+
Area to Export
+
+
+ <%= text_field_tag('maxlat', nil, :size => 10, :class => "export_bound") %>
+
+ <%= text_field_tag('minlon', nil, :size => 10, :class => "export_bound") %>
+ <%= text_field_tag('maxlon', nil, :size => 10, :class => "export_bound") %>
+
+ <%= text_field_tag('minlat', nil, :size => 10, :class => "export_bound") %>
+
+ Drag a box with control held down to select an area to export
+
+
+
+ Format to Export
+
+
+
+ <%= radio_button_tag("format", "osm") %>OpenStreetMap XML Data
+
+ <%= radio_button_tag("format", "mapnik") %>Mapnik Image
+
+ <%= radio_button_tag("format", "osmarender") %>Osmarender Image
+
+
+
+
+
+
+
Options
+
+
+
Format <%= select_tag("mapnik_format", options_for_select([["PNG", "png"], ["JPEG", "jpeg"], ["SVG", "svg"], ["PDF", "pdf"], ["Postscript", "ps"]], "png")) %>
+
Scale 1 : <%= text_field_tag("mapnik_scale", nil, :size => 8) %> (max 1 : )
+
Image Size x
+
+
+
+
+
Options
+
+
+
Format <%= select_tag("osmarender_format", options_for_select([["PNG", "png"], ["JPEG", "jpeg"]], "png")) %>
+
Zoom <%= select_tag("osmarender_zoom", options_for_select([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])) %>
+
+
+
+
+
+<% end %>
diff --git a/app/views/export/start.rjs b/app/views/export/start.rjs
new file mode 100644
index 000000000..2796d92fe
--- /dev/null
+++ b/app/views/export/start.rjs
@@ -0,0 +1,216 @@
+page.replace_html :sidebar_title, 'Export'
+page.replace_html :sidebar_content, :partial => 'start'
+page << < 0.25) {
+ $("format_osm").disabled = true;
+ $("format_osm").checked = false;
+ $("export_osm").style.display = "none";
+ } else {
+ $("format_osm").disabled = false;
+ }
+
+ var max_zoom = maxOsmarenderZoom();
+ var max_scale = maxMapnikScale();
+
+ $("mapnik_max_scale").innerHTML = roundScale(max_scale);
+
+ mapnikScaleChanged();
+
+ for (var o = 0; o < $("osmarender_zoom").options.length; o++) {
+ var option = $("osmarender_zoom").options[o];
+
+ if (option.value > max_zoom) {
+ option.disabled = true;
+ } else {
+ option.disabled = false;
+ }
+ }
+
+ if ($("osmarender_zoom").options.selectedIndex + 4 > max_zoom) {
+ $("osmarender_zoom").options.selectedIndex = max_zoom - 4;
+ }
+ }
+
+ function maxMapnikScale() {
+ var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
+ var epsg4326 = new OpenLayers.Projection("EPSG:4326");
+ var epsg900913 = new OpenLayers.Projection("EPSG:900913");
+
+ bounds.transform(epsg4326, epsg900913);
+
+ return Math.floor(Math.sqrt(bounds.getWidth() * bounds.getHeight() / 0.3136));
+ }
+
+ function mapnikImageSize(scale) {
+ var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
+ var epsg4326 = new OpenLayers.Projection("EPSG:4326");
+ var epsg900913 = new OpenLayers.Projection("EPSG:900913");
+
+ bounds.transform(epsg4326, epsg900913);
+
+ return new OpenLayers.Size(Math.round(bounds.getWidth() / scale / 0.00028),
+ Math.round(bounds.getHeight() / scale / 0.00028));
+ }
+
+ function maxOsmarenderZoom() {
+ var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
+ var xzoom = Math.LOG2E * Math.log(2000 * 1.40625 / bounds.getWidth());
+ var ymin = bounds.bottom * Math.PI / 180;
+ var ymax = bounds.top * Math.PI / 180;
+ 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)))))
+
+ return Math.floor(Math.min(xzoom, yzoom));
+ }
+
+ function roundScale(scale) {
+ var precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2);
+
+ return precision * Math.ceil(scale / precision);
+ }
+
+ function mapnikSizeChanged() {
+ var size = mapnikImageSize($("mapnik_scale").value);
+
+ $("mapnik_image_width").innerHTML = size.w;
+ $("mapnik_image_height").innerHTML = size.h;
+ }
+
+ function mapnikScaleChanged() {
+ mapnikSizeChanged();
+
+ if ($("mapnik_scale").value < maxMapnikScale()) {
+ $("export_commit").disabled = true;
+ } else {
+ $("export_commit").disabled = false;
+ }
+ }
+
+ $("mapnik_scale").onchange = mapnikScaleChanged;
+
+ startExport();
+EOJ
diff --git a/app/views/layouts/site.rhtml b/app/views/layouts/site.rhtml
index bcb479cca..073b76388 100644
--- a/app/views/layouts/site.rhtml
+++ b/app/views/layouts/site.rhtml
@@ -36,15 +36,19 @@
<%
viewclass = ''
editclass = ''
+ exportclass = ''
traceclass = ''
viewclass = 'active' if params['controller'] == 'site' and params['action'] == 'index'
editclass = 'active' if params['controller'] == 'site' and params['action'] == 'edit'
- editclass = 'active' if params['controller'] == 'campaign'
+ exportclass = 'active' if params['controller'] == 'site' and params['action'] == 'export'
traceclass = 'active' if params['controller'] == 'trace'
+ diaryclass = 'active' if params['controller'] == 'diary_entry'
%>
- <%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps', :class => viewclass } %>
- <%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps', :class => editclass } %>
- <%= link_to 'GPS traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces', :class => traceclass } %>
+ <%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps', :class => viewclass} %>
+ <%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps', :class => editclass} %>
+ <%= link_to_remote 'Export', {:url => {:controller => 'export', :action => 'start'}}, {:id => 'exportanchor', :title => 'export map data', :class => exportclass, :href => url_for(:controller => 'site', :action => 'export')} %>
+ <%= link_to 'GPS Traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces', :class => traceclass} %>
+ <%= link_to 'User Diaries', {:controller => 'diary_entry', :action => 'list'}, {:id => 'diaryanchor', :title => 'view user diaries', :class => diaryclass} %>
@@ -82,7 +86,6 @@