ropenlayer 0.0.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/History.txt +9 -0
  2. data/Manifest.txt +0 -20
  3. data/PostInstall.txt +1 -2
  4. data/README.rdoc +161 -23
  5. data/lib/generators/ropenlayer/install/INSTALL +16 -0
  6. data/lib/generators/ropenlayer/install/USAGE +7 -0
  7. data/lib/generators/ropenlayer/install/install_generator.rb +20 -0
  8. data/lib/generators/ropenlayer/install/templates/config/initializers/ropenlayer.rb +13 -0
  9. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/add_point_off.png +0 -0
  10. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/add_point_on.png +0 -0
  11. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/blank.gif +0 -0
  12. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/close.gif +0 -0
  13. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/default_marker.png +0 -0
  14. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/drag-rectangle-off.png +0 -0
  15. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/drag-rectangle-on.png +0 -0
  16. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/draw_line_off.png +0 -0
  17. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/draw_line_on.png +0 -0
  18. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/draw_point_off.png +0 -0
  19. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/draw_point_on.png +0 -0
  20. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/draw_polygon_off.png +0 -0
  21. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/draw_polygon_on.png +0 -0
  22. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/edit_map.png +0 -0
  23. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/edit_map_active.png +0 -0
  24. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/editing_tool_bar.png +0 -0
  25. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/layers_switch.png +0 -0
  26. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/layers_switch_active.png +0 -0
  27. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/move_feature_off.png +0 -0
  28. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/move_feature_on.png +0 -0
  29. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/navigation_history.png +0 -0
  30. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/none_button.png +0 -0
  31. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/overview_replacement.gif +0 -0
  32. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/pan-panel-NOALPHA.png +0 -0
  33. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/pan-panel.png +0 -0
  34. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/pan-panel_active.png +0 -0
  35. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/pan_off.png +0 -0
  36. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/pan_on.png +0 -0
  37. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/panning-hand-off.png +0 -0
  38. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/panning-hand-on.png +0 -0
  39. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/remove_point_off.png +0 -0
  40. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/remove_point_on.png +0 -0
  41. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/ruler.png +0 -0
  42. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/save_features_off.png +0 -0
  43. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/save_features_on.png +0 -0
  44. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/view_next_off.png +0 -0
  45. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/view_next_on.png +0 -0
  46. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/view_previous_off.png +0 -0
  47. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/view_previous_on.png +0 -0
  48. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/zoom-panel-NOALPHA.png +0 -0
  49. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/zoom-panel.png +0 -0
  50. data/lib/generators/ropenlayer/install/templates/public/images/ropenlayer/zoom-panel_active.png +0 -0
  51. data/lib/generators/ropenlayer/install/templates/public/stylesheets/ropenlayer.css +430 -0
  52. data/lib/generators/ropenlayer/migration/USAGE +10 -0
  53. data/lib/generators/ropenlayer/migration/migration_generator.rb +22 -0
  54. data/lib/generators/ropenlayer/migration/templates/migration.rb +31 -0
  55. data/lib/ropenlayer/acts_as/mapper.rb +147 -0
  56. data/lib/ropenlayer/acts_as/nodeable.rb +109 -0
  57. data/lib/ropenlayer/acts_as.rb +138 -0
  58. data/lib/ropenlayer/category.rb +14 -0
  59. data/lib/ropenlayer/form_builder.rb +69 -0
  60. data/lib/ropenlayer/icon.rb +12 -0
  61. data/lib/ropenlayer/js_helper/jquery.rb +63 -0
  62. data/lib/ropenlayer/js_helper/prototype.rb +51 -0
  63. data/lib/ropenlayer/localization.rb +6 -0
  64. data/lib/ropenlayer/node.rb +38 -0
  65. data/lib/ropenlayer/openlayer/box_control/base.rb +57 -0
  66. data/lib/ropenlayer/openlayer/box_control/edit_map.rb +85 -0
  67. data/lib/ropenlayer/openlayer/box_control/layers_select.rb +17 -0
  68. data/lib/ropenlayer/openlayer/control.rb +42 -0
  69. data/lib/ropenlayer/openlayer/feature.rb +119 -0
  70. data/lib/ropenlayer/openlayer/js.rb +63 -0
  71. data/lib/ropenlayer/openlayer/layer/base.rb +88 -0
  72. data/lib/ropenlayer/openlayer/layer/elements_marker.rb +20 -0
  73. data/lib/ropenlayer/openlayer/layer/elements_vector.rb +35 -0
  74. data/lib/ropenlayer/openlayer/map.rb +192 -0
  75. data/lib/ropenlayer.rb +59 -14
  76. data/ropenlayer.gemspec +11 -8
  77. metadata +94 -17
  78. data/lib/ropenlayer/box_control/base.rb +0 -47
  79. data/lib/ropenlayer/box_control/edit_map.rb +0 -79
  80. data/lib/ropenlayer/box_control/layers_select.rb +0 -16
  81. data/lib/ropenlayer/control.rb +0 -40
  82. data/lib/ropenlayer/js.rb +0 -62
  83. data/lib/ropenlayer/layer/base.rb +0 -87
  84. data/lib/ropenlayer/layer/elements_marker.rb +0 -18
  85. data/lib/ropenlayer/layer/elements_vector.rb +0 -33
  86. data/lib/ropenlayer/map.rb +0 -176
