Class: Gooby::GoogleMapGenerator

Inherits:
GoobyObject show all
Defined in:
lib/gooby/cls_google_map_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GoobyProjectInfo

#google_maps_api_level, #project_author, #project_copyright, #project_date, #project_license, #project_version_number, #project_year, #some_new_thing, #tested_files

Methods included from Introspect

#introspect, #to_yaml_properties

Methods included from GoobyString

#tokenize

Methods included from GoobyIO

#read_as_ascii_lines, #read_lines, #strip_lines

Constructor Details

#initialize(csv_file, dttm_idx = 1, num_idx = 2, lat_idx = 3, lng_idx = 4, alt_idx = 5, cdist_idx = 6) ⇒ 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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gooby/cls_google_map_generator.rb', line 26

def initialize(csv_file, dttm_idx=1, num_idx=2, lat_idx=3, lng_idx=4, alt_idx=5, cdist_idx=6)
  @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
  @options   =  Gooby::Options.new(nil)
  @content_hash = Hash.new('')
  @run   = Gooby::Run.new(1)
  @track = Gooby::Track.new(1)
  @run.add_track(@track)
  @tkpts = Array.new
  
  @csv_lines = read_as_ascii_lines(@csv_file, 10, true) 
  @csv_lines.each { | line |
    dline = Gooby::DelimLine.new(line)
    if (!dline.is_comment?)
      tkpt = dline.as_trackpoint(@num_idx, @lat_idx, @lng_idx, @alt_idx, @dttm_idx)
      if tkpt
        @track.add_trackpoint(tkpt)
      end
    end
  }
  @run.finish
end

Instance Attribute Details

#alt_idxObject (readonly)

Returns the value of attribute alt_idx.



18
19
20
# File 'lib/gooby/cls_google_map_generator.rb', line 18

def alt_idx
  @alt_idx
end

#cdist_idxObject (readonly)

Returns the value of attribute cdist_idx.



18
19
20
# File 'lib/gooby/cls_google_map_generator.rb', line 18

def cdist_idx
  @cdist_idx
end

#center_latitudeObject (readonly)

Returns the value of attribute center_latitude.



19
20
21
# File 'lib/gooby/cls_google_map_generator.rb', line 19

def center_latitude
  @center_latitude
end

#center_longitudeObject (readonly)

Returns the value of attribute center_longitude.



19
20
21
# File 'lib/gooby/cls_google_map_generator.rb', line 19

def center_longitude
  @center_longitude
end

#content_hashObject (readonly)

Returns the value of attribute content_hash.



19
20
21
# File 'lib/gooby/cls_google_map_generator.rb', line 19

def content_hash
  @content_hash
end

#csv_fileObject (readonly)

Returns the value of attribute csv_file.



18
19
20
# File 'lib/gooby/cls_google_map_generator.rb', line 18

def csv_file
  @csv_file
end

#csv_linesObject (readonly)

Returns the value of attribute csv_lines.



18
19
20
# File 'lib/gooby/cls_google_map_generator.rb', line 18

def csv_lines
  @csv_lines
end

#dttm_idxObject (readonly)

Returns the value of attribute dttm_idx.



18
19
20
# File 'lib/gooby/cls_google_map_generator.rb', line 18

def dttm_idx
  @dttm_idx
end

#gpoint_arrayObject (readonly)

Returns the value of attribute gpoint_array.



19
20
21
# File 'lib/gooby/cls_google_map_generator.rb', line 19

def gpoint_array
  @gpoint_array
end

#lat_idxObject (readonly)

Returns the value of attribute lat_idx.



18
19
20
# File 'lib/gooby/cls_google_map_generator.rb', line 18

def lat_idx
  @lat_idx
end

#lng_idxObject (readonly)

Returns the value of attribute lng_idx.



18
19
20
# File 'lib/gooby/cls_google_map_generator.rb', line 18

def lng_idx
  @lng_idx
end

#notesObject (readonly)

Returns the value of attribute notes.



19
20
21
# File 'lib/gooby/cls_google_map_generator.rb', line 19

def notes
  @notes
end

#num_idxObject (readonly)

Returns the value of attribute num_idx.



18
19
20
# File 'lib/gooby/cls_google_map_generator.rb', line 18

def num_idx
  @num_idx
end

#overlay_pointsObject (readonly)

Returns the value of attribute overlay_points.



19
20
21
# File 'lib/gooby/cls_google_map_generator.rb', line 19

def overlay_points
  @overlay_points
end

#runObject (readonly)

Returns the value of attribute run.



19
20
21
# File 'lib/gooby/cls_google_map_generator.rb', line 19

def run
  @run
end

#tkptsObject (readonly)

Returns the value of attribute tkpts.



19
20
21
# File 'lib/gooby/cls_google_map_generator.rb', line 19

def tkpts
  @tkpts
end

Instance Method Details

#filter_trackpointsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gooby/cls_google_map_generator.rb', line 78

def filter_trackpoints        
  count, @tkpts = 0, Array.new
  firstTkpt = @options.get('gmap_first_tkpt_number')
  lastTkpt  = @options.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(options) ⇒ Object

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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gooby/cls_google_map_generator.rb', line 57

def generate(options)
  if (options == nil)
    @options =  Gooby::Options.new(nil)
  else
    @options = options
  end  
  @content_hash['when_generated'] = Time.now
  @content_hash['title'] = @options.get('gmap_title')               
  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(options) ⇒ Object

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



95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
# File 'lib/gooby/cls_google_map_generator.rb', line 95

def generate_page(options)

  # 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 = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n  <head>\n<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n<title> Google Map by Gooby </title>\n\#{content_hash['key_js']}\n\#{content_hash['main_js_start']}\n\#{content_hash['main_js_route_overlay']}  \n\#{content_hash['main_js_checkpoint_overlays']}  \n\#{content_hash['main_js_map_clicked_listeners']}  \n\#{content_hash['main_js_end']}\n  </head>\n  <body onload=\"load()\" onunload=\"GUnload()\">\n<center>\n<h3> \#{content_hash['title']} </h3>\n<h5> Generated by Gooby \#{content_hash['when_generated']} <br> Gooby = Google APIs + Ruby </h5>    \n\#{content_hash['map_div']}    \n\#{content_hash['messages_div']}   \n</center>\n  </body>\n</html>\n"

  # html_file = File.new(out_file, "w+")
  # html_file.write(s)
  # html_file.flush
  # html_file.close  
  puts s   # Output is redirected by shell.    
end