Class: TopicsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/topics_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



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

#legendObject



103
104
105
106
107
108
109
# File 'app/controllers/topics_controller.rb', line 103

def legend
  #TODO: -> show?mode=legend
  @topic = Topic.includes(:layers).where(:name => params[:id]).first
  @topic ||= Topic.includes(:layers).find(params[:id])
  authorize! :show, @topic
  render :layout => false
end

#prepJsonObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/topics_controller.rb', line 84

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

#queryObject



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
76
77
78
79
80
81
82
# File 'app/controllers/topics_controller.rb', line 33

def query
  client_srid = params[:srid].blank? ? GeoModel.default_client_srid : params[:srid].to_i
  @client_srid = client_srid

  # optional parameter to return only the feature nearest to the center of the search geometry, if no custom layer query is used
  # use layer setting by default
  nearest = params['nearest'].nil? ? nil : params['nearest'] == 'true'

  @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
    authorize! :show, topic
    query_topic['topicobj'] = topic
    if params['bbox']
      query_topic['results'] = topic.query(current_ability, query_topic, params['bbox'], nearest, current_user, client_srid)
    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, nearest, current_user, client_srid)
    elsif params['circle']
      query_topic['results'] = topic.query(current_ability, query_topic, params['circle'], nearest, current_user, client_srid)
    elsif params['poly']
      query_topic['results'] = topic.query(current_ability, query_topic, params['poly'], nearest, current_user, client_srid)
    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

#showObject

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