ropenlayer 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ropenlayer (0.3.3)
5
- activerecord (~> 3.0.3)
4
+ ropenlayer (0.3.4)
5
+ activerecord (>= 3.0.3)
6
6
  json_pure (~> 1.5.1)
7
- rails (~> 3.0.3)
7
+ rails (>= 3.0.3)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.3.4 2011-05-09
2
+ * Improves
3
+ * Added some test with rspec
4
+ * improve node drawing. all style variables can now be defined in acts_as_localizable_on method
5
+
1
6
  === 0.3.3
2
7
  * Malformed previous release
3
8
 
@@ -69,10 +69,11 @@ module Ropenlayer
69
69
 
70
70
  def node_data
71
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?
72
+ #[ :name, :popup_content, :icon_url, :color ].each do |attribute|
73
+ node_map_attributes = Ropenlayer::Openlayer::Feature.all_attributes.inject({}) do |hash, attribute|
74
+
75
+ hash[attribute] = eval_node_attribute(attributes_config[attribute]) unless attributes_config[attribute].nil?
76
+ hash
76
77
  end
77
78
 
78
79
  if self.node.localizations.any?
@@ -26,8 +26,14 @@ module Ropenlayer
26
26
  self.localizations << self.localizations.new(:longitude => data.split.first, :latitude => data.split.last, :order => order = order.next)
27
27
  end
28
28
  end
29
-
30
29
 
30
+ def main_latitude
31
+ self.localizations.first ? self.localizations.first.latitude : nil
32
+ end
33
+
34
+ def main_longitude
35
+ self.localizations.first ? self.localizations.first.longitude : nil
36
+ end
31
37
  end
32
38
 
33
39
  end
@@ -2,12 +2,45 @@ module Ropenlayer
2
2
  module Openlayer
3
3
  class Feature
4
4
 
5
- DEFAULT_ICON_SIZE = [ 40, 34 ]
6
- DEFAULT_ICON_URL = "/images/ropenlayer/default_marker.png"
7
- DEFAULT_POPUP_SIZE = [ 600, 400 ]
8
-
9
5
  attr_reader :map
10
6
 
7
+ def self.default_attributes
8
+ { # Style Attributes
9
+ :style => {
10
+ :cursor => 'pointer',
11
+ :graphic_width => 32,
12
+ :graphic_height => 32,
13
+ :stroke_color => '#008600',
14
+ :stroke_opacity => 0.9,
15
+ :stroke_width => 2,
16
+ :fill_color => '#008600',
17
+ :fill_opacity => 0.9,
18
+ :point_radius => 5,
19
+ :pointer_events => 'visiblePainted',
20
+ :font_size => '12px',
21
+ :font_weight => 'bold'
22
+ },
23
+ :render => {
24
+ # Render Attributes
25
+ :name => 'Another Feature',
26
+ :icon_url => '/images/ropenlayer/default_marker.png',
27
+ :icon_size => [ 40, 34 ],
28
+ # iccon offsset attribute must be writen as js code.
29
+ # x offset (first value) and y offset (last value) should maybe fixed values or mathematical operations with size var who is actually icon_size x and y values...
30
+ # for example, to offset half of icon dimensions, just type
31
+ # [ '-(size.w/2)', '-(size.h/2)' ]
32
+ :icon_offset => ['-(size.w/2)', '-(size.h/2)'],
33
+ :popup_size => [ 600, 400 ],
34
+ :popup_bgcolor => '#16b87d',
35
+ :popup_content => false
36
+ }
37
+ }
38
+ end
39
+
40
+ def self.all_attributes
41
+ default_attributes.map{|attr| attr.last.keys }.flatten
42
+ end
43
+
11
44
  def self.draw_collection(map_object)
12
45
  features = map_object.draw_features
13
46
  feature_objects = features.inject([]) do |objects, feature_data|
@@ -22,18 +55,23 @@ module Ropenlayer
22
55
  @map = map
23
56
  @id = attributes[:id] || raise("No defined id for feature #{ attributes.inspect }")
24
57
  @js_id = "#{ @map.js_id }node#{ @id }"
