Make JOSM remote control based editing work
This commit is contained in:
parent
b90219f1d3
commit
c3453cf57d
5 changed files with 66 additions and 35 deletions
|
@ -32,36 +32,40 @@ class SiteController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
session[:token] = @user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token])
|
||||
|
||||
@preferred_editor = @user.preferred_editor || DEFAULT_EDITOR
|
||||
editor = @user.preferred_editor || DEFAULT_EDITOR
|
||||
|
||||
# Decide on a lat lon to initialise potlatch with. Various ways of doing this
|
||||
if params['lon'] and params['lat']
|
||||
@lon = params['lon'].to_f
|
||||
@lat = params['lat'].to_f
|
||||
@zoom = params['zoom'].to_i
|
||||
|
||||
elsif params['mlon'] and params['mlat']
|
||||
@lon = params['mlon'].to_f
|
||||
@lat = params['mlat'].to_f
|
||||
@zoom = params['zoom'].to_i
|
||||
|
||||
elsif params['gpx']
|
||||
#use gpx id to locate (dealt with below)
|
||||
|
||||
elsif cookies.key?("_osm_location")
|
||||
@lon, @lat, @zoom, layers = cookies["_osm_location"].split("|")
|
||||
|
||||
elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
|
||||
@lon = @user.home_lon
|
||||
@lat = @user.home_lat
|
||||
|
||||
if editor == "josm"
|
||||
render :action => :index
|
||||
else
|
||||
#catch all. Do nothing. lat=nil, lon=nil
|
||||
#Currently this results in potlatch starting up at 0,0 (Atlantic ocean).
|
||||
end
|
||||
session[:token] = @user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token])
|
||||
|
||||
@zoom = '14' if @zoom.nil?
|
||||
# Decide on a lat lon to initialise potlatch with. Various ways of doing this
|
||||
if params['lon'] and params['lat']
|
||||
@lon = params['lon'].to_f
|
||||
@lat = params['lat'].to_f
|
||||
@zoom = params['zoom'].to_i
|
||||
|
||||
elsif params['mlon'] and params['mlat']
|
||||
@lon = params['mlon'].to_f
|
||||
@lat = params['mlat'].to_f
|
||||
@zoom = params['zoom'].to_i
|
||||
|
||||
elsif params['gpx']
|
||||
#use gpx id to locate (dealt with below)
|
||||
|
||||
elsif cookies.key?("_osm_location")
|
||||
@lon, @lat, @zoom, layers = cookies["_osm_location"].split("|")
|
||||
|
||||
elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
|
||||
@lon = @user.home_lon
|
||||
@lat = @user.home_lat
|
||||
|
||||
else
|
||||
#catch all. Do nothing. lat=nil, lon=nil
|
||||
#Currently this results in potlatch starting up at 0,0 (Atlantic ocean).
|
||||
end
|
||||
|
||||
@zoom = '14' if @zoom.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -119,6 +119,14 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
def preferred_editor
|
||||
if @user and @user.preferred_editor
|
||||
@user.preferred_editor
|
||||
else
|
||||
DEFAULT_EDITOR
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def javascript_strings_for_key(key)
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
<div id="map">
|
||||
<% query = "lat=#{@lat || 0}&lon=#{@lon || 0}&zoom=#{@zoom}" %>
|
||||
<iframe src="http://127.0.0.1:8111/load_and_zoom?<%= query %>" width="100%" height="100%">
|
||||
<p><%= t 'site.edit.no_iframe_support' %></p>
|
||||
</iframe>
|
||||
</div>
|
|
@ -19,7 +19,7 @@
|
|||
<%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
|
||||
<%= render :partial => 'search' %>
|
||||
|
||||
<%= render :partial => @preferred_editor %>
|
||||
<%= render :partial => preferred_editor %>
|
||||
|
||||
<script type="text/javascript" defer="defer">
|
||||
function resizeContent() {
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
<div id="map">
|
||||
</div>
|
||||
|
||||
<iframe id="linkloader" style="display: none">
|
||||
</iframe>
|
||||
|
||||
<div id="permalink">
|
||||
<a href="/" id="permalinkanchor"><%= t 'site.index.permalink' %></a><br/>
|
||||
<a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a>
|
||||
|
@ -267,11 +270,33 @@ end
|
|||
resizeMap();
|
||||
}
|
||||
|
||||
function josmEditHandler() {
|
||||
var extent = getMapExtent();
|
||||
|
||||
$("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function installEditHandler() {
|
||||
<% if preferred_editor == "josm" %>
|
||||
$("editanchor").onclick =josmEditHandler;
|
||||
|
||||
<% if params[:action] == "edit" %>
|
||||
josmEditHandler();
|
||||
<% end %>
|
||||
<% end %>
|
||||
}
|
||||
|
||||
mapInit();
|
||||
|
||||
window.onload = handleResize;
|
||||
window.onresize = handleResize;
|
||||
|
||||
Event.observe(window, 'load', installEditHandler);
|
||||
Event.observe(window, 'load', handleResize);
|
||||
Event.observe(window, 'resize', handleResize);
|
||||
|
||||
<% if params['action'] == 'export' %>
|
||||
<%= remote_function :url => { :controller => 'export', :action => 'start' } %>
|
||||
<% end %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue