geos-extensions 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{geos-extensions}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["J Smith"]
12
- s.date = %q{2011-06-27}
11
+ s.authors = [%q{J Smith}]
12
+ s.date = %q{2011-07-06}
13
13
  s.description = %q{Extensions for the GEOS library.}
14
14
  s.email = %q{code@zoocasa.com}
15
15
  s.extra_rdoc_files = [
@@ -46,8 +46,8 @@ Gem::Specification.new do |s|
46
46
  "test/writer_test.rb"
47
47
  ]
48
48
  s.homepage = %q{http://github.com/zoocasa/geos-extensions}
49
- s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.7.2}
49
+ s.require_paths = [%q{lib}]
50
+ s.rubygems_version = %q{1.8.5}
51
51
  s.summary = %q{Extensions for the GEOS library.}
52
52
 
53
53
  if s.respond_to? :specification_version then
@@ -9,7 +9,7 @@ module Geos::GoogleMaps::Api3
9
9
  shape
10
10
  }.freeze
11
11
 
12
- # Returns a new LatLngBounds object with the proper GLatLngs in place
12
+ # Returns a new LatLngBounds object with the proper LatLngs in place
13
13
  # for determining the geometry bounds.
14
14
  def to_g_lat_lng_bounds_api3(options = {})
15
15
  "new google.maps.LatLngBounds(#{self.lower_left.to_g_lat_lng_api3(options)}, #{self.upper_right.to_g_lat_lng_api3(options)})"
@@ -49,69 +49,75 @@ module Geos::GoogleMaps::Api3
49
49
  end
50
50
 
51
51
  module CoordinateSequence
52
- # Returns a Ruby Array of GLatLngs.
52
+ UNESCAPED_POLY_OPTIONS = %w{
53
+ clickable
54
+ fillOpacity
55
+ geodesic
56
+ map
57
+ path
58
+ paths
59
+ strokeOpacity
60
+ strokeWeight
61
+ zIndex
62
+ }.freeze
63
+
64
+ # Returns a Ruby Array of LatLngs.
53
65
  def to_g_lat_lng_api3(options = {})
54
66
  self.to_a.collect do |p|
55
67
  "new google.maps.LatLng(#{p[1]}, #{p[0]})"
56
68
  end
57
69
  end
58
70
 
59
- # Returns a new GPolyline. Note that this GPolyline just uses whatever
71
+ # Returns a new Polyline. Note that this Polyline just uses whatever
60
72
  # coordinates are found in the sequence in order, so it might not
61
73
  # make much sense at all.
62
74
  #
63
- # The options Hash follows the Google Maps API arguments to the
64
- # GPolyline constructor and include :color, :weight, :opacity and
65
- # :options. 'null' is used in place of any unset options.
75
+ # The polyline_options Hash follows the Google Maps API arguments to the
76
+ # Polyline constructor and include :clickable, :geodesic, :map, etc. See
77
+ # the Google Maps API documentation for details.
78
+ #
79
+ # The options Hash allows you to specify if certain arguments should be
80
+ # escaped on output. Usually the options in UNESCAPED_POLY_OPTIONS are
81
+ # escaped, but if for some reason you want some other options to be
82
+ # escaped, pass them along in options[:escape]. The options Hash also
83
+ # passes along options to to_g_lat_lng_api3.
66
84
  def to_g_polyline_api3(polyline_options = {}, options = {})
67
- klass = if options[:short_class]
68
- 'GPolyline'
69
- else
70
- 'google.maps.Polyline'
71
- end
72
-
73
- poly_opts = if polyline_options[:polyline_options]
74
- Geos::Helper.camelize_keys(polyline_options[:polyline_options])
75
- end
85
+ options = {
86
+ :escape => [],
87
+ :lat_lng_options => {}
88
+ }.merge(options)
76
89
 
77
- args = [
78
- (polyline_options[:color] ? "'#{Geos::Helper.escape_javascript(polyline_options[:color])}'" : 'null'),
79
- (polyline_options[:weight] || 'null'),
80
- (polyline_options[:opacity] || 'null'),
81
- (poly_opts ? poly_opts.to_json : 'null')
82
- ].join(', ')
90
+ opts = Geos::Helper.camelize_keys(polyline_options)
91
+ opts[:path] = "[#{self.to_g_lat_lng_api3(options[:lat_lng_options]).join(', ')}]"
92
+ json = Geos::Helper.escape_json(opts, UNESCAPED_POLY_OPTIONS - options[:escape])
83
93
 
84
- "new #{klass}([#{self.to_g_lat_lng(options).join(', ')}], #{args})"
94
+ "new google.maps.Polyline(#{json})"
85
95
  end
86
96
 
