Class: Gooby::GoogleMapGenerator

Inherits:
GoobyObject show all
Defined in:
lib/gooby_google_map_generator.rb

Overview

Instances of this class represent a <Run> aggregate object from a

Forerunner XML file.  

Additionally, there is distance, pace, and Google Map generation logic 
in this class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GoobyKernel

#character_align, #default_delimiter, #invalid_altitude, #invalid_heartbeat, #invalid_latitude, #invalid_longitude, #invalid_time, #project_author, #project_copyright, #project_date, #project_embedded_comment, #project_license, #project_name, #project_version_number, #project_year, #read_as_ascii_lines, #read_lines, #strip_lines, #tokenize

Constructor Details

#initialize(csv_file, dttm_idx = 1, num_idx = 4, lat_idx = 5, lng_idx = 6, alt_idx = 7, cdist_idx = 8) ⇒ GoogleMapGenerator

The default csv input file format is as follows: 1 | 2006-01-15T18:31:10Z | 1279 | 33.42601 | -111.92927 | 347.654 | 26.3514930151813 1 | 2004-11-13T13:05:20Z | 2 | 37.54318 | -77.43636 | -58.022 | 0.00297286231747969



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gooby_google_map_generator.rb', line 29

def initialize(csv_file, dttm_idx=1, num_idx=4, lat_idx=5, lng_idx=6, alt_idx=7, cdist_idx=8)
  @csv_file  = csv_file
  @dttm_idx  = dttm_idx
  @num_idx   = num_idx
  @lat_idx   = lat_idx
  @lng_idx   = lng_idx
  @alt_idx   = alt_idx
  @cdist_idx = cdist_idx
        
  # Override default csv value indices if specified in the configuration yaml file.
  @configuration =  Gooby::Configuration.get_config
  @dttm_idx  = @configuration.get('csv_dttm_idx')  if @configuration.get('csv_dttm_idx')
  @num_idx   = @configuration.get('csv_num_idx')   if @configuration.get('csv_num_idx')
  @lat_idx   = @configuration.get('csv_lat_idx')   if @configuration.get('csv_lat_idx')
  @lng_idx   = @configuration.get('csv_lng_idx')   if @configuration.get('csv_lng_idx')
  @alt_idx   = @configuration.get('csv_alt_idx')   if @configuration.get('csv_alt_idx')
  @title     = @configuration.get("#{@csv_file}")  
        
  @content_hash = Hash.new('')
  @run   = Gooby::Run.new(1)
  @track = Gooby::Track.new(1)
  @run.add_track(@track)
  @tkpts = Array.new
  @icon_url_base = @configuration.get('gmap_icon_url_base')
  
  list = Array.new
  list << @csv_file
  @csv_reader = Gooby::CsvReader.new(list)
  @csv_points = @csv_reader.read
  @csv_points.each { |csv_point| 
    tkpt = csv_point.as_trackpoint
    if tkpt
      @track.add_trackpoint(tkpt)
    end
  }
  @run.finish
end

Instance Attribute Details

#alt_idxObject (readonly)

Returns the value of attribute alt_idx.



21
22
23
# File 'lib/gooby_google_map_generator.rb', line 21

def alt_idx
  @alt_idx
end

#cdist_idxObject (readonly)

Returns the value of attribute cdist_idx.



21
22
23
# File 'lib/gooby_google_map_generator.rb', line 21

def cdist_idx
  @cdist_idx
end

#center_latitudeObject (readonly)

Returns the value of attribute center_latitude.



22
23
24
# File 'lib/gooby_google_map_generator.rb', line 22

def center_latitude
  @center_latitude
end

#center_longitudeObject (readonly)

Returns the value of attribute center_longitude.



22
23
24
# File 'lib/gooby_google_map_generator.rb', line 22

def center_longitude
  @center_longitude
end

#content_hashObject (readonly)

Returns the value of attribute content_hash.



22
23
24
# File 'lib/gooby_google_map_generator.rb', line 22

def content_hash
  @content_hash
end

#csv_fileObject (readonly)

Returns the value of attribute csv_file.



21
22
23
# File 'lib/gooby_google_map_generator.rb', line 21

def csv_file
  @csv_file
end

#csv_linesObject (readonly)

Returns the value of attribute csv_lines.



21
22
23
# File 'lib/gooby_google_map_generator.rb', line 21

def csv_lines
  @csv_lines
end

