1 class SiteController < ApplicationController
3 layout :map_layout, :only => [:index, :export]
5 before_filter :authorize_web
6 before_filter :set_locale
7 before_filter :redirect_browse_params, :only => :index
8 before_filter :redirect_map_params, :only => [:index, :edit, :export]
9 before_filter :require_user, :only => [:welcome]
10 before_filter :require_oauth, :only => [:index]
13 unless STATUS == :database_readonly or STATUS == :database_offline
14 session[:location] ||= OSM::IPLocation(request.env['REMOTE_ADDR'])
19 lon, lat, zoom = ShortLink::decode(params[:code])
20 new_params = params.except(:code, :lon, :lat, :zoom, :layers, :node, :way, :relation, :changeset)
22 if new_params.has_key? :m
24 new_params[:mlat] = lat
25 new_params[:mlon] = lon
28 if params.has_key? :node
29 new_params[:controller] = 'browse'
30 new_params[:action] = 'node'
31 new_params[:id] = params[:node]
32 elsif params.has_key? :way
33 new_params[:controller] = 'browse'
34 new_params[:action] = 'way'
35 new_params[:id] = params[:way]
36 elsif params.has_key? :relation
37 new_params[:controller] = 'browse'
38 new_params[:action] = 'relation'
39 new_params[:id] = params[:relation]
40 elsif params.has_key? :changeset
41 new_params[:controller] = 'browse'
42 new_params[:action] = 'changeset'
43 new_params[:id] = params[:changeset]
45 new_params[:controller] = 'site'
46 new_params[:action] = 'index'
49 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
51 if params.has_key? :layers
52 new_params[:anchor] += "&layers=#{params[:layers]}"
55 redirect_to Hash[new_params]
59 expires_in 7.days, :public => true
60 render :layout => false
64 editor = preferred_editor
68 render :action => :index, :layout => map_layout
75 bbox = Node.find(params[:node]).bbox.to_unscaled
76 @lat = bbox.centre_lat
77 @lon = bbox.centre_lon
80 bbox = Way.find(params[:way]).bbox.to_unscaled
81 @lat = bbox.centre_lat
82 @lon = bbox.centre_lon
85 note = Note.find(params[:note])
90 trace = Trace.visible_to(@user).find(params[:gpx])
92 @lon = trace.longitude
98 @locale = params[:copyright_locale] || I18n.locale
117 render :text => RichText.new(params[:format], params[:text]).to_html
121 render "id", :layout => false
126 def redirect_browse_params
128 redirect_to node_path(params[:node])
130 redirect_to way_path(params[:way])
131 elsif params[:relation]
132 redirect_to relation_path(params[:relation])
134 redirect_to browse_note_path(params[:note])
136 redirect_to search_path(:query => params[:query])
140 def redirect_map_params
143 if params[:lat] && params[:lon]
144 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
148 anchor << "layers=#{params.delete(:layers)}"
149 elsif params.delete(:notes) == 'yes'
154 redirect_to Hash[params].merge(:anchor => anchor.join('&'))