Commit initial work on export tab.
This commit is contained in:
parent
b95e10ac8f
commit
1df50231fa
7 changed files with 307 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
|||
class ExportController < ApplicationController
|
||||
def start
|
||||
render :update do |page|
|
||||
page.replace_html :sidebar_title, 'Export'
|
||||
page.replace_html :sidebar_content, :partial => 'start'
|
||||
page.call "openSidebar"
|
||||
end
|
||||
|
|
103
app/views/export/_start.rhtml
Normal file
103
app/views/export/_start.rhtml
Normal file
|
@ -0,0 +1,103 @@
|
|||
<% form_tag :action => 'next' do %>
|
||||
|
||||
<p class="export_heading">Area to Export</p>
|
||||
|
||||
<div class="export_bounds">
|
||||
<%= text_field('export', 'maxlat', { :size => 10, :class => "export_bound" }) %>
|
||||
<br/>
|
||||
<%= text_field('export', 'minlon', { :size => 10, :class => "export_bound" }) %>
|
||||
<%= text_field('export', 'maxlon', { :size => 10, :class => "export_bound" }) %>
|
||||
<br/>
|
||||
<%= text_field('export', 'minlat', { :size => 10, :class => "export_bound" }) %>
|
||||
</div>
|
||||
|
||||
<p class="export_heading">Format to Export</p>
|
||||
|
||||
<div class="export_details">
|
||||
<%= radio_button('export', 'format', 'osm' ) %>OpenStreetMap XML Data
|
||||
<br/>
|
||||
<%= radio_button('export', 'format', 'png' ) %>PNG Image
|
||||
<br/>
|
||||
<%= radio_button('export', 'format', 'pdf' ) %>PDF Document
|
||||
<br/>
|
||||
<%= radio_button('export', 'format', 'svg' ) %>SVG Document
|
||||
</div>
|
||||
|
||||
<div id="export_osm">
|
||||
<p class="export_heading">Licence</p>
|
||||
|
||||
<div class="export_details">
|
||||
<p>OSM license agreement blah blah blah...</p>
|
||||
</div
|
||||
</div>
|
||||
|
||||
<div id="export_mapnik">
|
||||
<p class="export_heading">Options</p>
|
||||
|
||||
<div class="export_details">
|
||||
<p>Scale 1 : <%= text_field('export', 'mapnik_scale', { :size => 10 }) %></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
function startExport() {
|
||||
var vectors = new OpenLayers.Layer.Vector("Vector Layer", {
|
||||
displayInLayerSwitcher: false,
|
||||
});
|
||||
map.addLayer(vectors);
|
||||
|
||||
var 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);
|
||||
updateRegion(map.getExtent());
|
||||
}
|
||||
|
||||
function setFormat(format) {
|
||||
$("export_osm").style.display = "none";
|
||||
$("export_mapnik").style.display = "none";
|
||||
$("export_" + format).style.display = "inline";
|
||||
}
|
||||
|
||||
$("export_format_osm").onclick = function() { setFormat("osm") };
|
||||
$("export_format_png").onclick = function() { setFormat("mapnik") };
|
||||
$("export_format_pdf").onclick = function() { setFormat("mapnik") };
|
||||
$("export_format_svg").onclick = function() { setFormat("mapnik") };
|
||||
|
||||
function mapMoved() {
|
||||
updateRegion(map.getExtent());
|
||||
}
|
||||
|
||||
function boxComplete(box) {
|
||||
map.events.unregister("moveend", map, mapMoved);
|
||||
updateRegion(box.getBounds());
|
||||
}
|
||||
|
||||
function updateRegion(bounds) {
|
||||
var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
|
||||
var bl = mercatorToLonLat(new OpenLayers.LonLat(bounds.left, bounds.bottom));
|
||||
var tr = mercatorToLonLat(new OpenLayers.LonLat(bounds.right, bounds.top));
|
||||
|
||||
$("export_maxlat").value = Math.round(tr.lat * decimals) / decimals;
|
||||
$("export_minlon").value = Math.round(bl.lon * decimals) / decimals;
|
||||
$("export_maxlon").value = Math.round(tr.lon * decimals) / decimals;
|
||||
$("export_minlat").value = Math.round(bl.lat * decimals) / decimals;
|
||||
}
|
||||
|
||||
startExport();
|
||||
// -->
|
||||
</script>
|
|
@ -36,14 +36,16 @@
|
|||
<%
|
||||
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'
|
||||
%>
|
||||
<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 'Export', {:controller => 'site', :action => 'export'}, {:id => 'exportanchor', :title => 'export map data', :class => exportclass } %></li>
|
||||
<li><%= link_to 'GPS traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces', :class => traceclass } %></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
162
app/views/site/export.rhtml
Normal file
162
app/views/site/export.rhtml
Normal file
|
@ -0,0 +1,162 @@
|
|||
<% content_for :greeting do %>
|
||||
<% if @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
|
||||
<%= link_to_function 'home', "setPosition(#{@user.home_lat}, #{@user.home_lon}, 10)" %> |
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
|
||||
|
||||
<div id="map">
|
||||
</div>
|
||||
|
||||
<% if params['mlon'] and params['mlat'] %>
|
||||
<% marker = true %>
|
||||
<% mlon = h(params['mlon']) %>
|
||||
<% mlat = h(params['mlat']) %>
|
||||
<% end %>
|
||||
|
||||
<% if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat'] %>
|
||||
<% bbox = true %>
|
||||
<% minlon = h(params['minlon']) %>
|
||||
<% minlat = h(params['minlat']) %>
|
||||
<% maxlon = h(params['maxlon']) %>
|
||||
<% maxlat = h(params['maxlat']) %>
|
||||
<% end %>
|
||||
|
||||
<% if params['lon'] and params['lat'] %>
|
||||
<% lon = h(params['lon']) %>
|
||||
<% lat = h(params['lat']) %>
|
||||
<% zoom = h(params['zoom'] || '5') %>
|
||||
<% layers = h(params['layers']) %>
|
||||
<% elsif params['mlon'] and params['mlat'] %>
|
||||
<% lon = h(params['mlon']) %>
|
||||
<% lat = h(params['mlat']) %>
|
||||
<% zoom = h(params['zoom'] || '12') %>
|
||||
<% layers = h(params['layers']) %>
|
||||
<% elsif cookies.key?("location") %>
|
||||
<% lon,lat,zoom,layers = cookies["location"].split(",") %>
|
||||
<% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
|
||||
<% lon = @user.home_lon %>
|
||||
<% lat = @user.home_lat %>
|
||||
<% zoom = '10' %>
|
||||
<% else %>
|
||||
<% session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location] %>
|
||||
<% if session[:location] %>
|
||||
<% bbox = true %>
|
||||
<% minlon = session[:location][:minlon] %>
|
||||
<% minlat = session[:location][:minlat] %>
|
||||
<% maxlon = session[:location][:maxlon] %>
|
||||
<% maxlat = session[:location][:maxlat] %>
|
||||
<% else %>
|
||||
<% lon = '-0.1' %>
|
||||
<% lat = '51.5' %>
|
||||
<% zoom = h(params['zoom'] || '5') %>
|
||||
<% layers = h(params['layers']) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= javascript_include_tag '/openlayers/OpenLayers.js' %>
|
||||
<%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
|
||||
<%= javascript_include_tag 'map.js' %>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
var brokenContentSize = $("content").offsetWidth == 0;
|
||||
var marker;
|
||||
var map;
|
||||
function init(){
|
||||
map = createMap("map");
|
||||
|
||||
<% if bbox %>
|
||||
var min = lonLatToMercator(new OpenLayers.LonLat(<%= minlon %>, <%= minlat %>));
|
||||
var max = lonLatToMercator(new OpenLayers.LonLat(<%= maxlon %>, <%= maxlat %>));
|
||||
var bbox = new OpenLayers.Bounds(min.lon, min.lat, max.lon, max.lat);
|
||||
|
||||
map.zoomToExtent(bbox);
|
||||
<% else %>
|
||||
var centre = lonLatToMercator(new OpenLayers.LonLat(<%= lon %>, <%= lat %>));
|
||||
var zoom = <%= zoom %>;
|
||||
|
||||
<% if params['scale'] and params['scale'].length > 0 then %>
|
||||
zoom = scaleToZoom(<%= params['scale'].to_f() %>);
|
||||
<% end %>
|
||||
|
||||
map.setCenter(centre, zoom);
|
||||
<% end %>
|
||||
|
||||
// <% if layers %>
|
||||
// setMapLayers("<%= layers %>");
|
||||
// <% end %>
|
||||
|
||||
// <% if marker %>
|
||||
// marker = addMarkerToMap(lonLatToMercator(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)));
|
||||
// <% end %>
|
||||
|
||||
map.events.register("moveend", map, updateLocation);
|
||||
map.events.register("changelayer", map, updateLocation);
|
||||
updateLocation();
|
||||
|
||||
handleResize();
|
||||
|
||||
<%= remote_function(:url => { :controller => :export, :action => :start }) %>
|
||||
}
|
||||
|
||||
function setPosition(lat, lon, zoom) {
|
||||
var centre = lonLatToMercator(new OpenLayers.LonLat(lon, lat));
|
||||
|
||||
map.setCenter(centre, zoom);
|
||||
|
||||
if (marker)
|
||||
removeMarkerFromMap(marker);
|
||||
|
||||
marker = addMarkerToMap(centre, getArrowIcon());
|
||||
}
|
||||
|
||||
function updateLocation() {
|
||||
var lonlat = mercatorToLonLat(map.getCenter());
|
||||
var zoom = map.getZoom();
|
||||
var layers = getMapLayers();
|
||||
|
||||
updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
|
||||
|
||||
document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
|
||||
}
|
||||
|
||||
function resizeContent() {
|
||||
var content = $("content");
|
||||
var rightMargin = parseInt(getStyle(content, "right"));
|
||||
var bottomMargin = parseInt(getStyle(content, "bottom"));
|
||||
|
||||
content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
|
||||
content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
|
||||
}
|
||||
|
||||
function resizeMap() {
|
||||
var centre = map.getCenter();
|
||||
var zoom = map.getZoom();
|
||||
var sidebar_width = $("sidebar").offsetWidth;
|
||||
|
||||
if (sidebar_width > 0) {
|
||||
sidebar_width = sidebar_width + 5
|
||||
}
|
||||
|
||||
$("map").style.left = (sidebar_width) + "px";
|
||||
$("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
|
||||
$("map").style.height = ($("content").offsetHeight - 2) + "px";
|
||||
|
||||
map.setCenter(centre, zoom);
|
||||
}
|
||||
|
||||
function handleResize() {
|
||||
if (brokenContentSize) {
|
||||
resizeContent();
|
||||
}
|
||||
|
||||
resizeMap();
|
||||
}
|
||||
|
||||
window.onresize = handleResize;
|
||||
window.onload = init;
|
||||
// -->
|
||||
</script>
|
|
@ -64,6 +64,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
map.connect '/user/upload_image', :controller => 'user', :action => 'upload_image'
|
||||
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 +122,9 @@ 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'
|
||||
|
||||
# messages
|
||||
|
||||
map.connect '/user/:display_name/inbox', :controller => 'message', :action => 'inbox'
|
||||
|
|
|
@ -8,6 +8,10 @@ OpenLayers._getScriptLocation = function () {
|
|||
|
||||
function createMap(divName) {
|
||||
map = new OpenLayers.Map(divName, {
|
||||
maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
|
||||
maxResolution: 156543,
|
||||
units: "m",
|
||||
projection: "EPSG:900913",
|
||||
controls: [
|
||||
new OpenLayers.Control.ArgParser(),
|
||||
new OpenLayers.Control.Attribution(),
|
||||
|
@ -28,11 +32,8 @@ function createMap(divName) {
|
|||
|
||||
var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
|
||||
markers = new OpenLayers.Layer.Markers("Markers", {
|
||||
displayInLayerSwitcher: false, numZoomLevels: numZoomLevels,
|
||||
maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
|
||||
maxResolution: 156543,
|
||||
units: "m",
|
||||
projection: "EPSG:41001"
|
||||
displayInLayerSwitcher: false,
|
||||
numZoomLevels: numZoomLevels
|
||||
});
|
||||
map.addLayer(markers);
|
||||
|
||||
|
|
|
@ -580,3 +580,31 @@ 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue