Class: Ropenlayer::Openlayer::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/ropenlayer/openlayer/control.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, map) ⇒ Control

Returns a new instance of Control.



17
18
19
20
21
22
# File 'lib/ropenlayer/openlayer/control.rb', line 17

def initialize(name, map)
  @name   = name
  @map    = map
  @js_id  = "#{ map.js_id }_#{ name }"
  @config = Ropenlayer::Openlayer::Control.configs[name]
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/ropenlayer/openlayer/control.rb', line 5

def config
  @config
end

#js_idObject (readonly)

Returns the value of attribute js_id.



7
8
9
# File 'lib/ropenlayer/openlayer/control.rb', line 7

def js_id
  @js_id
end

#mapObject (readonly)

Returns the value of attribute map.



8
9
10
# File 'lib/ropenlayer/openlayer/control.rb', line 8

def map
  @map
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/ropenlayer/openlayer/control.rb', line 6

def name
  @name
end

Class Method Details

.build_collection(map) ⇒ Object



10
11
12
13
14
15
# File 'lib/ropenlayer/openlayer/control.rb', line 10

def self.build_collection(map)
  map.control_names.inject([]) do |controls, control_name|
    controls << new(control_name, map)
    controls
  end
end

Instance Method Details

#to_jsObject



24
25
26
27
28
29
# File 'lib/ropenlayer/openlayer/control.rb', line 24

def to_js
  %(// Adding #{ @name } control   
    #{ Ropenlayer::Openlayer::Js.new_var(@js_id, "#{ Ropenlayer::Openlayer::Js.new_method(@config[:method], @config) }").to_js } 
    #{ Ropenlayer::Openlayer::Js.new("#{ map.js_id }.addControl(#{ @js_id })").to_js } 
    )
end