Module: Cloudkicker::ControlElements

Included in:
Map
Defined in:
lib/critical_juncture/control_elements.rb

Instance Method Summary collapse

Instance Method Details

#add_map_control(map_control_type, position = :top_right, padding_x = 10, padding_y = 10) ⇒ Object

add create a map control with type, position and padding

Params:

map_control_type
  The size of the control on the map
  Options - :large, :small
position
  Where the control is located on the map
  Options - :top_right
padding_x
  Amount of padding in the x direction in pixels - depends on where the position is set to, 
  but always from the outer edge of the map
padding_y
  Amount of padding in the y direction in pixels - depends on where the position is set to, 
  but always from the outer edge of the map


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/critical_juncture/control_elements.rb', line 20

def add_map_control(map_control_type, position = :top_right, padding_x = 10, padding_y = 10)
  control_position =  case position
                      when :top_right
                        'CM.TOP_RIGHT'
                      end
  
  control_type =  case @map_control_type.to_sym
                  when :large
                     'CM.LargeMapControl()'
                  when :small
                    'CM.SmallMapControl()'
                  end
  
  js = <<-JS
    // create a new control position and add padding
    var controlPosition = new CM.ControlPosition(#{control_position}, new CM.Size(#{padding_x}, #{padding_y}));
    map.addControl(new #{control_type}, controlPosition);
  JS
  
  return js
end