87
- # Returns a new GPolygon. Note that this GPolygon just uses whatever
97
+ # Returns a new Polygon. Note that this Polygon just uses whatever
88
98
  # coordinates are found in the sequence in order, so it might not
89
99
  # make much sense at all.
90
100
  #
91
- # The options Hash follows the Google Maps API arguments to the
92
- # GPolygon constructor and include :stroke_color, :stroke_weight,
93
- # :stroke_opacity, :fill_color, :fill_opacity and :options. 'null' is
94
- # used in place of any unset options.
101
+ # The polygon_options Hash follows the Google Maps API arguments to the
102
+ # Polyline constructor and include :clickable, :geodesic, :map, etc. See
103
+ # the Google Maps API documentation for details.
104
+ #
105
+ # The options Hash allows you to specify if certain arguments should be
106
+ # escaped on output. Usually the options in UNESCAPED_POLY_OPTIONS are
107
+ # escaped, but if for some reason you want some other options to be
108
+ # escaped, pass them along in options[:escape]. The options Hash also
109
+ # passes along options to to_g_lat_lng_api3.
95
110
  def to_g_polygon_api3(polygon_options = {}, options = {})
96
- klass = if options[:short_class]
97
- 'GPolygon'
98
- else
99
- 'google.maps.Polygon'
100
- end
111
+ options = {
112
+ :escape => [],
113
+ :lat_lng_options => {}
114
+ }.merge(options)
101
115
 
102
- poly_opts = if polygon_options[:polygon_options]
103
- Geos::Helper.camelize_keys(polygon_options[:polygon_options])
104
- end
116
+ opts = Geos::Helper.camelize_keys(polygon_options)
117
+ opts[:paths] = "[#{self.to_g_lat_lng_api3(options[:lat_lng_options]).join(', ')}]"
118
+ json = Geos::Helper.escape_json(opts, UNESCAPED_POLY_OPTIONS - options[:escape])
105
119
 
106
- args = [
107
- (polygon_options[:stroke_color] ? "'#{Geos::Helper.escape_javascript(polygon_options[:stroke_color])}'" : 'null'),
108
- (polygon_options[:stroke_weight] || 'null'),
109
- (polygon_options[:stroke_opacity] || 'null'),
110
- (polygon_options[:fill_color] ? "'#{Geos::Helper.escape_javascript(polygon_options[:fill_color])}'" : 'null'),
111
- (polygon_options[:fill_opacity] || 'null'),
112
- (poly_opts ? poly_opts.to_json : 'null')
113
- ].join(', ')
114
- "new #{klass}([#{self.to_g_lat_lng_api3(options).join(', ')}], #{args})"
120
+ "new google.maps.Polygon(#{json})"
115
121
  end
116
122
  end
117
123
 
@@ -132,14 +138,14 @@ module Geos::GoogleMaps::Api3
132
138
  end
133
139
 
134
140
  module Polygon
135
- # Returns a GPolyline of the exterior ring of the Polygon. This does
141
+ # Returns a Polyline of the exterior ring of the Polygon. This does
136
142
  # not take into consideration any interior rings the Polygon may
137
143
  # have.
138
144
  def to_g_polyline_api3(polyline_options = {}, options = {})
139
145
  self.exterior_ring.to_g_polyline_api3(polyline_options, options)
140
146
  end
141
147
 
142
- # Returns a GPolygon of the exterior ring of the Polygon. This does
148
+ # Returns a Polygon of the exterior ring of the Polygon. This does
143
149
  # not take into consideration any interior rings the Polygon may
144
150
  # have.
145
151
  def to_g_polygon_api3(polygon_options = {}, options = {})
@@ -148,7 +154,7 @@ module Geos::GoogleMaps::Api3
148
154
  end
149
155
 
150
156
  module GeometryCollection
151
- # Returns a Ruby Array of GPolylines for each geometry in the
157
+ # Returns a Ruby Array of Polylines for each geometry in the
152
158
  # collection.
153
159
  def to_g_polyline_api3(polyline_options = {}, options = {})
154
160
  self.collect do |p|
@@ -156,7 +162,7 @@ module Geos::GoogleMaps::Api3
156
162
  end
157
163
  end
158
164
 
159
- # Returns a Ruby Array of GPolygons for each geometry in the
165
+ # Returns a Ruby Array of Polygons for each geometry in the
160
166
  # collection.
161
167
  def to_g_polygon_api3(polygon_options = {}, options = {})
162
168
  self.collect do |p|
@@ -166,4 +172,4 @@ module Geos::GoogleMaps::Api3
166
172
  end
167
173
  end
168
174
 