#dttm_idxObject (readonly)

Returns the value of attribute dttm_idx.



21
22
23
# File 'lib/gooby_google_map_generator.rb', line 21

def dttm_idx
  @dttm_idx
end

#gpoint_arrayObject (readonly)

Returns the value of attribute gpoint_array.



22
23
24
# File 'lib/gooby_google_map_generator.rb', line 22

def gpoint_array
  @gpoint_array
end

#lat_idxObject (readonly)

Returns the value of attribute lat_idx.



21
22
23
# File 'lib/gooby_google_map_generator.rb', line 21

def lat_idx
  @lat_idx
end

#lng_idxObject (readonly)

Returns the value of attribute lng_idx.



21
22
23
# File 'lib/gooby_google_map_generator.rb', line 21

def lng_idx
  @lng_idx
end

#notesObject (readonly)

Returns the value of attribute notes.



22
23
24
# File 'lib/gooby_google_map_generator.rb', line 22

def notes
  @notes
end

#num_idxObject (readonly)

Returns the value of attribute num_idx.



21
22
23
# File 'lib/gooby_google_map_generator.rb', line 21

def num_idx
  @num_idx
end

#overlay_pointsObject (readonly)

Returns the value of attribute overlay_points.



22
23
24
# File 'lib/gooby_google_map_generator.rb', line 22

def overlay_points
  @overlay_points
end

#runObject (readonly)

Returns the value of attribute run.



22
23
24
# File 'lib/gooby_google_map_generator.rb', line 22

def run
  @run
end

#tkptsObject (readonly)

Returns the value of attribute tkpts.



22
23
24
# File 'lib/gooby_google_map_generator.rb', line 22

def tkpts
  @tkpts
end

Instance Method Details

#filter_trackpointsObject



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/gooby_google_map_generator.rb', line 92

def filter_trackpoints        
  count, @tkpts = 0, Array.new
  firstTkpt = @configuration.get('gmap_first_tkpt_number')
  lastTkpt  = @configuration.get('gmap_last_tkpt_number')
  @run.tracks.each { |trk| 
    trk.trackpoints.each { |tkpt|
      count = count + 1
      if ((count >= firstTkpt) && (count <= lastTkpt))
        @tkpts.push(tkpt)
      end
    }
  }   
end

#generate(configuration) ⇒ Object

Returns a Hash with specific generated content at the following keys:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gooby_google_map_generator.rb', line 70

def generate(configuration)
  if (configuration == nil)
    @configuration = Gooby::Configuration.get_config
  else
    @configuration = configuration
  end  
  @content_hash['when_generated'] = Time.now
  @content_hash['title'] = @title
  @icon_url_base = @configuration.get('gmap_icon_url_base')               
  filter_trackpoints  
  compute_center_point
  generate_key_js
  generate_map_div
  generate_messages_div
  generate_main_js_start
  generate_main_js_route_overlay
  generate_main_js_checkpoint_overlays
  generate_main_js_map_clicked_listeners      
  generate_main_js_end    
  @content_hash
end

#generate_page(configuration) ⇒ Object

Returns a Hash with specific generated content at the following keys:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/gooby_google_map_generator.rb', line 109

def generate_page(configuration)

  # puts "generate_page #{@csv_file} #{@csv_lines.size}"
  content_hash = generate(nil)
  s = String.new(@csv_file)
  s.gsub("/", " ")
  tokens = tokenize(s, nil)
  out_file = "#{tokens[-2]}.html"
  #content_hash.keys.sort.each { | key | puts key }

s = <<HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="description" content="Google Map generated with #{project_embedded_comment}">
<meta name="keywords" content="Google Map #{project_embedded_comment} GPS">
<title> Google Map by Gooby </title>
#{content_hash['key_js']}
#{content_hash['main_js_start']}
#{content_hash['main_js_route_overlay']}  
#{content_hash['main_js_checkpoint_overlays']}  
#{content_hash['main_js_map_clicked_listeners']}  
#{content_hash['main_js_end']}
  </head>
  <body onload="load()" onunload="GUnload()">
<center>
<h3> #{@title} </h3>
<h5> Generated by Gooby #{content_hash['when_generated']} <br> Gooby = Google APIs + Ruby </h5>    
#{content_hash['map_div']}    
#{content_hash['messages_div']}   
</center>
  </body>
</html>
HERE
  puts s   # Redirect output via shell.
end