@@ -0,0 +1,42 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ class Control
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.control_names.inject([]) do |controls, control_name|
12
+ controls << new(control_name, map)
13
+ controls
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 = Ropenlayer::Openlayer::Control.configs[name]
22
+ end
23
+
24
+ def to_js
25
+ %(// Adding #{ @name } control
26
+ #{ Ropenlayer::Openlayer::Js.new_var(@js_id, "#{ Ropenlayer::Openlayer::Js.new_method(@config[:method], @config) }").to_js }
27
+ #{ Ropenlayer::Openlayer::Js.new("#{ map.js_id }.addControl(#{ @js_id })").to_js }
28
+ )
29
+ end
30
+
31
+ private
32
+ def self.configs
33
+ { :layers_switcher => { :method => "OpenLayers.Control.LayerSwitcher", :args => "" },
34
+ :mouse_position => { :method => "OpenLayers.Control.MousePosition", :args => "" },
35
+ :pan_panel => { :method => "OpenLayers.Control.PanPanel", :args => "" },
36
+ :navigation => { :method => "OpenLayers.Control.Navigation", :args => "" },
37
+ :zoom_panel => { :method => "OpenLayers.Control.ZoomPanel", :args => "" },
38
+ :scale_line => { :method => "OpenLayers.Control.ScaleLine", :args => "" }}
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,119 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ class Feature
4
+
5
+ DEFAULT_ICON_SIZE = [ 40, 34 ]
6
+ DEFAULT_ICON_URL = "/images/ropenlayer/default_marker.png"
7
+
8
+ attr_reader :map
9
+
10
+ def self.draw_collection(map_object)
11
+ features = map_object.draw_features
12
+ feature_objects = features.inject([]) do |objects, feature_data|
13
+ objects << new(map_object, feature_data)
14
+ objects
15
+ end
16
+ %( //Adding features
17
+ #{ feature_objects.map(&:to_js) } )
18
+ end
19
+
20
+ def initialize(map, attributes)
21
+ @map = map
22
+ @id = attributes[:id] || raise("No defined id for feature #{ attributes.inspect }")
23
+ @js_id = "#{ @map.js_id }node#{ @id }"
24
+ @name = attributes[:name] || 'Another Feature'
25
+ @popup_content = attributes[:popup_content] || false
26
+ @geometry = attributes[:geometry] || raise("No defined geometry for feature #{ attributes.inspect }")
27
+ @longitude = attributes[:longitude] || raise("No defined longitude for feature #{ attributes.inspect }")
28
+ @latitude = attributes[:latitude] || raise("No defined latitude for feature #{ attributes.inspect }")
29
+ @icon_url = attributes[:icon_url]
30
+ @icon_size = attributes[:icon_size]
31
+ @color = attributes[:color]
32
+ @localizations = attributes[:localizations]
33
+ end
34
+
35
+ def to_js
36
+ %( #{ build_main_geometry }
37
+ #{ build_vector_feature }
38
+ #{ build_main_icon }
39
+ #{ build_main_feature }
40
+
41
+ #{ build_marker_click_function if @popup_content }
42
+
43
+ #{ Ropenlayer::Openlayer::Js.new("#{ @map.markers_layer.js_id }.addMarker(#{ @js_id }MainMarker)").to_js }
44
+ #{ Ropenlayer::Openlayer::Js.new("#{ @map.vectors_layer.js_id }.addFeatures([#{ @js_id }VectorFeature, #{ @js_id }MainFeature])").to_js }
45
+
46
+
47
+ )
48
+
49
+ end
50
+
51
+ private
52
+ def build_main_geometry
53
+ case @geometry
54
+ when "POINT"
55
+ return Ropenlayer::Openlayer::Js.new_var("#{ @js_id }MainGeometry", Ropenlayer::Openlayer::Js.new_method("OpenLayers.Geometry.Point", :args => [ @longitude, @latitude ]).to_s).to_js
56
+ when "LINESTRING"
57
+ return %( #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }LinearPoints", "[]").to_js }
58
+ #{ @localizations.inject('') do |points_in_line, localization|
59
+ point_in_line = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Geometry.Point", :args => [ localization[:longitude], localization[:latitude] ]).to_s
60
+ points_in_line << Ropenlayer::Openlayer::Js.new("#{ @js_id }LinearPoints.push(#{ point_in_line }) ").to_js
61
+ points_in_line
62
+ end }
63
+ #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }MainGeometry", Ropenlayer::Openlayer::Js.new_method("OpenLayers.Geometry.LineString", :args => ["#{ @js_id }LinearPoints"]).to_s).to_js } )
64
+ when "POLYGON"
65
+ return %( #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }LinearPoints", "[]").to_js }
66
+ #{ @localizations.inject('') do |points_in_line, localization|
67
+ point_in_line = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Geometry.Point", :args => [ localization[:longitude], localization[:latitude] ]).to_s
68
+ points_in_line << Ropenlayer::Openlayer::Js.new("#{ @js_id }LinearPoints.push(#{ point_in_line }) ").to_js
69
+ points_in_line
70
+ end }
71
+ #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }LinearRing", Ropenlayer::Openlayer::Js.new_method("OpenLayers.Geometry.LinearRing", :args => ["#{ @js_id }LinearPoints"]).to_s).to_js }
72
+ #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }MainGeometry", Ropenlayer::Openlayer::Js.new_method("OpenLayers.Geometry.Polygon", :args => ["#{ @js_id }LinearRing"]).to_s).to_js } )
73
+ end
74
+ end
75
+
76
+ def build_vector_feature
77
+ vector_feature_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Feature.Vector", :args => [ "#{ @js_id }MainGeometry" ]).to_s
78
+ %( #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }VectorFeature", vector_feature_method).to_js }
79
+ #{ Ropenlayer::Openlayer::Js.new("#{ @js_id }VectorFeature.attributes = { name: '#{ @name }', favColor: 'red', fillColor: '#{ @color }' }").to_js } )
80
+ end
81
+
82
+ def build_main_icon
83
+ icon_size = (@icon_size and @icon_size.is_a?(Array)) ? @icon_size : DEFAULT_ICON_SIZE
84
+ icon_url = (@icon_url and @icon_url.is_a?(String)) ? @icon_url : DEFAULT_ICON_URL
85
+
86
+ size_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Size", :args => icon_size).to_s
87
+ offset_method = Ropenlayer::Openlayer::Js.new("function(size){ return new OpenLayers.Pixel(-(size.w/2), -(size.h/2)) }").to_s
88
+
89
+ icon_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Icon", :args => [ "'#{ icon_url }'", size_method, 'null', offset_method ]).to_s
90
+ %( #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }Icon", icon_method).to_js } )
91
+ end
92
+
93
+ def build_main_feature
94
+ main_feature_lonlat = Ropenlayer::Openlayer::Js.new_method("OpenLayers.LonLat", :args => [ @longitude, @latitude ]).to_s
95
+ main_feature_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Feature", :args => [ @map.vectors_layer.js_id, main_feature_lonlat ]).to_s
96
+ %( #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }MainFeature", main_feature_method).to_js }
97
+ #{ Ropenlayer::Openlayer::Js.new("#{ @js_id }MainFeature.data.icon = #{ @js_id }Icon").to_js }
98
+ #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }MainMarker", "#{ @js_id }MainFeature.createMarker()").to_js } )
99
+ end
100
+
101
+ def build_marker_click_function
102
+ function_content = %(
103
+ if (this.popup == null) {
104
+ this.popup = this.createPopup(true);
105
+ this.popup.setBackgroundColor('#16b87d');
106
+ this.popup.setContentHTML('#{ @popup_content }');
107
+ #{ @map.js_id }.addPopup(this.popup);
108
+ this.popup.show();
109
+ } else {
110
+ this.popup.toggle();
111
+ }
112
+ OpenLayers.Event.stop(evt);
113
+ )
114
+ %( #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id}MarkerClickFunction", "function(event) {#{ function_content }}").to_js }
115
+ #{ Ropenlayer::Openlayer::Js.new("#{ @js_id }MainMarker.events.register('mousedown', #{ @js_id }MainFeature, #{ @js_id}MarkerClickFunction)").to_js } )
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,63 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ class Js
4
+
5
+ attr_accessor :body
6
+
7
+ # == Ropenlayer::Openlayer::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::Openlayer::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
63
+ end
@@ -0,0 +1,88 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ module Layer
4
+ class Base
5
+
6
+ attr_reader :config
7
+ attr_reader :name
8
+ attr_reader :js_id
9
+ attr_reader :map
10
+
11
+ def self.build_collection(map)
12
+ map.layer_names.uniq.inject([]) do |layers, layer_name|
13
+ layers << new(layer_name, map)
14
+ layers
15
+ end
16
+ end
17
+
18
+ def initialize(name, map)
19
+ @name = name
20
+ @map = map
21
+ @js_id = "#{ map.js_id }_#{ name }"
22
+ @config = self.class.layers_config[name]
23
+ end
24
+
25
+ def to_js
26
+ %( // Adding #{ @name } layer
27
+ #{ Ropenlayer::Openlayer::Js.new_var(@js_id, "#{ Ropenlayer::Openlayer::Js.new_method(@config[:method], @config) }").to_js }
28
+ #{ Ropenlayer::Openlayer::Js.new("#{ map.js_id }.addLayer(#{ @js_id })").to_js } )
29
+ end
30
+
31
+ private
32
+ # return a hash with config options for Ropenlayer layers.
33
+ # U can override this method as ur wish to get config from other places, for example, AR.
34
+ def self.layers_config
35
+ { :osm => { :method => "OpenLayers.Layer.OSM",
36
+ :args => [ "'Usar Mapa OSM'" ],
37
+ :propierties => { },
38
+ :description => 'Mapa Libre OSM' },
39
+
40
+ :wms => { :method => "OpenLayers.Layer.WMS",
41
+ :args => [ "'OpenLayers WMS'", "'http://vmap0.tiles.osgeo.org/wms/vmap0'" ],
42
+ :propierties => { :layers => "'basic'" },
43
+ :description => 'Mapa Libre WMS'},
44
+
45
+ :wms => { :method => "OpenLayers.Layer.WMS",
46
+ :args => [ "'OpenLayers WMS'", "'http://vmap0.tiles.osgeo.org/wms/vmap0'" ],
47
+ :propierties => { :layers => "'basic'" },
48
+ :description => 'Mapa Libre WMS' },
49
+
50
+ :google_streets => { :method => "OpenLayers.Layer.Google",
51
+ :args => [ "'Google Streets'" ],
52
+ :propierties => { :numZoomLevels => "20" },
53
+ :description => 'Mapa StreetsGoogle' },
54
+
55
+ :google_satellite => { :method => "OpenLayers.Layer.Google",
56
+ :args => [ "'Google Satellite'" ],
57
+ :propierties => { :type => "google.maps.MapTypeId.SATELLITE", :numZoomLevels => "22" },
58
+ :description => 'Mapa Satélite de Google' },
59
+
60
+ :google_physical => { :method => "OpenLayers.Layer.Google",
61
+ :args => [ "'Google Physical'" ],
62
+ :propierties => { :type => "google.maps.MapTypeId.TERRAIN" },
63
+ :description => 'Mapa Físico de Google' },
64
+
65
+ :google_hybrid => { :method => "OpenLayers.Layer.Google",
66
+ :args => [ "'Google Hybrid'" ],
67
+ :propierties => { :type => "google.maps.MapTypeId.HYBRID", :numZoomLevels => "22" },
68
+ :description => 'Mapa Híbrido de Google' },
69
+
70
+ :yahoo => { :method => "OpenLayers.Layer.Yahoo",
71
+ :args => [ ],
72
+ :propierties => { },
73
+ :description => 'Mapa Yahoo' },
74
+ :new_elements => { :method => "OpenLayers.Layer.Vector",
75
+ :args => [ "'Vector Layer for create elements'" ],
76
+ :propierties => { },
77
+ :description => 'New Vectors Layer' },
78
+
79
+ :vector_elements => { :method => "OpenLayers.Layer.Vector",
80
+ :args => [ "'Capa de Marcadores''" ],
81
+ :propierties => { },
82
+ :description => 'Capa para marcadores de elements' }
83
+ }
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,20 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ module Layer
4
+ class ElementsMarker < Base
5
+
6
+ def initialize(map)
7
+ super(:marker_elements, map)
8
+ end
9
+
10
+ private
11
+ def self.layers_config
12
+ { :marker_elements => { :method => "OpenLayers.Layer.Markers",
13
+ :args => [ "'Capa de Marcadores'" ],
14
+ :propierties => { },
15
+ :description => 'Capa para marcadores de elements' } }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ module Layer
4
+ class ElementsVector < Base
5
+
6
+ def initialize(map)
7
+ super(:vector_elements, map)
8
+ end
9
+
10
+ private
11
+ def self.layers_config
12
+ { :vector_elements => { :method => "OpenLayers.Layer.Vector",
13
+ :args => [ "'Capa de Elementos'" ],
14
+ :propierties => { :styleMap => "#{ Ropenlayer::Openlayer::Js.new_method("OpenLayers.StyleMap", :propierties => { :default => default_vector_style_parameters.to_json }) }" },
15
+ :description => 'Capa para marcadores de elements' } }
16
+ end
17
+
18
+ def self.default_vector_style_parameters
19
+ { :cursor => 'normal',
20
+ :graphicWidth => 48,
21
+ :graphicHeight => 48,
22
+ :strokeColor => '${fillColor}',
23
+ :strokeOpacity => 0.8,
24
+ :strokeWidth => 5,
25
+ :fillColor => '${fillColor}',
26
+ :fillOpacity => 0.8,
27
+ :pointRadius => 30,
28
+ :pointerEvents => 'visiblePainted',
29
+ :fontSize => '12px',
30
+ :fontWeight => 'bold' }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,192 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ class Map
4
+
5
+ attr_reader :js_id
6
+ attr_reader :div_id
7
+ attr_reader :js_propierties
8
+ attr_reader :options
9
+
10
+ attr_reader :layer_names
11
+ attr_reader :layers
12
+
13
+ attr_reader :js_helper
14
+
15
+ attr_accessor :layers_select
16
+
17
+ attr_accessor :control_names
18
+ attr_accessor :controls
19
+
20
+ attr_accessor :markers_layer
21
+ attr_accessor :vectors_layer
22
+ attr_accessor :js_notification_area
23
+
24
+ attr_accessor :form_localizations_fields
25
+
26
+ attr_accessor :draw_features
27
+
28
+
29
+ # used to scope js variables created with the map. Js name will be created with this prefix + plus dom_id argument
30
+ MAP_JS_PREFIX = 'olObject'
31
+ DEFAULT_ADD_FEATURE_CALLBACK = 'addFeatureToMap'
32
+
33
+
34
+ # == Initialize
35
+ #
36
+ # Create a map object with parsed attributes. Ropenlayer manage two ids for each map.
37
+ # - js_div, use to scope all the variables names to draw js output.
38
+ # - div_id, the dom_id passed as argument to construtor. For example
39
+ #
40
+ # For example
41
+ #
42
+ # m = Ropenlayer::Openlayer::Map.new('group_map')
43
+ # => <Ropenlayer::Openlayer::Map:0xf7344fe8>
44
+ # m.js_id
45
+ # => "olObject_group_map"
46
+ # n.div_id
47
+ # => "group_map"
48
+ #
49
+ # To draw map, just call to_js method. For example, in a rails 3.x application
50
+ #
51
+ # <%= raw javascript_tag(Ropenlayer::Openlayer::Map.new('group_map').to_js) %>
52
+ #
53
+ # Ropenlayer::Openlayer::Map use this options
54
+ #
55
+ # - layers: Select which layers are used in map. For a list of available layers see <tt>Ropenlayer::Openlayer::Laye::Baser</tt>
56
+ # - default_layer: Default layer at render. Default layers.first
57
+ # - layer_select: If true, map will render a control for change between differents layers
58
+ # - controls: Select which controls are used in map. For a list of available controlse see <tt>Ropenlayer::Openlayer::Control</tt>
59
+ # - latitude: Specify default latitude for map. Map will be pointed at this latitude at render.
60
+ # - longitude: Specify default longitude for map. Map will be pointed at this longitude at render.
61
+ # - zoom: Specify default zoom for map. Map will be render with this zoom enable.
62
+ # - edit_map: If true, map will display a custom control what enable edit capabilities with map
63
+ #
64
+ # Map object accepts other options scoped in :map_js_options key.
65
+ #
66
+ # - theme: CSS theme used to display. By default none is used
67
+ # - projection: Specify projection. Argument must be a valid OpenLayers.Projection JS object. See more on
68
+ # - units: Units for measure. By default: "'m'"
69
+ # - maxResolution: maxResolution of the map, by default word length: "156543.0339"
70
+ # - meaxExtentd: Bound for projection. Must be valid OpenLayers.Bounds object. By default world length bound. See for more info.
71
+ #
72
+ # After display objects, you can, ofc, call methods from openlayers api to instace js variable. For example
73
+ #
74
+ # <% map = Ropenlayer::Openlayer::Map.new('group_map') %>
75
+ # <%= raw javascript_tag map.to_js %>
76
+ # <%= raw javascript_tag "#{ map.js_id }.setCenter(new OpenLayers.LonLat(0,0), 10);" %>
77
+ #
78
+ # Will call the setCenter OpenLayer.Map JS method to map.js_id js instace object
79
+ #
80
+ def initialize(dom_id, options = {})
81
+ @js_id = "#{ MAP_JS_PREFIX }_#{ dom_id }"
82
+ @div_id = "#{ dom_id }"
83
+
84
+ options[:add_feature_callback] ||= DEFAULT_ADD_FEATURE_CALLBACK
85
+ @options = options
86
+
87
+ @js_propierties = map_js_propierties(options[:map_js_options])
88
+
89
+ @layer_names = @options[:layers] || self.class.default_layers
90
+ if options[:default_layer]
91
+ def_layer = @layer_names.delete(options[:default_layer])
92
+ @layer_names = @layer_names.push(def_layer).reverse if def_layer
93
+ end
94
+
95
+ @layers = Ropenlayer::Openlayer::Layer::Base.build_collection(self)
96
+
97
+ @control_names = @options[:controls] || self.class.default_controls
98
+ @controls = Ropenlayer::Openlayer::Control.build_collection(self)
99
+
100
+ @latitude = @options[:latitude] || self.class.default_latitude
101
+ @longitude = @options[:longitude] || self.class.default_longitude
102
+ @zoom = @options[:zoom] || self.class.default_zoom
103
+
104
+ @layers_select = @options[:layer_select].nil? or @options[:layer_select]
105
+ @edit_map = @options[:edit_map]
106
+
107
+ @markers_layer = Ropenlayer::Openlayer::Layer::ElementsMarker.new(self)
108
+ @vectors_layer = Ropenlayer::Openlayer::Layer::ElementsVector.new(self)
109
+
110
+ @draw_features = options[:draw_features] || []
111
+
112
+ @js_notification_area = "#{ @js_id }_notification_area"
113
+ @form_localizations_fields = {}
114
+
115
+ @js_helper = Ropenlayer.js_helper
116
+ end
117
+
118
+ def map_js_propierties(map_js_options = {})
119
+ map_js_options ||= {}
120
+ propierties = {}
121
+
122
+ propierties[:div] = "'#{ div_id }'"
123
+ propierties[:controls] = "[]"
124
+
125
+ propierties[:theme] = map_js_options[:theme] || "'/stylesheets/ropenlayer.css'"
126
+ propierties[:projection] = map_js_options[:projection] || "#{ Ropenlayer::Openlayer::Js.new_method("OpenLayers.Projection", :args => ["'EPSG:900913'"]) }"
127
+ propierties[:units] = map_js_options[:units] || "'m'"
128
+ propierties[:maxResolution] = map_js_options[:units] || "156543.0339"
129
+ propierties[:maxExtent] = map_js_options[:maxExtent] || "#{ Ropenlayer::Openlayer::Js.new_method("OpenLayers.Bounds", :args => ["-20037508", "-20037508", "20037508", "20037508.34"]) }"
130
+ propierties
131
+ end
132
+
133
+
134
+ def set_center
135
+ %(// Setting center
136
+ #{ Ropenlayer::Openlayer::Js.new("#{ @js_id }.setCenter(#{ Ropenlayer::Openlayer::Js.new_method("OpenLayers.LonLat", :args => [ @longitude, @latitude ]) }, #{ @zoom })").to_js } )
137
+ end
138
+
139
+ def add_notification_area
140
+ %(// Notification area
141
+ #{ Ropenlayer::Openlayer::Js.new_var(@js_notification_area, Ropenlayer::Openlayer::Js.new(@js_helper.create_xhtml_element('div', { :class => "'olMapNotificationArea'",
142
+ :style => "'display: none;'",
143
+ :id => "'#{ @js_notification_area }'" })).to_js) }
144
+ )
145
+ end
146
+
147
+
148
+ def self.default_layers
149
+ [ :google_hybrid, :google_streets, :wms, :google_satellite, :google_physical, :osm ]
150
+ end
151
+
152
+ def self.default_latitude
153
+ 4580313.35287
154
+ end
155
+
156
+ def self.default_longitude
157
+ 263274.20626803
158
+ end
159
+
160
+ def self.default_zoom
161
+ 4
162
+ end
163
+
164
+ def self.default_controls
165
+ [ :scale_line, :mouse_position, :pan_panel, :navigation, :zoom_panel ]
166
+ end
167
+
168
+ # Map to JS OpenLayer construtor
169
+ def to_js
170
+ %( // Ropenlayer::Openlayer::Map.to_s OpenLayers Cartographic JS project licensed under BSD~style license. More information can be found at http://openlayers.org/
171
+ #{ Ropenlayer::Openlayer::Js.new_var(@js_id, Ropenlayer::Openlayer::Js.new_method("OpenLayers.Map", :propierties => @js_propierties)).to_js }
172
+
173
+ #{ add_notification_area }
174
+
175
+ #{ @layers.map(&:to_js) }
176
+ #{ @controls.map(&:to_js) }
177
+
178
+ #{ set_center }
179
+
180
+ #{ Ropenlayer::Openlayer::BoxControl::LayersSelect.new(self).to_js if @layers_select }
181
+ #{ Ropenlayer::Openlayer::BoxControl::EditMap.new(self).to_js if @edit_map }
182
+
183
+ #{ @vectors_layer.to_js }
184
+ #{ @markers_layer.to_js }
185
+
186
+ #{ Ropenlayer::Openlayer::Feature.draw_collection(self) if @draw_features.any? }
187
+ )
188
+ end
189
+ end
190
+ end
191
+ end
192
+
data/lib/ropenlayer.rb CHANGED
@@ -1,17 +1,62 @@
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'
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ # Rubygems and Rails Stuff
4
+ require 'rubygems'
5
+ require 'rails'
6
+ require 'active_record'
14
7
 
15
8
  module Ropenlayer
16
- VERSION = '0.0.1'
9
+
10
+ VERSION = '0.3.0'
11
+
12
+ autoload :Node, 'ropenlayer/node'
13
+ autoload :Localization, 'ropenlayer/localization'
14
+ autoload :ActsAs, 'ropenlayer/acts_as'
15
+ autoload :FormBuilder, 'ropenlayer/form_builder'
16
+
17
+ module ActsAs
18
+ autoload :Mapper, 'ropenlayer/acts_as/mapper'
19
+ autoload :Nodeable, 'ropenlayer/acts_as/nodeable'
20
+ end
21
+
22
+ module JsHelper
23
+ autoload :Jquery, 'ropenlayer/js_helper/jquery'
24
+ autoload :Prototype, 'ropenlayer/js_helper/prototype'
25
+ end
26
+
27
+ module Openlayer
28
+ autoload :Js, 'ropenlayer/openlayer/js'
29
+ autoload :Map, 'ropenlayer/openlayer/map'
30
+ autoload :Control, 'ropenlayer/openlayer/control'
31
+ autoload :Feature, 'ropenlayer/openlayer/feature'
32
+
33
+ module BoxControl
34
+ autoload :Base, 'ropenlayer/openlayer/box_control/base'
35
+ autoload :EditMap, 'ropenlayer/openlayer/box_control/edit_map'
36
+ autoload :LayersSelect, 'ropenlayer/openlayer/box_control/layers_select'
37
+ end
38
+
39
+ module Layer
40
+ autoload :Base, 'ropenlayer/openlayer/layer/base'
41
+ autoload :ElementsMarker, 'ropenlayer/openlayer/layer/elements_marker'
42
+ autoload :ElementsVector, 'ropenlayer/openlayer/layer/elements_vector'
43
+ end
44
+ end
45
+
46
+
47
+ mattr_accessor :js_helper
48
+ @@js_helper = Ropenlayer::JsHelper::Jquery
49
+
50
+ def self.setup
51
+ yield self
52
+ end
53
+
54
+ class Railtie < Rails::Railtie
55
+ initializer 'ropenlayer.initialize' do
56
+ ActiveRecord::Base.extend Ropenlayer::ActsAs
57
+ ActiveSupport.on_load(:action_view) do
58
+ ActionView::Helpers::FormBuilder.send :include, Ropenlayer::FormBuilder
59
+ end
60
+ end
61
+ end
17
62
  end
data/ropenlayer.gemspec CHANGED
@@ -1,18 +1,21 @@
1
1
  require File.join(File.dirname(__FILE__), 'lib', 'ropenlayer')
2
2
 
3
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."
4
+
5
+ # define gem
6
+ s.name = "ropenlayer"
7
+ s.version = Ropenlayer::VERSION
8
+ 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
9
  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")
10
+ s.authors = ['Gnoxys' ]
11
+ s.email = ['development@gnoxys.net']
12
+ s.homepage = 'http://gitorious.org/gnoxys/ropenlayer'
13
+ s.files = `git ls-files`.split("\n")
12
14
 
15
+ # dependencies
13
16
  s.add_runtime_dependency('json_pure', '~> 1.2.3')
17
+ s.add_runtime_dependency('rails', '~> 3.0.3')
14
18
  s.add_development_dependency('rspec', '~> 2.3.0')
15
-
16
19
  if RUBY_VERSION < '1.9'
17
20
  s.add_development_dependency('ruby-debug', '~> 0.10.3')
18
21
  end