+ before_filter :require_oauth, :only => [:index]
+
+ def index
+ anchor = []
+
+ if params[:lat] && params[:lon]
+ anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
+ end
+
+ if params[:layers]
+ anchor << "layers=#{params.delete(:layers)}"
+ elsif params.delete(:notes) == 'yes'
+ anchor << "layers=N"
+ end
+
+ if anchor.present?
+ redirect_to params.merge(:anchor => anchor.join('&'))
+ return
+ end
+
+ unless STATUS == :database_readonly or STATUS == :database_offline
+ session[:location] ||= OSM::IPLocation(request.env['REMOTE_ADDR'])
+ end
+ end
+
+ def permalink
+ lon, lat, zoom = ShortLink::decode(params[:code])
+ new_params = params.except(:code, :lon, :lat, :zoom)
+
+ if new_params.has_key? :m
+ new_params.delete :m
+ new_params[:mlat] = lat
+ new_params[:mlon] = lon
+ end
+
+ new_params[:controller] = 'site'
+ new_params[:action] = 'index'
+ new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"