Add Google Map of voters
[selectricity-live] / vendor / plugins / ym4r_gm / lib / gm_plugin / helper.rb
1 \r
2 Ym4r::GmPlugin::GPolyline.class_eval do\r
3   #Creates a GPolyline object from a georuby line string. Assumes the points of the line strings are stored in Longitude(x)/Latitude(y) order.\r
4   def self.from_georuby(line_string,color = nil,weight = nil,opacity = nil)\r
5     GPolyline.new(line_string.points.collect { |point| GLatLng.new([point.y,point.x])},color,weight,opacity)\r
6   end\r
7 end\r
8 \r
9 Ym4r::GmPlugin::GMarker.class_eval do\r
10   #Creates a GMarker object from a georuby point. Accepts the same options as the GMarker constructor. Assumes the points of the line strings are stored in Longitude(x)/Latitude(y) order.\r
11   def self.from_georuby(point,options = {})\r
12     GMarker.new([point.y,point.x],options)\r
13   end\r
14 end\r
15 \r
16 Ym4r::GmPlugin::GLatLng.class_eval do\r
17   #Creates a GLatLng object from a georuby point. Assumes the points of the line strings are stored in Longitude(x)/Latitude(y) order.\r
18   def self.from_georuby(point,unbounded = nil)\r
19     GLatLng.new([point.y,point.x],unbounded)\r
20   end\r
21 end\r
22 \r
23 Ym4r::GmPlugin::GLatLngBounds.class_eval do\r
24   #Creates a GLatLng object from a georuby point. Assumes the points of the line strings are stored in Longitude(x)/Latitude(y) order.\r
25   def self.from_georuby(envelope)\r
26     GLatLngBounds.new(GLatLng.from_georuby(envelope.lower_corner),\r
27                       GLatLng.from_georuby(envelope.upper_corner))\r
28   end\r
29 end\r
30 \r
31 Ym4r::GmPlugin::GPolygon.class_eval do\r
32   #Creates a GPolygon object from a georuby polygon or line string. Assumes the points of the line strings are stored in Longitude(x)/Latitude(y) order.\r
33   def self.from_georuby(ls_or_p, stroke_color="#000000",stroke_weight=1,stroke_opacity=1.0,color="#ff0000",opacity=1.0)\r
34     if ls_or_p.is_a?(GeoRuby::SimpleFeatures::LineString)\r
35       GPolygon.new(ls_or_p.collect { |point| GLatLng.new([point.y,point.x])},stroke_color,stroke_weight,stroke_opacity,color,opacity)\r
36     else\r
37       GPolygon.new(ls_or_p[0].collect { |point| GLatLng.new([point.y,point.x])},stroke_color,stroke_weight,stroke_opacity,color,opacity)\r
38     end\r
39   end\r
40 end\r
41 \r

Benjamin Mako Hill || Want to submit a patch?