Class: Ropenlayer::Openlayer::BoxControl::Base

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

Direct Known Subclasses

EditMap, LayersSelect

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, map, options = {}) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ropenlayer/openlayer/box_control/base.rb', line 13

def initialize(name, map, options = {})
  @name          = name
  @map           = map
  @links         = []
  
  @js_id         = "#{ map.js_id }_#{ name }"
  @js_control_id = "#{ @js_id }_control" 
  @js_links_id   = "#{ @js_id }_links" 
  @js_panel_id   = "#{ @js_id }_panel" 
  
  @css_class = options[:css_class] || "olCustomControl#{ @name.camelize }"
end

Instance Attribute Details

Returns the value of attribute js_links_id.



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

def js_links_id
  @js_links_id
end

Returns the value of attribute links.



10
11
12
# File 'lib/ropenlayer/openlayer/box_control/base.rb', line 10

def links
  @links
end

#mapObject (readonly)

Returns the value of attribute map.



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

def map
  @map
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#to_jsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ropenlayer/openlayer/box_control/base.rb', line 27

def to_js
  
  create_links_container   = @map.js_helper.create_xhtml_element("div", { :class => "'#{ @css_class }Links'", :style => "'display: none;'", :id    => "'#{ @js_links_id }'" })
  create_openlayer_control = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Control.Button", :propierties => { :displayClass => "'#{ @css_class }'",
                                                                                                                 :trigger      => "function() { #{ @map.js_helper.toggle_xhtml_element(@js_links_id) } }" }).to_s
  create_openlayer_panel   = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Control.Panel", :propierties => { :displayClass    => "'#{ @css_class }Panel'",
                                                                                                                 :defaultControl  => "#{ @js_control_id }" }).to_s
  
  %( // Adding #{ @name } box control   
    
    #{ Ropenlayer::Openlayer::Js.new_var(@js_control_id, create_openlayer_control).to_js }
    #{ Ropenlayer::Openlayer::Js.new_var(@js_links_id, create_links_container).to_js     }
    #{ Ropenlayer::Openlayer::Js.new_var(@js_panel_id, create_openlayer_panel).to_js     }
    
    #{ Ropenlayer::Openlayer::Js.new("#{ @js_panel_id }.addControls([#{ @js_control_id }])").to_js }
    #{ Ropenlayer::Openlayer::Js.new("#{ @map.js_id }.addControls([#{ @js_panel_id }])").to_js }

    #{ Ropenlayer::Openlayer::Js.new(@map.js_helper.insert_into_xhtml_element("#{ @js_control_id }.div", @js_links_id)).to_js }

    #{ links.inject('') do |links_string, link_config|
        link_config[:inner_html] = "'#{ link_config.delete(:text) }'"
        links_string << Ropenlayer::Openlayer::Js.new(@map.js_helper.insert_into_xhtml_element(@js_links_id, @map.js_helper.create_xhtml_element("a", link_config ))).to_js
        links_string
    end }
    
    )
end