Class: TopicsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TopicsController
- Defined in:
- app/controllers/topics_controller.rb
Instance Method Summary collapse
- #index ⇒ Object
- #legend ⇒ Object
- #prepJson ⇒ Object
- #query ⇒ Object
-
#show ⇒ Object
TODO: obsolete?.
Instance Method Details
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/topics_controller.rb', line 8 def index @app = Gbapplication.find_by_name(params[:gbapp]) if params[:gbapp] if @app.nil? logger.error "Gbapplication '#{params[:gbapp]}' not found" head :bad_request return end respond_to do |format| format.json do render :json => Topic.list(@app, current_ability, host_zone(request.host), wms_host) end end end |
#legend ⇒ Object
96 97 98 99 100 101 102 |
# File 'app/controllers/topics_controller.rb', line 96 def legend #TODO: -> show?mode=legend @topic = Topic.includes(:layers).where(:name => params[:id]).first @topic ||= Topic.includes(:layers).find(params[:id]) :show, @topic render :layout => false end |
#prepJson ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/topics_controller.rb', line 77 def prepJson query_results = {} @query_topics.each do |query_topic| layer_results = {} query_topic['results'].each do |result| layer_results[result[0][:name]] = result end query_results[query_topic['topicobj'].name] = layer_results end { :results => query_results, :height => @height, :x => @xx, :y => @yy }.to_json end |
#query ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/topics_controller.rb', line 33 def query @query_topics = ActiveSupport::JSON.decode(params[:infoQuery])['queryTopics'] #e.g. [{"layers"=>"lk25,grenzen,gemeindegrenzen,seen,wald,haltestellen", "divCls"=>"legmain", "level"=>"main", "topic"=>"BASISKARTEZH"}, {"layers"=>"", "divCls"=>"legover", "level"=>"over", "topic"=>"AVParzOverlayZH"}] @query_topics.each do |query_topic| topic = Topic.where(:name => query_topic['topic']).first :show, topic query_topic['topicobj'] = topic if params['bbox'] query_topic['results'] = topic.query(current_ability, query_topic, params['bbox']) elsif params['rect'] x1, y1, x2, y2 = params['rect'].split(',').collect(&:to_f) rect = "POLYGON((#{x1} #{y1}, #{x1} #{y2}, #{x2} #{y2}, #{x2} #{y1} ,#{x1} #{y1}))" query_topic['results'] = topic.query(current_ability, query_topic, rect) elsif params['circle'] query_topic['results'] = topic.query(current_ability, query_topic, params['circle']) elsif params['poly'] query_topic['results'] = topic.query(current_ability, query_topic, params['poly']) else # problem end end if params['bbox'] x1, y1, x2, y2 = (params['bbox']).split(',').collect(&:to_f) @xx = (x1 + x2) / 2.0 @yy = (y1 + y2) / 2.0 @height = 0 #Dtm.getHeight(params['bbox']) else @xx = 0 @yy = 0 @height = 0 end respond_to do |format| format.html { render :layout => false } format.json do render :json => prepJson end format.jsonp do render :json => prepJson, :callback => params[:callback] end end end |
#show ⇒ Object
TODO: obsolete?
23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/topics_controller.rb', line 23 def show #TODO: obsolete? @topic = Topic.includes(:layers).find(params[:id]) respond_to do |format| format.json do render :json => @topic.to_json(:include => :layers) end end end |