ropenlayer 0.0.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,109 @@
1
+ module Ropenlayer
2
+ module ActsAs
3
+
4
+ # acts_as_localizable_on: give to the model facilities to store and draw object in a map.
5
+ #
6
+ # class Team < ActiveRecord::Base
7
+ # acts_as_map :default_layer => :google_streets, :nodes => [ :offices ]
8
+ # end
9
+ #
10
+ # class Office < ActiveRecord::Base
11
+ # belongs_to :team
12
+ # acts_as_localizable_on :team
13
+ # end
14
+ #
15
+ # Avalaible options:
16
+ #
17
+ # All the options can be mapped to a Proc object that will bind self or a Symbol which perform send(:symbol) method.
18
+ # - :name, :Name of the point. By default, Just another Element
19
+ # - :popup_content:Content of the popup, if set, element will render a popup in click with this xhtml content. by default, is false
20
+ # - :icon_url: Icon url to show, by default, /images/ropenlayer/default_marker.png
21
+ # - :color: Background color, by default transparent
22
+ #
23
+ # Examples
24
+ #
25
+ # Build a Map of the team offices with custom icons
26
+ #
27
+ # # on app/models/team.rb
28
+ # class Team < ActiveRecord::Base
29
+ # has_many :offices
30
+ # acts_as_map :default_layer => :google_streets, :latitude => 40000.23, :longitude => 54555.233, :zoom => 3
31
+ # :nodes => [ :offices ]
32
+ # end
33
+ #
34
+ # # on app/models/office.rb
35
+ # class Office < ActiveRecord::Base
36
+ # belongs_to :team
37
+ # acts_as_localizable_on :team, :icon_url => Proc.new{|o| o.main ? '/images/main_office.png' : '/images/office.png' },
38
+ # :color => Proc.new{|o| o.main ? 'red' : 'blue' },
39
+ # :popup_content => :full_description
40
+ #
41
+ # def full_description
42
+ # %( #{ name } - #{ address } )
43
+ # end
44
+ # end
45
+ #
46
+ #
47
+ # on your view, just
48
+ #
49
+ # apps/views/offices/index.html
50
+ #
51
+ # <div id="offices_for_team_map" style="width: 500px; height: 400px;"></div>
52
+ # <%= raw @team.ropenlayer_map(:id => 'offices_for_team_map').to_js %>
53
+ module Nodeable
54
+
55
+ class << self
56
+ def included(base)
57
+
58
+ base.class_eval do
59
+
60
+ has_one :node, :as => :nodeable, :dependent => :destroy, :include => :localizations, :class_name => "Ropenlayer::Node"
61
+ accepts_nested_attributes_for :node
62
+
63
+ base.send :include, InstanceMethods
64
+
65
+ end
66
+ end
67
+
68
+ module InstanceMethods
69
+
70
+ def node_data
71
+ attributes_config = self.class.ropenlayer_node_config[:attributes] || {}
72
+
73
+ node_map_attributes = { }
74
+ [ :name, :popup_content, :icon_url, :color ].each do |attribute|
75
+ node_map_attributes[attribute] = eval_node_attribute(attributes_config[attribute]) unless attributes_config[attribute].nil?
76
+ end
77
+
78
+ if self.node.localizations.any?
79
+ node_map_attributes[:id] = self.node.id
80
+ node_map_attributes[:geometry] = self.node.geometry
81
+ node_map_attributes[:longitude] = self.node.localizations.first.longitude
82
+ node_map_attributes[:latitude] = self.node.localizations.first.latitude
83
+ node_map_attributes[:localizations] = self.node.localizations.map{|l| { :latitude => l.latitude, :longitude => l.longitude }}
84
+ else
85
+ node_map_attributes = nil
86
+ end
87
+ node_map_attributes
88
+ end
89
+
90
+ def ensure_nodeable_model
91
+ raise "Model `#{ self.class }` doesnt acts as nodeable" unless self.class.methods.include?("acts_as_nodeable") and self.class.acts_as_nodeable
92
+ end
93
+
94
+ private
95
+ def eval_node_attribute(attribute)
96
+ case attribute
97
+ when Symbol
98
+ return self.send(attribute)
99
+ when Proc
100
+ return attribute.call(self)
101
+ else
102
+ return attribute
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,138 @@
1
+ module Ropenlayer
2
+ module ActsAs
3
+
4
+ # acts_as_map: give to the model map construiction and build facilities.
5
+ #
6
+ # class Team < ActiveRecord::Base
7
+ # acts_as_map :default_layer => :google_streets
8
+ # end
9
+ #
10
+ # Avalaible options:
11
+ #
12
+ # - :longitude, :latitude, :zoom : Default starting values for map. Can be a float (latitude, longitude) or integer (zoom) object, so values will be parsed as them are.
13
+ # A Symbol, in this case, ropenlayer will send :symbol method to mapper instance, or a valid Proc object
14
+ # - :default_layer: Default layer for visualization. For avalaible layers see Ropenlayer::Openlayer::Map
15
+ # - :nodes: Relations which can be pointed on the map. Relations are expected to have acts_as_localizable_on behaviour in their class
16
+ #
17
+ # Examples
18
+ #
19
+ # Build a Map with static features, just for localization
20
+ #
21
+ # class Team < ActiveRecord::Base
22
+ # acts_as_map :default_layer => :google_streets, :latitude => 40000.23, :longitude => 54555.233, :zoom => 3
23
+ # end
24
+ #
25
+ # Build a Map with Proc calls to perform automatic localization on forms
26
+ #
27
+ # class Team < ActiveRecord
28
+ #
29
+ # has_many :offices
30
+ # has_one :main_office, :conditions => { :main => true }
31
+ #
32
+ # acts_as_map :default_layer => :google_streets, :longitude => :main_office_longitude, :latitude => :main_office_latitude, :zoom => :main_office_zoom
33
+ # :nodes => [ :offices ]
34
+ #
35
+ # def main_office_longitude
36
+ # main_office.longitude
37
+ # end
38
+ #
39
+ # def main_office_longitude=(value)
40
+ # main_office_longitude = value
41
+ # end
42
+ #
43
+ # def main_office_latitude
44
+ # main_office.latitude
45
+ # end
46
+ #
47
+ # def main_office_latitude=(value)
48
+ # main_office.latitude = value
49
+ # end
50
+ #
51
+ # def main_office_longitude
52
+ # main_office.longitude
53
+ # end
54
+ #
55
+ # def main_office_zoom=(value)
56
+ # main_office.zoom = value
57
+ # end
58
+ #
59
+ # end
60
+ #
61
+ def acts_as_map(options = {})
62
+
63
+ class_eval do
64
+
65
+ cattr_reader :acts_as_mapper, :ropenlayer_mapper_config, :localizable
66
+
67
+ send("class_variable_set", "@@acts_as_mapper", true)
68
+ send("class_variable_set", "@@ropenlayer_mapper_config", options)
69
+
70
+ include Ropenlayer::ActsAs::Mapper
71
+
72
+ end
73
+ end
74
+
75
+ # acts_as_localizable_on: give to the model facilities to store and draw object in a map.
76
+ #
77
+ # class Team < ActiveRecord::Base
78
+ # acts_as_map :default_layer => :google_streets, :nodes => [ :offices ]
79
+ # end
80
+ #
81
+ # class Office < ActiveRecord::Base
82
+ # belongs_to :team
83
+ # acts_as_localizable_on :team
84
+ # end
85
+ #
86
+ # Avalaible options:
87
+ #
88
+ # All the options can be mapped to a Proc object that will bind self or a Symbol which perform send(:symbol) method.
89
+ # - :name, :Name of the point. By default, Just another Element
90
+ # - :popup_content:Content of the popup, if set, element will render a popup in click with this xhtml content. by default, is false
91
+ # - :icon_url: Icon url to show, by default, /images/ropenlayer/default_marker.png
92
+ # - :color: Background color, by default transparent
93
+ #
94
+ # Examples
95
+ #
96
+ # Build a Map of the team offices with custom icons
97
+ #
98
+ # # on app/models/team.rb
99
+ # class Team < ActiveRecord::Base
100
+ # has_many :offices
101
+ # acts_as_map :default_layer => :google_streets, :latitude => 40000.23, :longitude => 54555.233, :zoom => 3
102
+ # :nodes => [ :offices ]
103
+ # end
104
+ #
105
+ # # on app/models/office.rb
106
+ # class Office < ActiveRecord::Base
107
+ # belongs_to :team
108
+ # acts_as_localizable_on :team, :icon_url => Proc.new{|o| o.main ? '/images/main_office.png' : '/images/office.png' },
109
+ # :color => Proc.new{|o| o.main ? 'red' : 'blue' },
110
+ # :popup_content => :full_description
111
+ #
112
+ # def full_description
113
+ # %( #{ name } - #{ address } )
114
+ # end
115
+ # end
116
+ #
117
+ #
118
+ # on your view, just
119
+ #
120
+ # apps/views/offices/index.html
121
+ #
122
+ # <div id="offices_for_team_map" style="width: 500px; height: 400px;"></div>
123
+ # <%= raw @team.ropenlayer_map(:id => 'offices_for_team_map').to_js %>
124
+ def acts_as_localizable_on(relation, options = {})
125
+
126
+ class_eval do
127
+
128
+ cattr_reader :acts_as_nodeable
129
+ cattr_reader :ropenlayer_node_config
130
+
131
+ send("class_variable_set", "@@acts_as_nodeable", true)
132
+ send("class_variable_set", "@@ropenlayer_node_config", options)
133
+
134
+ include Ropenlayer::ActsAs::Nodeable
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,14 @@
1
+ module Ropenlayer
2
+ class Category < ActiveRecord::Base
3
+
4
+ set_table_name :ropenlayer_categories
5
+
6
+ belongs_to :mapper, :polymorphic => true
7
+
8
+ #before_save :ensure_format, Proc.new {|category| category.color.match(/^\#/) ? '' : category.color = "##{ category.color }"
9
+
10
+ end
11
+
12
+
13
+
14
+ end
@@ -0,0 +1,69 @@
1
+ module Ropenlayer
2
+ module FormBuilder
3
+
4
+ def map_localization(options = {}, map_div_options = {})
5
+ self.object.ensure_mapper_model
6
+ self.object.ensure_localizable_model
7
+
8
+ klass_config = self.object.class.ropenlayer_mapper_config
9
+ dom_id_map = "ropenlayer_#{ @template.params[:action] }_#{ @template.params[:controller] }"
10
+
11
+ map = self.object.build_map(dom_id_map, klass_config)
12
+
13
+ map_div_options.merge!(:id => dom_id_map)
14
+
15
+ return_tag = ''
16
+
17
+ [ :longitude , :latitude, :zoom ].each do |data|
18
+ id_hidden_value = "#{ self.object.class.name.underscore }_#{ klass_config[data] }"
19
+ map.form_localizations_fields[data] = id_hidden_value
20
+ return_tag << hidden_field(klass_config[data], :id => id_hidden_value)
21
+ end
22
+
23
+
24
+ return_tag << "#{ @template.content_tag("div", '', map_div_options) } #{ @template.javascript_tag map.to_js }"
25
+ return_tag << localization_helper(map)
26
+ @template.raw return_tag
27
+ end
28
+
29
+
30
+ def map_nodes_editor(mapper_relation, options = {}, map_div_options = {})
31
+ self.object.ensure_nodeable_model
32
+ mapper = self.object.send(mapper_relation)
33
+ mapper.ensure_mapper_model
34
+
35
+ mapper_config = mapper.class.ropenlayer_mapper_config
36
+ nodeable_config = self.object.class.ropenlayer_node_config
37
+
38
+ mapper_config.merge!(:edit_map => true)
39
+
40
+ dom_id_map = "ropenlayer_#{ mapper.class }_#{ @template.params[:action] }_#{ @template.params[:controller] }"
41
+ map = mapper.build_map(dom_id_map, mapper_config)
42
+
43
+ map_div_options.merge!(:id => dom_id_map)
44
+
45
+
46
+ return_tag = ''
47
+
48
+ self.object.node ||= self.object.build_node # FIXME has_many relation!
49
+
50
+ self.fields_for :node do |node_form|
51
+ return_tag << node_form.hidden_field(:geometry_string)
52
+ end
53
+
54
+ return_tag << @template.javascript_tag("#{ map.js_helper.create_new_feature_callback(map, self) }") unless map.options[:add_feature_callback] != map.class::DEFAULT_ADD_FEATURE_CALLBACK
55
+ return_tag << "#{ @template.content_tag("div", '', map_div_options) }#{ @template.javascript_tag map.to_js }"
56
+
57
+ @template.raw return_tag
58
+ end
59
+
60
+
61
+ private
62
+ def localization_helper(ropenlayer_object)
63
+ @template.link_to_function 'Store localization', "a = #{ ropenlayer_object.js_id }.getCenter(); long_dom = getElementById('#{ ropenlayer_object.form_localizations_fields[:longitude] }'); long_dom.value = a['lon']; lat_dom = getElementById('#{ ropenlayer_object.form_localizations_fields[:latitude] }'); lat_dom.value = a['lat']; b = #{ ropenlayer_object.js_id }.getZoom(); zoom_dom = getElementById('#{ ropenlayer_object.form_localizations_fields[:zoom] }'); zoom_dom.value = b; #{ ropenlayer_object.js_notification_area }.innerHTML = 'kk'"
64
+ end
65
+
66
+
67
+ end
68
+ end
69
+
@@ -0,0 +1,12 @@
1
+ module Ropenlayer
2
+ class Icon < ActiveRecord::Base
3
+
4
+ set_table_name :ropenlayer_icons
5
+
6
+ belongs_to :mapper, :polymorphic => true
7
+
8
+ #has_attached_file :logo, :styles => { :'48' => "48x48", :'64' => "64x64", :'128' => "128x128", :'256' => "256x256" }
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,63 @@
1
+ module Ropenlayer
2
+ module JsHelper
3
+ module Jquery
4
+
5
+ def self.create_xhtml_element(element_type, attributes = {})
6
+
7
+ inner_html = attributes.delete(:inner_html)
8
+
9
+
10
+ js_element = Ropenlayer::Openlayer::Js.new("$('<#{ element_type }")
11
+
12
+
13
+ attributes.each do |name, value|
14
+ if name.to_s.match(/^on/)
15
+ gsub_value = value.gsub("'","\\\\'")
16
+ else
17
+ gsub_value = value.gsub("'","")
18
+ end
19
+
20
+ js_element.body << %( #{ name }="#{ gsub_value }" )
21
+
22
+ end
23
+ js_element.body << ">"
24
+ js_element.body << inner_html.gsub("'","") if inner_html
25
+
26
+ js_element.body << "</#{ element_type }>')"
27
+ js_element.to_s
28
+ end
29
+
30
+ def self.create_new_feature_callback(map, form)
31
+ Ropenlayer::Openlayer::Js.new("function addFeatureToMap(feature) {
32
+
33
+ total_features = feature.layer.features.length;
34
+
35
+ // Right now, just one feature for node
36
+ if(total_features > 1) {
37
+ first_feature = feature.layer.features[0];
38
+ feature.layer.removeFeatures(first_feature);
39
+ }
40
+ //update_geomtry
41
+ $('##{ form.object.class.name.underscore }_node_attributes_geometry_string').attr('value', feature.geometry);
42
+
43
+ }").to_s
44
+ end
45
+
46
+ def self.insert_into_xhtml_element(js_element, content)
47
+ Ropenlayer::Openlayer::Js.new("$(#{ js_element }).append(#{ content })").to_s
48
+ end
49
+
50
+ def self.update_xhtml_element(js_element, content)
51
+ Ropenlayer::Openlayer::Js.new("#{ js_element }.innerHTML = #{ content }").to_s
52
+ end
53
+
54
+ def self.hide_xhtml_element(js_element)
55
+ Ropenlayer::Openlayer::Js.new("$(#{ js_element }).hide()").to_s
56
+ end
57
+
58
+ def self.toggle_xhtml_element(js_element)
59
+ Ropenlayer::Openlayer::Js.new("$(#{ js_element }).toggle()").to_s
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,51 @@
1
+ module Ropenlayer
2
+ module JsHelper
3
+ module Prototype
4
+
5
+ def self.create_xhtml_element(element_type, attributes = {})
6
+ inner_html = attributes.delete(:inner_html)
7
+
8
+ return_js = Ropenlayer::Openlayer::Js.new_method("Element", :args => [ "'#{ element_type }'" ], :propierties => attributes)
9
+ return_js.body << ".update(#{ inner_html })" if inner_html
10
+ return_js.to_s
11
+ end
12
+
13
+
14
+ def self.create_new_feature_callback(map, form)
15
+ Ropenlayer::Openlayer::Js.new("function addFeatureToMap(feature) {
16
+
17
+ total_features = feature.layer.features.size();
18
+
19
+ // Right now, just one feature for node
20
+ if(total_features > 1) {
21
+ first_feature = feature.layer.features.first();
22
+ feature.layer.removeFeatures(first_feature);
23
+ }
24
+ //update_geomtry
25
+ $('#{ form.object.class.name.underscore }_node_attributes_geometry_string').value = feature.geometry;
26
+
27
+ }").to_s
28
+ end
29
+
30
+ def self.insert_into_xhtml_element(js_element, content)
31
+ Ropenlayer::Openlayer::Js.new("#{ js_element }.insert(#{ content })").to_s
32
+ end
33
+
34
+ def self.update_xhtml_element(js_element, content)
35
+ Ropenlayer::Openlayer::Js.new("#{ js_element }.update(#{ content })").to_s
36
+ end
37
+
38
+ def self.hide_xhtml_element(js_element)
39
+ Ropenlayer::Openlayer::Js.new("#{ js_element }.hide()").to_s
40
+ end
41
+
42
+ def self.toggle_xhtml_element(js_element)
43
+ Ropenlayer::Openlayer::Js.new("#{ js_element }.toggle()").to_s
44
+ end
45
+
46
+
47
+
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,6 @@
1
+ module Ropenlayer
2
+ class Localization < ActiveRecord::Base
3
+ set_table_name :ropenlayer_localizations
4
+ belongs_to :nodeable, :polymorphic => true
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ module Ropenlayer
2
+ class Node < ActiveRecord::Base
3
+
4
+ attr_accessor :geometry_string
5
+
6
+ set_table_name :ropenlayer_nodes
7
+
8
+ GEOMETRY_TYPES = %w( POINT LINESTRING POLYGON )
9
+
10
+ belongs_to :map, :polymorphic => true
11
+
12
+ has_many :localizations, :class_name => 'Ropenlayer::Localization'
13
+
14
+ has_one :icon, :class_name => 'Ropenlayer::Icon'
15
+ has_one :category, :class_name => 'Ropenlayer::Category'
16
+
17
+
18
+ def geometry_string
19
+ "#{ geometry }(#{ localizations.map{|l| "#{ l.longitude } #{ l.latitude }"}.join(',')})"
20
+ end
21
+
22
+ def geometry_string=(data)
23
+ self.geometry = data.split('(').first
24
+ localizations_split = data.split('(').last.gsub(')', '').split(',')
25
+
26
+ self.localizations = []
27
+ order = 0
28
+ localizations_split.each do |data|
29
+ self.localizations << self.localizations.new(:longitude => data.split.first, :latitude => data.split.last, :order => order = order.next)
30
+ end
31
+ end
32
+
33
+
34
+ end
35
+
36
+ end
37
+
38
+
@@ -0,0 +1,57 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ module BoxControl
4
+ class Base
5
+
6
+ attr_reader :map
7
+ attr_reader :name
8
+ attr_reader :js_links_id
9
+
10
+ attr_accessor :links
11
+
12
+
13
+ def initialize(name, map, options = {})
14
+ @name = name
15
+ @map = map
16
+ @links = []
17
+
18
+ @js_id = "#{ map.js_id }_#{ name }"
19
+ @js_control_id = "#{ @js_id }_control"
20
+ @js_links_id = "#{ @js_id }_links"
21
+ @js_panel_id = "#{ @js_id }_panel"
22
+
23
+ @css_class = options[:css_class] || "olCustomControl#{ @name.camelize }"
24
+ end
25
+
26
+
27
+ def to_js
28
+
29
+ create_links_container = @map.js_helper.create_xhtml_element("div", { :class => "'#{ @css_class }Links'", :style => "'display: none;'", :id => "'#{ @js_links_id }'" })
30
+ create_openlayer_control = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Control.Button", :propierties => { :displayClass => "'#{ @css_class }'",
31
+ :trigger => "function() { #{ @map.js_helper.toggle_xhtml_element(@js_links_id) } }" }).to_s
32
+ create_openlayer_panel = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Control.Panel", :propierties => { :displayClass => "'#{ @css_class }Panel'",
33
+ :defaultControl => "#{ @js_control_id }" }).to_s
34
+
35
+ %( // Adding #{ @name } box control
36
+
37
+ #{ Ropenlayer::Openlayer::Js.new_var(@js_control_id, create_openlayer_control).to_js }
38
+ #{ Ropenlayer::Openlayer::Js.new_var(@js_links_id, create_links_container).to_js }
39
+ #{ Ropenlayer::Openlayer::Js.new_var(@js_panel_id, create_openlayer_panel).to_js }
40
+
41
+ #{ Ropenlayer::Openlayer::Js.new("#{ @js_panel_id }.addControls([#{ @js_control_id }])").to_js }
42
+ #{ Ropenlayer::Openlayer::Js.new("#{ @map.js_id }.addControls([#{ @js_panel_id }])").to_js }
43
+
44
+ #{ Ropenlayer::Openlayer::Js.new(@map.js_helper.insert_into_xhtml_element("#{ @js_control_id }.div", @js_links_id)).to_js }
45
+
46
+ #{ links.inject('') do |links_string, link_config|
47
+ link_config[:inner_html] = "'#{ link_config.delete(:text) }'"
48
+ 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
49
+ links_string
50
+ end }
51
+
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,85 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ module BoxControl
4
+ class EditMap < Base
5
+ def initialize(map)
6
+ super('edit_map', map, :css_class => 'olControlEditMapControl')
7
+ Ropenlayer::Openlayer::BoxControl::EditMap.controls.each do |control_name, control_options|
8
+
9
+
10
+ @links << { :id => "'link_to_edit_map_control_#{ control_name }'",
11
+ :class => "'olControlEditMapControlLink with_icon action_#{ control_name }'",
12
+ :text => "'#{ control_options[:description] }'",
13
+ :title => "'#{ control_options[:description] }'",
14
+ :onclick => %( #{ map.js_helper.update_xhtml_element(map.js_notification_area, "'#{ control_options[:help]}'") }; \
15
+ #{ map.js_helper.hide_xhtml_element(@js_links_id) }; \
16
+ #{ map.js_id }ActivateEditControl('#{ control_name }'); return false ) }
17
+
18
+ end
19
+ @links << { :id => "'link_to_edit_map_control_cancel'",
20
+ :class => "'olControlEditMapControlLink with_icon action_cancel'",
21
+ :text => "Cancelar",
22
+ :onclick => %( #{ map.js_id }ActivateEditControl('none'); #{ map.js_helper.hide_xhtml_element(@js_links_id) }; return false) }
23
+ end
24
+
25
+ def to_js
26
+ %(
27
+ var #{ map.js_id }EditMapControls = {};
28
+ function #{ map.js_id }ActivateEditControl(selectedControl) {
29
+ for(key in #{ map.js_id }EditMapControls) {
30
+ var control = #{ map.js_id }EditMapControls[key];
31
+ if(selectedControl == key) {
32
+ control.activate();
33
+ } else {
34
+ control.deactivate();
35
+ }
36
+ }
37
+ }
38
+ #{ new_elements_layer = Ropenlayer::Openlayer::Layer::Base.new(:new_elements, @map)
39
+ new_elements_layer.to_js }
40
+
41
+ #{ Ropenlayer::Openlayer::BoxControl::EditMap.controls.inject('') do |edit_controls_js, control_array|
42
+ control_name = control_array.first
43
+ control_options = control_array.last
44
+ control_options[:args] = [ new_elements_layer.js_id, control_options[:args]].flatten
45
+ control_options[:propierties][:featureAdded] = map.options[:add_feature_callback] || 'false' # FIXME
46
+
47
+ edit_controls_js << %( #{ Ropenlayer::Openlayer::Js.new_var("#{ map.js_id }_#{ control_name }",
48
+ "#{ Ropenlayer::Openlayer::Js.new_method(control_options[:method], control_options) }").to_js }
49
+ #{ Ropenlayer::Openlayer::Js.new("#{ map.js_id }.addControl(#{ map.js_id }_#{ control_name })").to_js }
50
+ #{ Ropenlayer::Openlayer::Js.new("#{ map.js_id }EditMapControls['#{ control_name }'] = #{ map.js_id }_#{ control_name }").to_js }
51
+ )
52
+ edit_controls_js
53
+ end }
54
+
55
+ #{ super }
56
+ )
57
+ end
58
+
59
+ private
60
+ def self.controls
61
+ { :add_point => {:method => "OpenLayers.Control.DrawFeature",
62
+ :args => [ "OpenLayers.Handler.Point" ],
63
+ :propierties => { },
64
+ :description => 'Crear un punto',
65
+ :help => 'Para crear un punto en el mapa, haga click en la posición deseada'
66
+ },
67
+ :add_line => { :method => "OpenLayers.Control.DrawFeature",
68
+ :args => [ "OpenLayers.Handler.Path" ],
69
+ :propierties => { },
70
+ :description => 'Crear una línea',
71
+ :help => 'Para crear un punto en el mapa, haga click en la posición deseada'
72
+
73
+ },
74
+ :add_polygon => { :method => "OpenLayers.Control.DrawFeature",
75
+ :args => [ "OpenLayers.Handler.Polygon" ],
76
+ :propierties => { },
77
+ :description => 'Crear un polígono',
78
+ :help => 'Para crear un punto en el mapa, haga click en la posición deseada'
79
+ }
80
+ }
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,17 @@
1
+ module Ropenlayer
2
+ module Openlayer
3
+ module BoxControl
4
+ class LayersSelect < Base
5
+ def initialize(map)
6
+ super('layers_select', map, :css_class => 'olControlLayersBoxControl')
7
+ map.layers.uniq.each do |layer|
8
+ @links << { :id => "'link_to_base_layer_#{ layer.name }'",
9
+ :class => "'olControlLayersBoxControl'",
10
+ :text => " » Usar Mapa #{ layer.config[:description] }",
11
+ :onclick => "#{ map.js_id }.setBaseLayer(#{ layer.js_id }); #{ map.js_helper.hide_xhtml_element(@js_links_id ) }; return false;" }
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end