Skip to content

Commit

Permalink
Make JOSM remote control based editing work
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Nov 29, 2010
1 parent b90219f commit c3453cf
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 35 deletions.
60 changes: 32 additions & 28 deletions app/controllers/site_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,40 @@ def key
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])

# 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)

@zoom = '14' if @zoom.nil?
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
8 changes: 8 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ def user_thumbnail(user, options = {})
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)
Expand Down
6 changes: 0 additions & 6 deletions app/views/site/_josm.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/site/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
25 changes: 25 additions & 0 deletions app/views/site/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 %>
Expand Down

0 comments on commit c3453cf

Please sign in to comment.