Class: Ropenlayer::Openlayer::BoxControl::EditMap

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

Instance Attribute Summary

Attributes inherited from Base

#js_links_id, #links, #map, #name

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ EditMap

Returns a new instance of EditMap.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ropenlayer/openlayer/box_control/edit_map.rb', line 5

def initialize(map)
  super('edit_map', map, :css_class => 'olControlEditMapControl')
  Ropenlayer::Openlayer::BoxControl::EditMap.controls.each do |control_name, control_options|
    
    
    @links  << { :id       => "'link_to_edit_map_control_#{ control_name }'",
                 :class    => "'olControlEditMapControlLink with_icon action_#{ control_name }'",
                 :text     => "'#{ control_options[:description] }'",
                 :title    => "'#{ control_options[:description] }'",
                 :onclick  => %( #{ map.js_helper.update_xhtml_element(map.js_notification_area, "'#{ control_options[:help]}'") }; \
                                 #{ map.js_helper.hide_xhtml_element(@js_links_id) }; \
                                 #{ map.js_id }ActivateEditControl('#{ control_name }'); return false ) }
               
  end
  @links << { :id       => "'link_to_edit_map_control_cancel'",
              :class    =>  "'olControlEditMapControlLink with_icon action_cancel'",
              :text     => "Cancelar",
              :onclick  => %( #{ map.js_id }ActivateEditControl('none'); #{  map.js_helper.hide_xhtml_element(@js_links_id) }; return false)  }
end

Instance Method Details

#to_jsObject



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
50
51
52
53
54
55
56
57
# File 'lib/ropenlayer/openlayer/box_control/edit_map.rb', line 25

def to_js
  %( 
    var #{ map.js_id }EditMapControls = {};
    function #{ map.js_id }ActivateEditControl(selectedControl) {
      for(key in #{ map.js_id }EditMapControls) {
        var control = #{ map.js_id }EditMapControls[key];
        if(selectedControl == key) {
          control.activate();
        } else {
          control.deactivate();
        }
      }
    }
    #{ new_elements_layer = Ropenlayer::Openlayer::Layer::Base.new(:new_elements, @map)
      new_elements_layer.to_js }

    #{ Ropenlayer::Openlayer::BoxControl::EditMap.controls.inject('') do |edit_controls_js, control_array|
        control_name    = control_array.first
        control_options = control_array.last
        control_options[:args] = [ new_elements_layer.js_id, control_options[:args]].flatten
        control_options[:propierties][:featureAdded] = map.options[:add_feature_callback] || 'false' # FIXME

        edit_controls_js << %( #{ Ropenlayer::Openlayer::Js.new_var("#{ map.js_id }_#{ control_name }", 
                                                                    "#{ Ropenlayer::Openlayer::Js.new_method(control_options[:method], control_options) }").to_js }
                                #{ Ropenlayer::Openlayer::Js.new("#{ map.js_id }.addControl(#{ map.js_id }_#{ control_name })").to_js }
                                #{ Ropenlayer::Openlayer::Js.new("#{ map.js_id }EditMapControls['#{ control_name }'] = #{ map.js_id }_#{ control_name }").to_js }
        )
        edit_controls_js
      end }
      
    #{ super }
    )
end