169
- Geos::GoogleMaps.use_api(2)
175
+ Geos::GoogleMaps.use_api(3)
@@ -17,7 +17,7 @@ module Geos
17
17
  autoload :ActiveRecord, File.join(GEOS_EXTENSIONS_BASE, *%w{ geos active_record_extensions })
18
18
  autoload :GoogleMaps, File.join(GEOS_EXTENSIONS_BASE, *%w{ geos google_maps })
19
19
 
20
- REGEXP_WKT = /^(?:SRID=(-?[0-9]+);)?(\s*[PLMCG].+)/i
20
+ REGEXP_WKT = /^\s*(?:SRID=(-?[0-9]+);)?(\s*[PLMCG].+)/im
21
21
  REGEXP_WKB_HEX = /^[A-Fa-f0-9\s]+$/
22
22
  REGEXP_G_LAT_LNG_BOUNDS = /^
23
23
  \(
@@ -48,44 +48,40 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
48
48
  if defined?(JSON)
49
49
  def test_to_g_polygon
50
50
  assert_equal(
51
- "new google.maps.Polygon([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)], null, null, null, null, null, null)",
51
+ %{new google.maps.Polygon({"paths": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)]})},
52
52
  @polygon.to_g_polygon
53
53
  )
54
54
 
55
55
  assert_equal(
56
- "new google.maps.Polygon([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)], '#b00b1e', 5, 0.5, '#b00b1e', null, {\"mouseOutTolerence\":5})",
56
+ "new google.maps.Polygon({\"strokeColor\": \"#b00b1e\", \"paths\": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)], \"fillColor\": \"#b00b1e\", \"strokeWeight\": 5, \"map\": map, \"strokeOpacity\": 0.5})",
57
57
  @polygon.to_g_polygon(
58
58
  :stroke_color => '#b00b1e',
59
59
  :stroke_weight => 5,
60
60
  :stroke_opacity => 0.5,
61
61
  :fill_color => '#b00b1e',
62
- :polygon_options => {
63
- :mouse_out_tolerence => 5
64
- }
62
+ :map => 'map'
65
63
  )
66
64
  )
67
65
  end
68
66
 
69
67
  def test_to_g_polyline
70
68
  assert_equal(
71
- "new google.maps.Polyline([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)], null, null, null, null)",
69
+ "new google.maps.Polyline({\"path\": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)]})",
72
70
  @polygon.to_g_polyline
73
71
  )
74
72
 
75
73
  assert_equal(
76
- "new google.maps.Polyline([new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)], '#b00b1e', 5, 0.5, {\"mouseOutTolerence\":5})",
74
+ "new google.maps.Polyline({\"path\": [new google.maps.LatLng(0.0, 0.0), new google.maps.LatLng(1.0, 1.0), new google.maps.LatLng(2.5, 2.5), new google.maps.LatLng(5.0, 5.0), new google.maps.LatLng(0.0, 0.0)], \"strokeColor\": \"#b00b1e\", \"strokeWeight\": 5, \"map\": map, \"strokeOpacity\": 0.5})",
77
75
  @polygon.to_g_polyline(
78
- :color => '#b00b1e',
79
- :weight => 5,
80
- :opacity => 0.5,
81
- :polyline_options => {
82
- :mouse_out_tolerence => 5
83
- }
76
+ :stroke_color => '#b00b1e',
77
+ :stroke_weight => 5,
78
+ :stroke_opacity => 0.5,
79
+ :map => 'map'
84
80
  )
85
81
  )
86
82
  end
87
83
 
88
- def test_to_g_marker_long
84
+ def test_to_g_marker
89
85
  marker = @point.to_g_marker
90
86
 
91
87
  lat, lng, json = if marker =~ /^new\s+
data/test/reader_test.rb CHANGED
@@ -109,4 +109,17 @@ class GeosReaderTests < Test::Unit::TestCase
109
109
  assert_saneness_of_polygon(polygon)
110
110
  end
111
111
  end
112
+
113
+ def test_read_wkt_with_newlines
114
+ geom = Geos.read(<<-EOF)
115
+ POLYGON((
116
+ 0 0,
117
+ 10 10,
118
+ 0 10,
119
+ 0 0
120
+ ))
121
+ EOF
122
+
123
+ assert_equal('POLYGON ((0 0, 10 10, 0 10, 0 0))', geom.to_wkt(:trim => true))
124
+ end
112
125
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geos-extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - J Smith
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-27 00:00:00 Z
18
+ date: 2011-07-06 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Extensions for the GEOS library.
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements: []
85
85
 
86
86
  rubyforge_project:
87
- rubygems_version: 1.7.2
87
+ rubygems_version: 1.8.5
88
88
  signing_key:
89
89
  specification_version: 3
90
90
  summary: Extensions for the GEOS library.