Class: LocateRule

Inherits:
Object
  • Object
show all
Defined in:
app/models/locate_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, layer = nil, search_field = nil) ⇒ LocateRule

Returns a new instance of LocateRule.



4
5
6
7
8
# File 'app/models/locate_rule.rb', line 4

def initialize(model, layer=nil, search_field=nil)
  @model = model.constantize
  @layer = layer
  @search_field = search_field
end

Instance Attribute Details

#layerObject

Returns the value of attribute layer.



2
3
4
# File 'app/models/locate_rule.rb', line 2

def layer
  @layer
end

#modelObject

Returns the value of attribute model.



2
3
4
# File 'app/models/locate_rule.rb', line 2

def model
  @model
end

#search_fieldObject

Returns the value of attribute search_field.



2
3
4
# File 'app/models/locate_rule.rb', line 2

def search_field
  @search_field
end

Instance Method Details

#locate(locations, client_srid = nil) ⇒ Object

get selection and extent for located features



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/locate_rule.rb', line 11

def locate(locations, client_srid=nil)
  features = if layer.nil?
    # user defined model
    seltopic = model.selection_topic
    sellayer = model.selection_layer
    selproperty = model.primary_key
    selscalerange = model.selection_scalerange
    search_locs = model.search_locations(locations)
    model.locate(search_locs, client_srid)
  else
    # generic SearchModel
    layer_obj = Layer.find_by_name(layer)
    seltopic = nil
    sellayer = layer_obj.name
    selproperty = layer_obj.feature_class.primary_key
    selscalerange = model.selection_scalerange
    search_locs = locations.split(',')
    model.layer_locate(layer_obj, search_field, search_locs, client_srid)
  end
  if features.present?
    x, y, scale = model.map_center(features)
    {
      :selection => {
        :topic => seltopic,
        :layer => sellayer,
        :property => selproperty,
        :values => features.collect {|f| f.send(model.primary_key) },
        :scalerange => selscalerange,
      },
      :x => x,
      :y => y,
      :scale => scale,
      :bbox => model.bbox(features)
    }
  else
    # no features found
    nil
  end
end