ropenlayer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *~
2
+ rdoc
3
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2011-01-11
2
+
3
+ * 1 major enhancement:
4
+ * release fist version of ropenlayer gem
data/Manifest.txt ADDED
@@ -0,0 +1,23 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ ropenlayer.gemspec
7
+ lib/ropenlayer.rb
8
+ lib/ropenlayer/control.rb
9
+ lib/ropenlayer/js.rb
10
+ lib/ropenlayer/map.rb
11
+ lib/ropenlayer/layer/base.rb
12
+ lib/ropenlayer/layer/elements_marker.rb
13
+ lib/ropenlayer/layer/elements_vector.rb
14
+ lib/ropenlayer/box_control/base.rb
15
+ lib/ropenlayer/box_control/edit_map.rb
16
+ lib/ropenlayer/box_control/layers_select.rb
17
+ script/console
18
+ script/destroy
19
+ script/generate
20
+ spec/
21
+
22
+
23
+
data/PostInstall.txt ADDED
@@ -0,0 +1,5 @@
1
+
2
+ For more information on lidia, see http://lidia.rubyforge.org
3
+
4
+
5
+
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+
2
+ = Ruby && Openlayers
3
+
4
+ * http://gitorious/gnoxys/ropenlayer
5
+ * http://openlayers.org/
6
+
7
+ == DESCRIPTION:
8
+
9
+ Ropenlayer is a wrapper constructor for openlayer javascript library written in ruby. It aims to provide an easy way to build maps and display it on webs.
10
+
11
+ At the moment, Ropenlayer gem comes with the following features.
12
+
13
+ - Create a JS OpenLayer.Map object with some options from ruby methods.
14
+ - Manage layers and controls displayed on the map.
15
+ - Create, by default, a marker and vectors layers for render items with icons or differents features as polygons or lines. more will come.
16
+ - Ropenlayer will namescope all the outpus so several maps on same screen are allowed.
17
+ - Set defaul latitude, longitude and zoom,
18
+
19
+ == Before use ropenlayer
20
+
21
+ Ropenlayer is still in alpha stage, so, you should have some skills with javascript and openlayers.
22
+
23
+ Also, ropenlayer assumes you have included openlayers library in your website. For more information, go to openlayers home (http://openlayers.org/) or view the examples at http://openlayers.org/dev/examples/
24
+
25
+ == Initialize
26
+
27
+ Create a map object with parsed attributes. Ropenlayer manage two ids for each map.
28
+
29
+ - js_div, use to scope all the variables names to draw js output.
30
+ - div_id, the dom_id passed as argument to construtor. For example
31
+
32
+ For example
33
+
34
+ m = Ropenlayer::Map.new('group_map')
35
+ => <Ropenlayer::Map:0xf7344fe8>
36
+ m.js_id
37
+ => "olObject_group_map"
38
+ n.div_id
39
+ => "group_map"
40
+
41
+ To draw map, just call to_js method. For example, in a rails 3.x application
42
+
43
+ <%= raw javascript_tag(Ropenlayer::Map.new('group_map').to_js) %>
44
+
45
+ For more information see Ropenlayer::Map
46
+
47
+ == DEMO
48
+
49
+ You can take a look to cartac (http://cartac.gnoxys.net) a application we develop over ropenlayer gem.
50
+
51
+ == REQUIREMENTS:
52
+
53
+ * json_pure (~>1.2.3)
54
+
55
+ == INSTALL:
56
+
57
+ * gem install ropenLayer
58
+
59
+ == LICENSE:
60
+
61
+ Same as Openlayers project: http://svn.openlayers.org/trunk/openlayers/license.txt
62
+
63
+ Copyright (c) 2011 Gnoxys. info@goxys.net
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require 'rake'
3
+ require 'rake/rdoctask'
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require 'rspec/core/rake_task'
7
+ require 'bundler'
8
+ require File.join(File.dirname(__FILE__), 'lib', 'ropenlayer')
9
+
10
+
11
+ Rspec::Core::RakeTask.new(:spec) do |t|
12
+ t.rspec_opts = ["--color"]
13
+ end
14
+
15
+ task :default => :spec
16
+
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'ropenlayer'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README.rdoc')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,47 @@
1
+ module Ropenlayer
2
+ module BoxControl
3
+ class Base
4
+
5
+ attr_reader :map
6
+ attr_reader :name
7
+ attr_reader :js_links_id
8
+
9
+ attr_accessor :links
10
+
11
+
12
+ def initialize(name, map, options = {})
13
+ @name = name
14
+ @map = map
15
+ @links = []
16
+
17
+ @js_id = "#{ map.js_id }_#{ name }"
18
+ @js_control_id = "#{ @js_id }_control"
19
+ @js_links_id = "#{ @js_id }_links"
20
+ @js_panel_id = "#{ @js_id }_panel"
21
+
22
+ @css_class = options[:css_class] || "olCustomControl#{ @name.camelize }"
23
+ end
24
+
25
+
26
+ def to_js
27
+ %( // Adding #{ @name } box control
28
+ #{ Ropenlayer::Js.new_var("#{ @js_links_id }", "#{ Ropenlayer::Js.new_method("Element", :args => [ "'div'" ], :propierties => { :class => "'#{ @css_class }Links'",
29
+ :style => "'display: none;'",
30
+ :id => "'#{ @js_links_id }'" })}").to_js }
31
+ #{ Ropenlayer::Js.new_var("#{ @js_control_id }", "#{ Ropenlayer::Js.new_method("OpenLayers.Control.Button", :propierties => { :displayClass => "'#{ @css_class }'",
32
+ :trigger => "function() { $('#{ @js_links_id }').toggle(); }" }) }").to_js }
33
+ #{ Ropenlayer::Js.new_var("#{ @js_panel_id }", "#{ Ropenlayer::Js.new_method("OpenLayers.Control.Panel", :propierties => { :displayClass => "'#{ @css_class }Panel'",
34
+ :defaultControl => "#{ @js_control_id }" }) }").to_js }
35
+ #{ Ropenlayer::Js.new("#{ @js_panel_id }.addControls([#{ @js_control_id }])").to_js }
36
+ #{ links.inject('') do |links_string, link_config|
37
+ link_text = link_config.delete(:text)
38
+ links_string << "#{ Ropenlayer::Js.new("#{ @js_links_id }.insert(#{ Ropenlayer::Js.new_method("Element", :args => ["'a'"], :propierties => link_config ) }.update('#{ link_text }'))").to_js }\n"
39
+ links_string
40
+ end }
41
+ #{ Ropenlayer::Js.new("#{ @map.js_id }.addControls([#{ @js_panel_id }])").to_js }
42
+ #{ Ropenlayer::Js.new("#{ @js_control_id }.div.insert(#{ @js_links_id })").to_js }
43
+ )
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,79 @@
1
+ module Ropenlayer
2
+ module BoxControl
3
+ class EditMap < Base
4
+ def initialize(map)
5
+ super('edit_map', map, :css_class => 'olControlEditMapControl')
6
+ Ropenlayer::BoxControl::EditMap.controls.each do |control_name, control_options|
7
+
8
+ @links << { :id => "'link_to_edit_map_control_#{ control_name }'",
9
+ :class => "'olControlEditMapControlLink with_icon action_#{ control_name }'",
10
+ :text => "#{ control_options[:description] }",
11
+ :title => "'#{ control_options[:description] }'",
12
+ :onclick => %( "#{ map.js_notification_area }.update('#{ control_options[:help]}'); new Effect.BlindDown(#{ map.js_notification_area });#{ @js_links_id }.hide(); #{ map.js_id }ActivateEditControl('#{ control_name }');return false;" ) }
13
+ end
14
+ @links << { :id => "'link_to_edit_map_control_cancel'",
15
+ :class => "'olControlEditMapControlLink with_icon action_cancel'",
16
+ :text => "Cancelar",
17
+ :onclick => %( "#{ @js_links_id }.hide(); return false;") }
18
+ end
19
+
20
+ def to_js
21
+ %(
22
+ var #{ map.js_id }EditMapControls = {};
23
+ function #{ map.js_id }ActivateEditControl(selectedControl) {
24
+ for(key in #{ map.js_id }EditMapControls) {
25
+ var control = #{ map.js_id }EditMapControls[key];
26
+ if(selectedControl == key) {
27
+ control.activate();
28
+ } else {
29
+ control.deactivate();
30
+ }
31
+ }
32
+ }
33
+ #{ new_elements_layer = Ropenlayer::Layer::Base.new(:new_elements, @map)
34
+ new_elements_layer.to_js }
35
+
36
+ #{ Ropenlayer::BoxControl::EditMap.controls.inject('') do |edit_controls_js, control_array|
37
+ control_name = control_array.first
38
+ control_options = control_array.last
39
+ control_options[:args] = [ new_elements_layer.js_id, control_options[:args]].flatten
40
+ control_options[:propierties][:featureAdded] = map.options[:new_feature_callback] || 'false' # FIXME
41
+
42
+ edit_controls_js << %( #{ Ropenlayer::Js.new_var("#{ map.js_id }_#{ control_name }",
43
+ "#{ Ropenlayer::Js.new_method(control_options[:method], control_options) }").to_js }
44
+ #{ Ropenlayer::Js.new("#{ map.js_id }.addControl(#{ map.js_id }_#{ control_name })").to_js }
45
+ #{ Ropenlayer::Js.new("#{ map.js_id }EditMapControls['#{ control_name }'] = #{ map.js_id }_#{ control_name }").to_js }
46
+ )
47
+ edit_controls_js
48
+ end }
49
+
50
+ #{ super }
51
+ )
52
+ end
53
+
54
+ private
55
+ def self.controls
56
+ { :add_point => {:method => "OpenLayers.Control.DrawFeature",
57
+ :args => [ "OpenLayers.Handler.Point" ],
58
+ :propierties => { },
59
+ :description => 'Crear un punto',
60
+ :help => 'Para crear un punto en el mapa, haga click en la posición deseada'
61
+ },
62
+ :add_line => { :method => "OpenLayers.Control.DrawFeature",
63
+ :args => [ "OpenLayers.Handler.Path" ],
64
+ :propierties => { },
65
+ :description => 'Crear una línea',
66
+ :help => 'Para crear un punto en el mapa, haga click en la posición deseada'
67
+
68
+ },
69
+ :add_polygon => { :method => "OpenLayers.Control.DrawFeature",
70
+ :args => [ "OpenLayers.Handler.Polygon" ],
71
+ :propierties => { },
72
+ :description => 'Crear un polígono',
73
+ :help => 'Para crear un punto en el mapa, haga click en la posición deseada'
74
+ }
75
+ }
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,16 @@
1
+ module Ropenlayer
2
+ module BoxControl
3
+ class LayersSelect < Base
4
+ def initialize(map)
5
+ super('layers_select', map, :css_class => 'olControlLayersBoxControl')
6
+ map.layers.each do |layer|
7
+ @links << { :id => "'link_to_base_layer_#{ layer.name }'",
8
+ :class => "'olControlLayersBoxControl'",
9
+ :text => " » Usar Mapa #{ layer.config[:description] }",
10
+ :onclick => "'#{ map.js_id }.setBaseLayer(#{ layer.js_id }); #{ @js_links_id }.hide(); return false;'" }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,40 @@
1
+ module Ropenlayer
2
+ class Control
3
+
4
+ attr_reader :config
5
+ attr_reader :name
6
+ attr_reader :js_id
7
+ attr_reader :map
8
+
9
+ def self.build_collection(map)
10
+ map.control_names.inject([]) do |controls, control_name|
11
+ controls << new(control_name, map)
12
+ controls
13
+ end
14
+ end
15
+
16
+ def initialize(name, map)
17
+ @name = name
18
+ @map = map
19
+ @js_id = "#{ map.js_id }_#{ name }"
20
+ @config = Ropenlayer::Control.configs[name]
21
+ end
22
+
23
+ def to_js
24
+ %(// Adding #{ @name } control
25
+ #{ Ropenlayer::Js.new_var(@js_id, "#{ Ropenlayer::Js.new_method(@config[:method], @config) }").to_js }
26
+ #{ Ropenlayer::Js.new("#{ map.js_id }.addControl(#{ @js_id })").to_js }
27
+ )
28
+ end
29
+
30
+ private
31
+ def self.configs
32
+ { :layers_switcher => { :method => "OpenLayers.Control.LayerSwitcher", :args => "" },
33
+ :mouse_position => { :method => "OpenLayers.Control.MousePosition", :args => "" },
34
+ :pan_panel => { :method => "OpenLayers.Control.PanPanel", :args => "" },
35
+ :navigation => { :method => "OpenLayers.Control.Navigation", :args => "" },
36
+ :zoom_panel => { :method => "OpenLayers.Control.ZoomPanel", :args => "" },
37
+ :scale_line => { :method => "OpenLayers.Control.ScaleLine", :args => "" }}
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,62 @@
1
+ module Ropenlayer
2
+
3
+ class Js
4
+
5
+ attr_accessor :body
6
+
7
+ # == Ropenlayer::Js
8
+ #
9
+ # Just a simple JS constructor for objects methods calls and variable setting
10
+ def initialize(initialize_string = '')
11
+ @body = initialize_string
12
+ end
13
+
14
+ # create a new js method
15
+ #
16
+ # Ropenlayer::Js.new_method("Element.create", "div", { :class => 'eyecandy', :id => 'my_id'}).to_s
17
+ # #=> new Element.create("div", { "class":"eyecandy","id":"my_id"});
18
+ #
19
+ def self.new_method(method, options = {})
20
+ js_object = new
21
+ args = options[:args] || []
22
+ propierties = options[:propierties] || {}
23
+
24
+ js_object.body = "new #{ method }("
25
+ js_object.body << "#{ args.join(', ') }" if args.any?
26
+
27
+ if propierties.keys.any?
28
+
29
+ js_object.body << ", " if args.any?
30
+
31
+ js_object.body << propierties.keys.inject("{") do |propierties_string, propierty|
32
+ propierties_string << "'#{ propierty }': #{ propierties[propierty] }"
33
+ propierties_string << ", " unless propierties.keys.last == propierty
34
+ propierties_string
35
+ end
36
+ js_object.body << "}"
37
+
38
+ end
39
+ js_object.body << ")"
40
+ js_object
41
+ end
42
+
43
+ # create a new js global variable:
44
+ #
45
+ # Ropenlayer::Js.new_var("test", "1").to_s
46
+ # #=> var test = "1"
47
+ #
48
+ def self.new_var(name, value)
49
+ new("var #{ name } = #{ value }")
50
+ end
51
+
52
+
53
+ def to_s
54
+ @body
55
+ end
56
+
57
+ def to_js
58
+ "#{ @body };"
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,87 @@
1
+ module Ropenlayer
2
+ module Layer
3
+ class Base
4
+
5
+ attr_reader :config
6
+ attr_reader :name
7
+ attr_reader :js_id
8
+ attr_reader :map
9
+
10
+ def self.build_collection(map)
11
+ map.layer_names.inject([]) do |layers, layer_name|
12
+ layers << new(layer_name, map)
13
+ layers
14
+ end
15
+ end
16
+
17
+ def initialize(name, map)
18
+ @name = name
19
+ @map = map
20
+ @js_id = "#{ map.js_id }_#{ name }"
21
+ @config = self.class.layers_config[name]
22
+ end
23
+
24
+ def to_js
25
+ %( // Adding #{ @name } layer
26
+ #{ Ropenlayer::Js.new_var(@js_id, "#{ Ropenlayer::Js.new_method(@config[:method], @config) }").to_js }
27
+ #{ Ropenlayer::Js.new("#{ map.js_id }.addLayer(#{ @js_id })").to_js } )
28
+ end
29
+
30
+ private
31
+ # return a hash with config options for Ropenlayer layers.
32
+ # U can override this method as ur wish to get config from other places, for example, AR.
33
+ def self.layers_config
34
+ { :osm => { :method => "OpenLayers.Layer.OSM",
35
+ :args => [ "'Usar Mapa OSM'" ],
36
+ :propierties => { },
37
+ :description => 'Mapa Libre OSM' },
38
+
39
+ :wms => { :method => "OpenLayers.Layer.WMS",
40
+ :args => [ "'OpenLayers WMS'", "'http://vmap0.tiles.osgeo.org/wms/vmap0'" ],
41
+ :propierties => { :layers => "'basic'" },
42
+ :description => 'Mapa Libre WMS'},
43
+
44
+ :wms => { :method => "OpenLayers.Layer.WMS",
45
+ :args => [ "'OpenLayers WMS'", "'http://vmap0.tiles.osgeo.org/wms/vmap0'" ],
46
+ :propierties => { :layers => "'basic'" },
47
+ :description => 'Mapa Libre WMS' },
48
+
49
+ :google_streets => { :method => "OpenLayers.Layer.Google",
50
+ :args => [ "'Google Streets'" ],
51
+ :propierties => { :numZoomLevels => "20" },
52
+ :description => 'Mapa StreetsGoogle' },
53
+
54
+ :google_satellite => { :method => "OpenLayers.Layer.Google",
55
+ :args => [ "'Google Satellite'" ],
56
+ :propierties => { :type => "google.maps.MapTypeId.SATELLITE", :numZoomLevels => "22" },
57
+ :description => 'Mapa Satélite de Google' },
58
+
59
+ :google_physical => { :method => "OpenLayers.Layer.Google",
60
+ :args => [ "'Google Physical'" ],
61
+ :propierties => { :type => "google.maps.MapTypeId.TERRAIN" },
62
+ :description => 'Mapa Físico de Google' },
63
+
64
+ :google_hybrid => { :method => "OpenLayers.Layer.Google",
65
+ :args => [ "'Google Hybrid'" ],
66
+ :propierties => { :type => "google.maps.MapTypeId.HYBRID", :numZoomLevels => "22" },
67
+ :description => 'Mapa Híbrido de Google' },
68
+
69
+ :yahoo => { :method => "OpenLayers.Layer.Yahoo",
70
+ :args => [ ],
71
+ :propierties => { },
72
+ :description => 'Mapa Yahoo' },
73
+ :new_elements => { :method => "OpenLayers.Layer.Vector",
74
+ :args => [ "'Vector Layer for create elements'" ],
75
+ :propierties => { },
76
+ :description => 'New Vectors Layer' },
77
+
78
+ :vector_elements => { :method => "OpenLayers.Layer.Vector",
79
+ :args => [ "'Capa de Marcadores''" ],
80
+ :propierties => { },
81
+ :description => 'Capa para marcadores de elements' }
82
+ }
83
+ end
84
+ end
85
+ end
86
+ end
87
+
@@ -0,0 +1,18 @@
1
+ module Ropenlayer
2
+ module Layer
3
+ class ElementsMarker < Base
4
+
5
+ def initialize(map)
6
+ super(:marker_elements, map)
7
+ end
8
+
9
+ private
10
+ def self.layers_config
11
+ { :marker_elements => { :method => "OpenLayers.Layer.Markers",
12
+ :args => [ "'Capa de Marcadores'" ],
13
+ :propierties => { },
14
+ :description => 'Capa para marcadores de elements' } }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ module Ropenlayer
2
+ module Layer
3
+ class ElementsVector < Base
4
+
5
+ def initialize(map)
6
+ super(:vector_elements, map)
7
+ end
8
+
9
+ private
10
+ def self.layers_config
11
+ { :vector_elements => { :method => "OpenLayers.Layer.Vector",
12
+ :args => [ "'Capa de Elementos'" ],
13
+ :propierties => { :styleMap => "#{ Ropenlayer::Js.new_method("OpenLayers.StyleMap", :propierties => { :default => default_vector_style_parameters.to_json }) }" },
14
+ :description => 'Capa para marcadores de elements' } }
15
+ end
16
+
17
+ def self.default_vector_style_parameters
18
+ { :cursor => 'normal',
19
+ :graphicWidth => 48,
20
+ :graphicHeight => 48,
21
+ :strokeColor => '${fillColor}',
22
+ :strokeOpacity => 0.8,
23
+ :strokeWidth => 5,
24
+ :fillColor => '${fillColor}',
25
+ :fillOpacity => 0.8,
26
+ :pointRadius => 30,
27
+ :pointerEvents => 'visiblePainted',
28
+ :fontSize => '12px',
29
+ :fontWeight => 'bold' }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,176 @@
1
+ module Ropenlayer
2
+ class Map
3
+
4
+ attr_reader :js_id
5
+ attr_reader :div_id
6
+ attr_reader :js_propierties
7
+ attr_reader :options
8
+
9
+ attr_reader :layer_names
10
+ attr_reader :layers
11
+
12
+ attr_accessor :layers_select
13
+
14
+ attr_accessor :control_names
15
+ attr_accessor :controls
16
+
17
+ attr_accessor :markers_layer
18
+ attr_accessor :vectors_layer
19
+ attr_accessor :js_notification_area
20
+
21
+ # used to scope js variables created with the map. Js name will be created with this prefix + plus dom_id argument
22
+ MAP_JS_PREFIX = 'olObject'
23
+
24
+ def self.print(map_object, options = {})
25
+ new(map_object, options).to_js
26
+ end
27
+
28
+ # == Initialize
29
+ #
30
+ # Create a map object with parsed attributes. Ropenlayer manage two ids for each map.
31
+ # - js_div, use to scope all the variables names to draw js output.
32
+ # - div_id, the dom_id passed as argument to construtor. For example
33
+ #
34
+ # For example
35
+ #
36
+ # m = Ropenlayer::Map.new('group_map')
37
+ # => <Ropenlayer::Map:0xf7344fe8>
38
+ # m.js_id
39
+ # => "olObject_group_map"
40
+ # n.div_id
41
+ # => "group_map"
42
+ #
43
+ # To draw map, just call to_js method. For example, in a rails 3.x application
44
+ #
45
+ # <%= raw javascript_tag(Ropenlayer::Map.new('group_map').to_js) %>
46
+ #
47
+ # Ropenlayer::Map use this options
48
+ #
49
+ # - layers: Select which layers are used in map. For a list of available layers see <tt>Ropenlayer::Laye::Baser</tt>
50
+ # - default_layer: Default layer at render. Default layers.first
51
+ # - layer_select: If true, map will render a control for change between differents layers
52
+ # - controls: Select which controls are used in map. For a list of available controlse see <tt>Ropenlayer::Control</tt>
53
+ # - latitude: Specify default latitude for map. Map will be pointed at this latitude at render.
54
+ # - longitude: Specify default longitude for map. Map will be pointed at this longitude at render.
55
+ # - zoom: Specify default zoom for map. Map will be render with this zoom enable.
56
+ # - edit_map: If true, map will display a custom control what enable edit capabilities with map
57
+ #
58
+ # Map object accepts other options scoped in :map_js_options key.
59
+ #
60
+ # - theme: CSS theme used to display. By default none is used
61
+ # - projection: Specify projection. Argument must be a valid OpenLayers.Projection JS object. See more on
62
+ # - units: Units for measure. By default: "'m'"
63
+ # - maxResolution: maxResolution of the map, by default word length: "156543.0339"
64
+ # - meaxExtentd: Bound for projection. Must be valid OpenLayers.Bounds object. By default world length bound. See for more info.
65
+ #
66
+ # After display objects, you can, ofc, call methods from openlayers api to instace js variable. For example
67
+ #
68
+ # <% map = Ropenlayer::Map.new('group_map') %>
69
+ # <%= raw javascript_tag map.to_js %>
70
+ # <%= raw javascript_tag "#{ map.js_id }.setCenter(new OpenLayers.LonLat(0,0), 10);" %>
71
+ #
72
+ # Will call the setCenter OpenLayer.Map JS method to map.js_id js instace object
73
+ #
74
+ def initialize(dom_id, options = {})
75
+ @js_id = "#{ MAP_JS_PREFIX }_#{ dom_id }"
76
+ @div_id = "#{ dom_id }"
77
+ @options = options
78
+
79
+ @js_propierties = map_js_propierties(options[:map_js_options])
80
+
81
+ @layer_names = @options[:layers] || self.class.default_layers
82
+ @layers = Ropenlayer::Layer::Base.build_collection(self)
83
+
84
+ @control_names = @options[:controls] || self.class.default_controls
85
+ @controls = Ropenlayer::Control.build_collection(self)
86
+
87
+ @latitude = @options[:latitude] || self.class.default_latitude
88
+ @longitude = @options[:longitude] || self.class.default_longitude
89
+ @zoom = @options[:zoom] || self.class.default_zoom
90
+
91
+ @layers_select = @options[:layer_select].nil? or @options[:layer_select]
92
+ @edit_map = @options[:edit_map]
93
+
94
+ @markers_layer = Ropenlayer::Layer::ElementsMarker.new(self)
95
+ @vectors_layer = Ropenlayer::Layer::ElementsVector.new(self)
96
+
97
+ @js_notification_area = "#{ @js_id }_notification_area"
98
+ end
99
+
100
+ def map_js_propierties(map_js_options = {})
101
+ map_js_options ||= {}
102
+ propierties = {}
103
+
104
+ propierties[:div] = "'#{ div_id }'"
105
+ propierties[:controls] = "[]"
106
+
107
+ propierties[:theme] = map_js_options[:theme] if map_js_options[:theme]
108
+ propierties[:projection] = map_js_options[:projection] || "#{ Ropenlayer::Js.new_method("OpenLayers.Projection", :args => ["'EPSG:900913'"]) }"
109
+ propierties[:units] = map_js_options[:units] || "'m'"
110
+ propierties[:maxResolution] = map_js_options[:units] || "156543.0339"
111
+ propierties[:maxExtent] = map_js_options[:maxExtent] || "#{ Ropenlayer::Js.new_method("OpenLayers.Bounds", :args => ["-20037508", "-20037508", "20037508", "20037508.34"]) }"
112
+ propierties
113
+ end
114
+
115
+
116
+ def set_center
117
+ %(// Setting center
118
+ #{ Ropenlayer::Js.new("#{ @js_id }.setCenter(#{ Ropenlayer::Js.new_method("OpenLayers.LonLat", :args => [ @longitude, @latitude ]) }, #{ @zoom })").to_js } )
119
+ end
120
+
121
+ def add_notification_area
122
+ %(// Notification area
123
+ #{ Ropenlayer::Js.new_var(@js_notification_area,
124
+ Ropenlayer::Js.new_method('Element', :args => ["'div'"],
125
+ :propierties => { :class => "'olMapNotificationArea'",
126
+ :style => "'display: none;'",
127
+ :id => "'#{ @js_notification_area }'" }).to_s).to_js }
128
+ #{ Ropenlayer::Js.new("#{ @js_id }.div.insert(#{ @js_notification_area });").to_js }
129
+ )
130
+ end
131
+
132
+
133
+
134
+ def self.default_layers
135
+ [ :google_hybrid, :google_streets, :wms, :google_satellite, :google_physical, :osm ]
136
+ end
137
+
138
+ def self.default_latitude
139
+ 4580313.35287
140
+ end
141
+
142
+ def self.default_longitude
143
+ 263274.20626803
144
+ end
145
+
146
+ def self.default_zoom
147
+ 4
148
+ end
149
+
150
+ def self.default_controls
151
+ [ :scale_line, :mouse_position, :pan_panel, :navigation, :zoom_panel ]
152
+ end
153
+
154
+ # Map to JS OpenLayer construtor
155
+ def to_js
156
+ %(// Ropenlayer::Map.to_s OpenLayers Cartographic JS project licensed under BSD~style license. More information can be found at http://openlayers.org/
157
+ #{ Ropenlayer::Js.new_var(@js_id, Ropenlayer::Js.new_method("OpenLayers.Map", :propierties => @js_propierties)).to_js }
158
+
159
+ #{ add_notification_area }
160
+
161
+ #{ @layers.map(&:to_js) }
162
+ #{ @controls.map(&:to_js) }
163
+
164
+ #{ set_center }
165
+
166
+ #{ Ropenlayer::BoxControl::LayersSelect.new(self).to_js if @layers_select }
167
+ #{ Ropenlayer::BoxControl::EditMap.new(self).to_js if @edit_map }
168
+
169
+ #{ @vectors_layer.to_js }
170
+ #{ @markers_layer.to_js }
171
+ )
172
+ end
173
+ end
174
+ end
175
+
176
+
data/lib/ropenlayer.rb ADDED
@@ -0,0 +1,17 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'json'
5
+ require 'ropenlayer/map'
6
+ require 'ropenlayer/control'
7
+ require 'ropenlayer/js'
8
+ require 'ropenlayer/box_control/base'
9
+ require 'ropenlayer/box_control/edit_map'
10
+ require 'ropenlayer/box_control/layers_select'
11
+ require 'ropenlayer/layer/base'
12
+ require 'ropenlayer/layer/elements_marker'
13
+ require 'ropenlayer/layer/elements_vector'
14
+
15
+ module Ropenlayer
16
+ VERSION = '0.0.1'
17
+ end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'ropenlayer')
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "ropenlayer"
5
+ s.version = Ropenlayer::VERSION
6
+ s.summary = "Ropenlayer is a wrapper constructor for openlayer javascript library written in ruby. It aims to provide an easy way to build maps and display it on webs."
7
+ s.description = "Ropenlayer is a wrapper constructor for openlayer javascript library written in ruby. It aims to provide an easy way to build maps and display it on webs."
8
+ s.authors = ['Gnoxys' ]
9
+ s.email = ['development@gnoxys.net']
10
+ s.homepage = 'http://gitorious.org/gnoxys/ropenlayer'
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_runtime_dependency('json_pure', '~> 1.2.3')
14
+ s.add_development_dependency('rspec', '~> 2.3.0')
15
+
16
+ if RUBY_VERSION < '1.9'
17
+ s.add_development_dependency('ruby-debug', '~> 0.10.3')
18
+ end
19
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/ropenlayer.rb'}"
9
+ puts "Loading ropenlayer gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ropenlayer
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Gnoxys
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-11 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json_pure
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 3
34
+ version: 1.2.3
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 2
48
+ - 3
49
+ - 0
50
+ version: 2.3.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: ruby-debug
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 49
62
+ segments:
63
+ - 0
64
+ - 10
65
+ - 3
66
+ version: 0.10.3
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: Ropenlayer is a wrapper constructor for openlayer javascript library written in ruby. It aims to provide an easy way to build maps and display it on webs.
70
+ email:
71
+ - development@gnoxys.net
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - .gitignore
80
+ - Gemfile
81
+ - History.txt
82
+ - Manifest.txt
83
+ - PostInstall.txt
84
+ - README.rdoc
85
+ - Rakefile
86
+ - lib/ropenlayer.rb
87
+ - lib/ropenlayer/box_control/base.rb
88
+ - lib/ropenlayer/box_control/edit_map.rb
89
+ - lib/ropenlayer/box_control/layers_select.rb
90
+ - lib/ropenlayer/control.rb
91
+ - lib/ropenlayer/js.rb
92
+ - lib/ropenlayer/layer/base.rb
93
+ - lib/ropenlayer/layer/elements_marker.rb
94
+ - lib/ropenlayer/layer/elements_vector.rb
95
+ - lib/ropenlayer/map.rb
96
+ - ropenlayer.gemspec
97
+ - script/console
98
+ - script/destroy
99
+ - script/generate
100
+ has_rdoc: true
101
+ homepage: http://gitorious.org/gnoxys/ropenlayer
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.3.7
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Ropenlayer is a wrapper constructor for openlayer javascript library written in ruby. It aims to provide an easy way to build maps and display it on webs.
134
+ test_files: []
135
+