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
--- /dev/null
+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
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
--- /dev/null
+module ExportHelper
+end
--- /dev/null
+<% form_tag :action => "finish" do %>
+
+ <p class="export_heading">Area to Export</p>
+
+ <div class="export_bounds">
+ <%= text_field_tag('maxlat', nil, :size => 10, :class => "export_bound") %>
+ <br/>
+ <%= text_field_tag('minlon', nil, :size => 10, :class => "export_bound") %>
+ <%= text_field_tag('maxlon', nil, :size => 10, :class => "export_bound") %>
+ <br/>
+ <%= text_field_tag('minlat', nil, :size => 10, :class => "export_bound") %>
+ <p class="export_hint">
+ Drag a box with control held down to select an area to export
+ </p>
+ </div>
+
+ <p class="export_heading">Format to Export</p>
+
+ <div class="export_details">
+ <p>
+ <%= radio_button_tag("format", "osm") %>OpenStreetMap XML Data
+ <br/>
+ <%= radio_button_tag("format", "mapnik") %>Mapnik Image
+ <br/>
+ <%= radio_button_tag("format", "osmarender") %>Osmarender Image
+ </p>
+ </div>
+
+ <div id="export_osm">
+ <p class="export_heading">Licence</p>
+
+ <div class="export_details">
+ <p>OpenStreetMap data is licensed under the <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons Attribution-ShareAlike 2.0 license</a>.</p>
+ </div>
+ </div>
+
+ <div id="export_mapnik">
+ <p class="export_heading">Options</p>
+
+ <div class="export_details">
+ <p>Format <%= select_tag("mapnik_format", options_for_select([["PNG", "png"], ["JPEG", "jpeg"], ["SVG", "svg"], ["PDF", "pdf"], ["Postscript", "ps"]], "png")) %></p>
+ <p>Scale 1 : <%= text_field_tag("mapnik_scale", nil, :size => 8) %> <span class="export_hint">(max 1 : <span id="mapnik_max_scale"></span>)</span></p>
+ <p>Image Size <span id="mapnik_image_width"></span> x <span id="mapnik_image_height"></span></p>
+ </div>
+ </div>
+
+ <div id="export_osmarender">
+ <p class="export_heading">Options</p>
+
+ <div class="export_details">
+ <p>Format <%= select_tag("osmarender_format", options_for_select([["PNG", "png"], ["JPEG", "jpeg"]], "png")) %></p>
+ <p>Zoom <%= select_tag("osmarender_zoom", options_for_select([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])) %></p>
+ </div>
+ </div>
+
+ <div class="export_buttons">
+ <p><%= submit_tag "Export", :id => "export_commit" %></p>
+ </div>
+
+<% end %>
--- /dev/null
+page.replace_html :sidebar_title, 'Export'
+page.replace_html :sidebar_content, :partial => 'start'
+page << <<EOJ
+ var vectors;
+ var box;
+
+ function startExport() {
+ vectors = new OpenLayers.Layer.Vector("Vector Layer", {
+ displayInLayerSwitcher: false
+ });
+ map.addLayer(vectors);
+
+ box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, {
+ handlerOptions: {
+ keyMask: OpenLayers.Handler.MOD_CTRL,
+ sides: 4,
+ snapAngle: 90,
+ irregular: true,
+ persist: true,
+ callbacks: { done: boxComplete }
+ }
+ });
+ map.addControl(box);
+
+ box.activate();
+
+ map.events.register("moveend", map, mapMoved);
+
+ openSidebar({ onclose: stopExport });
+
+ updateRegion(map.getExtent());
+
+ if (map.baseLayer.name == "Mapnik") {
+ $("format_mapnik").checked = true;
+ } else if (map.baseLayer.name == "Osmarender") {
+ $("format_osmarender").checked = true;
+ }
+
+ formatChanged();
+
+ $("viewanchor").className = "";
+ $("exportanchor").className = "active";
+ }
+
+ function stopExport() {
+ $("viewanchor").className = "active";
+ $("exportanchor").className = "";
+
+ map.events.unregister("moveend", map, mapMoved);
+ box.handler.clear();
+ map.removeLayer(vectors);
+ }
+
+ function formatChanged() {
+ if ($("format_osm").checked) {
+ $("export_osm").style.display = "inline";
+ } else {
+ $("export_osm").style.display = "none";
+ }
+
+ if ($("format_mapnik").checked) {
+ $("mapnik_scale").value = roundScale(map.getScale());
+ $("export_mapnik").style.display = "inline";
+
+ mapnikScaleChanged();
+ } else {
+ $("export_mapnik").style.display = "none";
+ }
+
+ if ($("format_osmarender").checked) {
+ var zoom = Math.min(map.getZoom(), maxOsmarenderZoom());
+
+ $("osmarender_zoom").options.selectedIndex = zoom - 4;
+ $("export_osmarender").style.display = "inline";
+ } else {
+ $("export_osmarender").style.display = "none";
+ }
+ }
+
+ $("format_osm").onclick = formatChanged;
+ $("format_mapnik").onclick = formatChanged;
+ $("format_osmarender").onclick = formatChanged;
+
+ function boundsChanged() {
+ var epsg4326 = new OpenLayers.Projection("EPSG:4326");
+ var bounds = new OpenLayers.Bounds($("minlon").value,
+ $("minlat").value,
+ $("maxlon").value,
+ $("maxlat").value);
+
+ bounds.transform(epsg4326, map.getProjectionObject());
+
+ map.events.unregister("moveend", map, mapMoved);
+ map.zoomToExtent(bounds);
+
+ box.handler.clear();
+ box.handler.feature = new OpenLayers.Feature.Vector(bounds.toGeometry());
+ box.handler.layer.addFeatures([box.handler.feature], [box.handler.style]);
+ box.handler.layer.drawFeature(box.handler.feature, box.handler.style);
+
+ mapnikSizeChanged();
+ }
+
+ $("maxlat").onchange = boundsChanged;
+ $("minlon").onchange = boundsChanged;
+ $("maxlon").onchange = boundsChanged;
+ $("minlat").onchange = boundsChanged;
+
+ function mapMoved() {
+ updateRegion(map.getExtent());
+ }
+
+ function boxComplete(box) {
+ map.events.unregister("moveend", map, mapMoved);
+ updateRegion(box.getBounds());
+ }
+
+ function updateRegion(bounds) {
+ var epsg4326 = new OpenLayers.Projection("EPSG:4326");
+ var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
+
+ bounds.transform(map.getProjectionObject(), epsg4326);
+
+ $("minlon").value = Math.round(bounds.left * decimals) / decimals;
+ $("minlat").value = Math.round(bounds.bottom * decimals) / decimals;
+ $("maxlon").value = Math.round(bounds.right * decimals) / decimals;
+ $("maxlat").value = Math.round(bounds.top * decimals) / decimals;
+
+ if (bounds.getWidth() * bounds.getHeight() > 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
<%
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'
%>
- <li><%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps', :class => viewclass } %></li>
- <li><%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps', :class => editclass } %></li>
- <li><%= link_to 'GPS traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces', :class => traceclass } %></li>
+ <li><%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps', :class => viewclass} %></li>
+ <li><%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps', :class => editclass} %></li>
+ <li><%= link_to_remote 'Export', {:url => {:controller => 'export', :action => 'start'}}, {:id => 'exportanchor', :title => 'export map data', :class => exportclass, :href => url_for(:controller => 'site', :action => 'export')} %></li>
+ <li><%= link_to 'GPS Traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces', :class => traceclass} %></li>
+ <li><%= link_to 'User Diaries', {:controller => 'diary_entry', :action => 'list'}, {:id => 'diaryanchor', :title => 'view user diaries', :class => diaryclass} %></li>
</ul>
</div>
<div id="left_menu" class="left_menu">
<a href="http://wiki.openstreetmap.org">Help & Wiki</a><br />
- <%= link_to "Users' diaries", {:controller => 'diary_entry', :action => 'list', :display_name => nil} %><br />
<a href="http://www.opengeodata.org/">News blog</a><br />
<a href="http://wiki.openstreetmap.org/index.php/Merchandise">Shop</a><br />
<%= yield :left_menu %>
else { var imgname = 'keymapnik13.png'; }
updateSidebar("Map key", "<p><img src='images/"+imgname+"' /></p>");
- openSidebar("210px");
+ openSidebar({ width: "210px" });
}
function updateKey() {
<script type="text/javascript">
<!--
- function openSidebar() {
- if (arguments.length) { $("sidebar").style.width = arguments[0]; }
+ var onclose;
+
+ function openSidebar(options) {
+ if (onclose) {
+ onclose();
+ onclose = null;
+ }
+
+ if (options.width) { $("sidebar").style.width = options.width; }
else { $("sidebar").style.width = "30%"; }
$("sidebar").style.display = "block";
<%= onopen %>
+
+ onclose = options.onclose;
}
function closeSidebar() {
$("sidebar").style.display = "none";
<%= onclose %>
+
+ if (onclose) {
+ onclose();
+ onclose = null;
+ }
}
function updateSidebar(title, content) {
window.onload = handleResize;
window.onresize = handleResize;
+
+ <% if params['action'] == 'export' %>
+ <%= remote_function :url => { :controller => 'export', :action => 'start' } %>
+ <% end %>
// -->
</script>
# 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'
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'
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
--- /dev/null
+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
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.ScaleLine()
],
+ maxResolution: 156543,
units: "m"
});
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");
+ }
}
}
}
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) {
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");';
list-style: square;
}
-input {
+input[type="text"] {
border: 1px solid black;
}
#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;
+}