From: Tom Hughes Date: Sat, 19 Apr 2008 13:14:30 +0000 (+0000) Subject: Merge 7296:7427 from export branch to trunk. X-Git-Tag: live~8878 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/c8bf26711c935aa14af1cfd72d8badc39b130f85?hp=f4fa8ed40e608105bac8fa06da3695c688327b51 Merge 7296:7427 from export branch to trunk. --- 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 +

+
+ +
+

Licence

+ +
+

OpenStreetMap data is licensed under the Creative Commons Attribution-ShareAlike 2.0 license.

+
+
+ +
+

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])) %>

+
+
+ +
+

<%= submit_tag "Export", :id => "export_commit" %>

+
+ +<% 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 @@
    Help & Wiki
    - <%= link_to "Users' diaries", {:controller => 'diary_entry', :action => 'list', :display_name => nil} %>
    News blog
    Shop
    <%= yield :left_menu %> diff --git a/app/views/site/_key.rhtml b/app/views/site/_key.rhtml index c6b6fe29a..643099498 100644 --- a/app/views/site/_key.rhtml +++ b/app/views/site/_key.rhtml @@ -12,7 +12,7 @@ else { var imgname = 'keymapnik13.png'; } updateSidebar("Map key", "

    "); - openSidebar("210px"); + openSidebar({ width: "210px" }); } function updateKey() { diff --git a/app/views/site/_sidebar.rhtml b/app/views/site/_sidebar.rhtml index 7addbe177..d81363590 100644 --- a/app/views/site/_sidebar.rhtml +++ b/app/views/site/_sidebar.rhtml @@ -11,19 +11,33 @@ diff --git a/config/routes.rb b/config/routes.rb index 1d3a13565..0a0396251 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,13 +57,21 @@ ActionController::Routing::Routes.draw do |map| # web site map.connect '/', :controller => 'site', :action => 'index' + map.connect '/edit', :controller => 'site', :action => 'edit' + map.connect '/export', :controller => 'site', :action => 'export' + map.connect '/login', :controller => 'user', :action => 'login' + map.connect '/logout', :controller => 'user', :action => 'logout' + map.connect '/user/new', :controller => 'user', :action => 'new' map.connect '/user/save', :controller => 'user', :action => 'save' map.connect '/user/confirm', :controller => 'user', :action => 'confirm' map.connect '/user/go_public', :controller => 'user', :action => 'go_public' - map.connect '/user/reset_password', :controller => 'user', :action => 'reset_password' - map.connect '/user/upload_image', :controller => 'user', :action => 'upload_image' + map.connect '/user/reset-password', :controller => 'user', :action => 'reset_password' + map.connect '/user/upload-image', :controller => 'user', :action => 'upload_image' + map.connect '/user/forgot-password', :controller => 'user', :action => 'lost_password' + map.connect '/index.html', :controller => 'site', :action => 'index' map.connect '/edit.html', :controller => 'site', :action => 'edit' + map.connect '/export.html', :controller => 'site', :action => 'export' map.connect '/search.html', :controller => 'way_tag', :action => 'search' map.connect '/login.html', :controller => 'user', :action => 'login' map.connect '/logout.html', :controller => 'user', :action => 'logout' @@ -121,6 +129,10 @@ ActionController::Routing::Routes.draw do |map| map.connect '/geocoder/search', :controller => 'geocoder', :action => 'search' map.connect '/geocoder/description', :controller => 'geocoder', :action => 'description' + # export + map.connect '/export/start', :controller => 'export', :action => 'start' + map.connect '/export/finish', :controller => 'export', :action => 'finish' + # messages map.connect '/user/:display_name/inbox', :controller => 'message', :action => 'inbox' @@ -131,6 +143,6 @@ ActionController::Routing::Routes.draw do |map| map.connect '/message/reply/:message_id', :controller => 'message', :action => 'reply' # fall through - map.connect ':controller/:id/:action' + map.connect ':controller/:id/:action' map.connect ':controller/:action' end diff --git a/lib/bounding_box.rb b/lib/bounding_box.rb new file mode 100644 index 000000000..d943768ad --- /dev/null +++ b/lib/bounding_box.rb @@ -0,0 +1,72 @@ +class BoundingBox + def initialize(min_lon, min_lat, max_lon, max_lat) + @bbox = [min_lon.to_f, min_lat.to_f, max_lon.to_f, max_lat.to_f] + end + + def self.from_s(s) + BoundingBox.new(s.split(/,/)) + end + + def min_lon + @bbox[0] + end + + def min_lon=(min_lon) + @bbox[0] = min_lon + end + + def min_lat + @bbox[1] + end + + def min_lat=(min_lat) + @bbox[1] = min_lat + end + + def max_lon + @bbox[2] + end + + def max_lon=(max_lon) + @bbox[2] = max_lon + end + + def max_lat + @bbox[3] + end + + def max_lat=(max_lat) + @bbox[3] = max_lat + end + + def centre_lon + (@bbox[0] + @bbox[2]) / 2.0 + end + + def centre_lat + (@bbox[1] + @bbox[3]) / 2.0 + end + + def width + @bbox[2] - @bbox[0] + end + + def height + @bbox[3] - @bbox[1] + end + + def slippy_width(zoom) + width * 256.0 * 2.0 ** zoom / 360.0 + end + + def slippy_height(zoom) + min = min_lat * Math::PI / 180.0 + max = max_lat * Math::PI / 180.0 + + Math.log((Math.tan(max) + 1.0 / Math.cos(max)) / (Math.tan(min) + 1.0 / Math.cos(min))) * 128.0 * 2.0 ** zoom / Math::PI + end + + def to_s + return @bbox.join(",") + end +end diff --git a/public/javascripts/map.js b/public/javascripts/map.js index d8765fe1a..51cd9f6a5 100644 --- a/public/javascripts/map.js +++ b/public/javascripts/map.js @@ -17,6 +17,7 @@ function createMap(divName) { new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.ScaleLine() ], + maxResolution: 156543, units: "m" }); @@ -130,12 +131,15 @@ function getMapLayers() { function setMapLayers(layers) { for (var i=0; i < layers.length; i++) { var layer = map.layers[i]; - var c = layers.charAt(i); - if (c == "B") { - map.setBaseLayer(layer); - } else if ( (c == "T") || (c == "F") ) { - layer.setVisibility(c == "T"); + if (layer) { + var c = layers.charAt(i); + + if (c == "B") { + map.setBaseLayer(layer); + } else if ( (c == "T") || (c == "F") ) { + layer.setVisibility(c == "T"); + } } } } diff --git a/public/javascripts/site.js b/public/javascripts/site.js index 6fb68e65a..95c0b938e 100644 --- a/public/javascripts/site.js +++ b/public/javascripts/site.js @@ -29,6 +29,18 @@ function updatelinks(lon,lat,zoom,layers) { node.href = setArgs(node.href, args); } + node = document.getElementById("exportanchor"); + if (node) { + var args = getArgs(node.href); + args["lat"] = lat; + args["lon"] = lon; + args["zoom"] = zoom; + if (layers) { + args["layers"] = layers; + } + node.href = setArgs(node.href, args); + } + node = document.getElementById("editanchor"); if (node) { if (zoom >= 11) { @@ -36,7 +48,7 @@ function updatelinks(lon,lat,zoom,layers) { args.lat = lat; args.lon = lon; args.zoom = zoom; - node.href = setArgs("/edit.html", args); + node.href = setArgs("/edit", args); node.style.fontStyle = 'normal'; } else { node.href = 'javascript:alert("zoom in to edit map");'; diff --git a/public/stylesheets/site.css b/public/stylesheets/site.css index f2306e7b4..c7f1b0085 100644 --- a/public/stylesheets/site.css +++ b/public/stylesheets/site.css @@ -525,7 +525,7 @@ hides rule from IE5-Mac \*/ list-style: square; } -input { +input[type="text"] { border: 1px solid black; } @@ -580,3 +580,45 @@ input { #attribution { display: none; } + +.export_heading { + margin: 0px; + padding: 3px 6px 3px 6px; + border: 1px solid #ccc; + background: #ddd; +} + +.export_bounds { + width: 100%; + text-align: center; +} + +.export_bound { + margin: 5px; +} + +.export_details { + padding: 2px 6px 2px 6px; +} + +#export_osm { + display: none; +} + +#export_mapnik { + display: none; +} + +#export_osmarender { + display: none; +} + +.export_hint { + padding: 0px 12px 0px 12px; + font-style: italic; +} + +.export_buttons { + width: 100%; + text-align: center; +}