25
- @name = attributes[:name] || 'Another Feature'
26
- @popup_content = attributes[:popup_content] || false
27
58
  @geometry = attributes[:geometry] || raise("No defined geometry for feature #{ attributes.inspect }")
28
59
  @longitude = attributes[:longitude] || raise("No defined longitude for feature #{ attributes.inspect }")
29
60
  @latitude = attributes[:latitude] || raise("No defined latitude for feature #{ attributes.inspect }")
30
- @icon_url = attributes[:icon_url]
31
- @icon_size = attributes[:icon_size]
32
- @popup_size = attributes[:popup_size]
33
- @color = attributes[:color]
34
61
  @localizations = attributes[:localizations]
62
+
63
+ @attributes = attributes
64
+ @name = attributes[:name] || 'Another Feature'
65
+
66
+ [:icon_url, :popup_content, :popup_bgcolor ].each do |render_attribute|
67
+ build_render_attribute(render_attribute, String)
68
+ end
69
+ [:icon_size, :popup_size, :icon_offset ].each do |render_attribute|
70
+ build_render_attribute(render_attribute, Array)
71
+ end
72
+
35
73
  end
36
-
74
+
37
75
  def to_js
38
76
  %( #{ build_main_geometry }
39
77
  #{ build_vector_feature }
@@ -44,8 +82,6 @@ module Ropenlayer
44
82
 
45
83
  #{ Ropenlayer::Openlayer::Js.new("#{ @map.markers_layer.js_id }.addMarker(#{ @js_id }MainMarker)").to_js }
46
84
  #{ Ropenlayer::Openlayer::Js.new("#{ @map.vectors_layer.js_id }.addFeatures([#{ @js_id }VectorFeature, #{ @js_id }MainFeature])").to_js }
47
-
48
-
49
85
  )
50
86
 
51
87
  end
@@ -78,17 +114,14 @@ module Ropenlayer
78
114
  def build_vector_feature
79
115
  vector_feature_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Feature.Vector", :args => [ "#{ @js_id }MainGeometry" ]).to_s
