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 ptsper = _num_points / nframes;
58 proj = OSM::Mercator.new(min_lat, min_lon, max_lat, max_lon, width, height)
60 frames = Array.new(nframes, GD2::Image::IndexedColor.new(width, height))
62 (0..nframes - 1).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 >= (ptsper * n)) && (pt <= (ptsper * (n+1))))
95 pen.line(px, py, oldpx, oldpy) unless first
103 res = GD2::AnimatedGif::gif_anim_begin(frames[0])
104 res << GD2::AnimatedGif::gif_anim_add(frames[0], nil, delay)
105 (1..nframes - 1).each do |n|
106 res << GD2::AnimatedGif::gif_anim_add(frames[n], frames[n-1], delay)
108 res << GD2::AnimatedGif::gif_anim_end()
113 def icon(min_lat, min_lon, max_lat, max_lon)
116 proj = OSM::Mercator.new(min_lat, min_lon, max_lat, max_lon, width, height)
118 image = GD2::Image::IndexedColor.new(width, height)
120 black = image.palette.allocate(GD2::Color[0, 0, 0])
121 white = image.palette.allocate(GD2::Color[255, 255, 255])
125 pen.rectangle(0, 0, width, height, true)
130 pen.anti_aliasing = true
131 pen.dont_blend = false
139 px = proj.x(p.longitude)
140 py = proj.y(p.latitude)
142 pen.line(px, py, oldpx, oldpy) unless first
154 TrkPt = Struct.new(:segment, :latitude, :longitude, :altitude, :timestamp) do
156 latitude && longitude && timestamp &&
157 latitude >= -90 && latitude <= 90 &&
158 longitude >= -180 && longitude <= 180