Sha256: 1ff4a7e19460422e215ebc5b90323ba2d2c5443de6ca513ea93e016829b6ebe4

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

module Ropenlayer
  module Openlayer
    class Control
      
      attr_reader :config
      attr_reader :name
      attr_reader :js_id
      attr_reader :map
      
      def self.build_collection(map)
        map.control_names.inject([]) do |controls, control_name|
          controls << new(control_name, map)
          controls
        end
      end
      
      def initialize(name, map)
        @name   = name
        @map    = map
        @js_id  = "#{ map.js_id }_#{ name }"
        @config = Ropenlayer::Openlayer::Control.configs[name]
      end
      
      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

      private 
      def self.configs
        { :layers_switcher => { :method => "OpenLayers.Control.LayerSwitcher", :args  => "" },
          :mouse_position  => { :method => "OpenLayers.Control.MousePosition", :args  => "" },
          :pan_panel       => { :method => "OpenLayers.Control.PanPanel",      :args  => "" },
          :navigation      => { :method => "OpenLayers.Control.Navigation",    :args  => "" },
          :zoom_panel      => { :method => "OpenLayers.Control.ZoomPanel",     :args  => "" },
          :scale_line      => { :method => "OpenLayers.Control.ScaleLine",     :args  => "" }}
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ropenlayer-0.3.5 lib/ropenlayer/openlayer/control.rb
ropenlayer-0.3.4 lib/ropenlayer/openlayer/control.rb
ropenlayer-0.3.3 lib/ropenlayer/openlayer/control.rb
ropenlayer-0.3.1 lib/ropenlayer/openlayer/control.rb
ropenlayer-0.3.0 lib/ropenlayer/openlayer/control.rb