7 attr_reader :possible_points
8 attr_reader :actual_points
16 return enum_for(:points) unless block_given?
24 reader = XML::Reader.io(@file)
29 if reader.node_type == XML::Reader::TYPE_ELEMENT
30 if reader.name == "trkpt"
31 point = TrkPt.new(@tracksegs, reader["lat"].to_f, reader["lon"].to_f)
33 elsif reader.name == "ele" && point
34 point.altitude = reader.read_string.to_f
35 elsif reader.name == "time" && point
36 point.timestamp = Time.parse(reader.read_string)
38 elsif reader.node_type == XML::Reader::TYPE_END_ELEMENT
39 if reader.name == "trkpt" && point && point.valid?
43 elsif reader.name == "trkseg"
50 def picture(min_lat, min_lon, max_lat, max_lon, num_points)
56 points_per_frame = num_points / nframes
58 proj = OSM::Mercator.new(min_lat, min_lon, max_lat, max_lon, width, height)
62 (0...nframes).each do |n|
63 frames[n] = GD2::Image::IndexedColor.new(width, height)
64 black = frames[n].palette.allocate(GD2::Color[0, 0, 0])
65 white = frames[n].palette.allocate(GD2::Color[255, 255, 255])
66 grey = frames[n].palette.allocate(GD2::Color[187, 187, 187])
68 frames[n].draw do |pen|
70 pen.rectangle(0, 0, width, height, true)
73 frames[n].draw do |pen|
75 pen.anti_aliasing = true
76 pen.dont_blend = false
83 points.each_with_index do |p, pt|
84 px = proj.x(p.longitude)
85 py = proj.y(p.latitude)
87 if (pt >= (points_per_frame * n)) && (pt <= (points_per_frame * (n + 1)))
95 pen.line(px, py, oldpx, oldpy) unless first
103 image = GD2::AnimatedGif.new
104 frames.each do |frame|
105 image.add(frame, :delay => delay)
109 output = StringIO.new
114 def icon(min_lat, min_lon, max_lat, max_lon)
117 proj = OSM::Mercator.new(min_lat, min_lon, max_lat, max_lon, width, height)
119 image = GD2::Image::IndexedColor.new(width, height)
121 black = image.palette.allocate(GD2::Color[0, 0, 0])
122 white = image.palette.allocate(GD2::Color[255, 255, 255])
126 pen.rectangle(0, 0, width, height, true)
131 pen.anti_aliasing = true
132 pen.dont_blend = false
140 px = proj.x(p.longitude)
141 py = proj.y(p.latitude)
143 pen.line(px, py, oldpx, oldpy) unless first
155 TrkPt = Struct.new(:segment, :latitude, :longitude, :altitude, :timestamp) do
157 latitude && longitude && timestamp &&
158 latitude >= -90 && latitude <= 90 &&
159 longitude >= -180 && longitude <= 180