80
116
  %( #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }VectorFeature", vector_feature_method).to_js }
81
- #{ Ropenlayer::Openlayer::Js.new("#{ @js_id }VectorFeature.attributes = { name: '#{ @name }', favColor: 'red', fillColor: '#{ @color }' }").to_js } )
117
+ #{ Ropenlayer::Openlayer::Js.new("#{ @js_id }VectorFeature.attributes = #{ build_vector_style_attributes_name.to_json }").to_js } )
82
118
  end
83
-
84
- def build_main_icon
85
- icon_size = (@icon_size and @icon_size.is_a?(Array)) ? @icon_size : DEFAULT_ICON_SIZE
86
- icon_url = (@icon_url and @icon_url.is_a?(String)) ? @icon_url : DEFAULT_ICON_URL
87
119
 
88
- size_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Size", :args => icon_size).to_s
89
- offset_method = Ropenlayer::Openlayer::Js.new("function(size){ return new OpenLayers.Pixel(-(size.w/2), -(size.h*2)) }").to_s
90
-
91
- icon_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Icon", :args => [ "'#{ icon_url }'", size_method, 'null', offset_method ]).to_s
120
+ def build_main_icon
121
+ size_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Size", :args => @icon_size).to_s
122
+ pixel_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Pixel", :args => @icon_offset).to_s
123
+ offset_method = Ropenlayer::Openlayer::Js.new("function(size){ return #{ pixel_method } }").to_s
124
+ icon_method = Ropenlayer::Openlayer::Js.new_method("OpenLayers.Icon", :args => [ "'#{ @icon_url }'", size_method, 'null', offset_method ]).to_s
92
125
  %( #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id }Icon", icon_method).to_js } )
93
126
  end
94
127
 
@@ -101,11 +134,10 @@ module Ropenlayer
101
134
  end
102
135
 
103
136
  def build_marker_click_function
104
- popup_size = (@popup_size and @popup_size.is_a?(Array)) ? @popup_size : DEFAULT_POPUP_SIZE
105
137
  function_content = %(
106
138
  if (this.popup == null) {
107
139
  this.popup = this.createPopup(true);
108
- this.popup.setSize = function(size) { return new OpenLayers.Size(#{ popup_size.join)(',') }); };
140
+ this.popup.setSize = function(size) { return new OpenLayers.Size(#{ @popup_size.join(',') }); };
109
141
  this.popup.setBackgroundColor('#16b87d');
110
142
  this.popup.setContentHTML('#{ @popup_content.gsub("'","") }');
111
143
  #{ @map.js_id }.addPopup(this.popup);
@@ -113,11 +145,24 @@ module Ropenlayer
113
145
  } else {
114
146
  this.popup.toggle();
115
147
  }
116
- OpenLayers.Event.stop(evt);
148
+ //OpenLayers.Event.stop(evt);
117
149
  )
118
150
  %( #{ Ropenlayer::Openlayer::Js.new_var("#{ @js_id}MarkerClickFunction", "function(event) {#{ function_content }}").to_js }
119
151
  #{ Ropenlayer::Openlayer::Js.new("#{ @js_id }MainMarker.events.register('mousedown', #{ @js_id }MainFeature, #{ @js_id}MarkerClickFunction)").to_js } )
120
152
  end
153
+
154
+ def build_vector_style_attributes_name
155
+ style_attributes = self.class.default_attributes[:style].keys
156
+ style_attributes.inject({}) do |hash, attribute|
157
+ hash[attribute] = @attributes[attribute] || self.class.default_attributes[:style][attribute]
158
+ hash
159
+ end
160
+ end
161
+
162
+ def build_render_attribute(attribute, should_be_klass)
163
+ value = (@attributes[attribute] and @attributes[attribute].is_a?(should_be_klass)) ? @attributes[attribute] : self.class.default_attributes[:render][attribute]
164
+ instance_variable_set("@#{ attribute }", value)
165
+ end
121
166
  end
122
167
  end
123
168
  end
@@ -10,24 +10,38 @@ module Ropenlayer
10
10
  private
11
11
  def self.layers_config
12
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' } }
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
16
  end
17
17
 
18
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' }
19
+ { :cursor => '${cursor}',
20
+ :graphicWidth => '${graphic_width}',
21
+ :graphicHeight => '${graphic_height}',
22
+ :strokeColor => '${stroke_color}',
23
+ :strokeOpacity => '${stroke_opacity}',
24
+ :strokeWidth => '${stroke_width}',
25
+ :fillColor => '${fill_color}',
26
+ :fillOpacity => '${fill_opacity}',
27
+ :pointRadius => '${point_radius}',
28
+ :pointerEvents => '${pointer_events}',
29
+ :fontSize => '${font_size}',
30
+ :fontWeight => '${font_weight}'
31
+ }
32
+
33
+ # { :cursor => 'normal',
34
+ # :graphicWidth => 48,
35
+ # :graphicHeight => 48,
36
+ # :strokeColor => '${fillColor}',
37
+ # :strokeOpacity => 0.8,
38
+ # :strokeWidth => 5,
39
+ # :fillColor => '${fillColor}',
40
+ # :fillOpacity => 0.8,
41
+ # :pointRadius => 30,
42
+ # :pointerEvents => 'visiblePainted',
43
+ # :fontSize => '12px',
44
+ # :fontWeight => 'bold' }
31
45
  end
32
46
  end
33
47
  end
@@ -1,3 +1,3 @@
1
1
  module Ropenlayer
2
- VERSION = "0.3.3" unless defined? Ropenlayer::VERSION
2
+ VERSION = "0.3.4" unless defined? Ropenlayer::VERSION
3
3
  end
data/ropenlayer.gemspec CHANGED
@@ -14,9 +14,10 @@ Gem::Specification.new do |s|
14
14
  s.files = `git ls-files`.split("\n")
15
15
 
16
16
  # dependencies
17
- s.add_dependency('json_pure', '~> 1.5.1')
18
- s.add_dependency('rails', '~> 3.0.3')
19
- s.add_dependency('activerecord', '~> 3.0.3')
17
+ s.add_dependency 'json_pure', '~> 1.5.1'
18
+ s.add_dependency 'rails', '>=3.0.3'
19
+ s.add_dependency 'activerecord', '>=3.0.3'
20
+
20
21
  s.add_development_dependency('rspec', '~> 2.5.0')
21
22
  s.add_development_dependency('jasmine', '~> 1.0.2.0')
22
23
 
@@ -0,0 +1,39 @@
1
+
2
+ require File.join(File.dirname(__FILE__),'../../lib/ropenlayer.rb')
3
+
4
+ describe Ropenlayer do
5
+ describe Ropenlayer::Openlayer do
6
+ describe Ropenlayer::Openlayer::Feature do
7
+
8
+ before(:all) do
9
+ @test_map = Ropenlayer::Openlayer::Map.new('test')
10
+ @valid_options = { :id => 'test_feature', :geometry => 'POINT', :longitude => 0, :latitude => 0 }
11
+ @render_options = @valid_options.merge({ :name => 'NOT another feature', :icon_url => '/example', :icon_size => [1,1],
12
+ :popup_size => [1,1], :popup_content => 'hay' })
13
+ end
14
+
15
+ it "should create a new instance given valid attributes. and obtaine default values" do
16
+ feature = Ropenlayer::Openlayer::Feature.new(@test_map, @valid_options)
17
+ feature.class.should == Ropenlayer::Openlayer::Feature
18
+ feature.instance_variable_get("@name").should == 'Another Feature'
19
+ feature.instance_variable_get("@icon_url").should == '/images/ropenlayer/default_marker.png'
20
+ feature.instance_variable_get("@icon_size").should == [40, 34 ]
21
+ feature.instance_variable_get("@popup_size").should == [ 600, 400 ]
22
+ feature.instance_variable_get("@popup_content").should == false
23
+ end
24
+
25
+ it "should have recognize changes in render values" do
26
+ feature = Ropenlayer::Openlayer::Feature.new(@test_map, @render_options)
27
+ feature.class.should == Ropenlayer::Openlayer::Feature
28
+ feature.instance_variable_get("@name").should == 'NOT another feature'
29
+ feature.instance_variable_get("@icon_url").should == '/example'
30
+ feature.instance_variable_get("@icon_size").should == [1, 1 ]
31
+ feature.instance_variable_get("@popup_size").should == [ 1, 1 ]
32
+ feature.instance_variable_get("@popup_content").should == 'hay'
33
+ end
34
+
35
+ end
36
+
37
+
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+
2
+ require File.join(File.dirname(__FILE__),'../../lib/ropenlayer.rb')
3
+
4
+ describe Ropenlayer do
5
+ describe Ropenlayer::Openlayer do
6
+ describe Ropenlayer::Openlayer::Map do
7
+ it "should create a new instance given valid attributes" do
8
+ map = Ropenlayer::Openlayer::Map.new('test')
9
+ map.class.should == Ropenlayer::Openlayer::Map
10
+ end
11
+
12
+ it "should have default values then" do
13
+ map = Ropenlayer::Openlayer::Map.new('test')
14
+ map.js_id.should == 'olObject_test'
15
+ map.div_id.should == 'test'
16
+
17
+
18
+ end
19
+
20
+ end
21
+
22
+
23
+ end
24
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ropenlayer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gnoxys
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-08 00:00:00 +02:00
18
+ date: 2011-05-09 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -38,7 +38,7 @@ dependencies:
38
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ~>
41
+ - - ">="
42
42
  - !ruby/object:Gem::Version
43
43
  hash: 1
44
44
  segments:
@@ -54,7 +54,7 @@ dependencies:
54
54
  version_requirements: &id003 !ruby/object:Gem::Requirement
55
55
  none: false
56
56
  requirements:
57
- - - ~>
57
+ - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  hash: 1
60
60
  segments:
@@ -215,6 +215,8 @@ files:
215
215
  - spec/javascripts/support/jasmine_config.rb
216
216
  - spec/javascripts/support/jasmine_runner.rb
217
217
  - spec/javascripts/support/run.html.erb
218
+ - spec/ropenlayer/feature_spec.rb
219
+ - spec/ropenlayer/map_spec.rb
218
220
  has_rdoc: true
219
221
  homepage: http://gitorious.org/gnoxys/ropenlayer
220
222
  licenses: []