/[maps]/web/googlemap.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /web/googlemap.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by dpavlin, Fri Dec 7 00:59:05 2007 UTC revision 31 by dpavlin, Sat Dec 8 20:37:50 2007 UTC
# Line 9  use CGI::Carp qw/fatalsToBrowser/; Line 9  use CGI::Carp qw/fatalsToBrowser/;
9  use File::Find;  use File::Find;
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
11    
12  use lib '../';  use lib '../lib';
13    use blib;
14  use NMEA;  use NMEA;
15    use KML;
16    
17  my $trace_path = '/home/dpavlin/x/openmoko/gps/';  my $trace_path = '../nmea/';
18    
19  # http://localhost/  # http://localhost/
20  my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg';  my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg';
# Line 24  find({ wanted => sub { Line 26  find({ wanted => sub {
26    
27  my $q = CGI->new;  my $q = CGI->new;
28    
 print $q->header;  
   
29  my $head = '';  my $head = '';
30  my $html = join('', qq{  my $html = join('', qq{
31  <h1>Select GPS NMEA dump</h1>  <h1>Select GPS NMEA dump</h1>
# Line 38  my $html = join('', qq{ Line 38  my $html = join('', qq{
38                                  "$_ (" . (stat("$trace_path/$_"))[7] . " bytes)"                                  "$_ (" . (stat("$trace_path/$_"))[7] . " bytes)"
39                          }                          }
40                          sort {                          sort {
41                                  (stat("$trace_path/$a"))[10] <=> (stat("$trace_path/$b"))[10]                                  (stat("$trace_path/$a"))[9] <=> (stat("$trace_path/$b"))[9]
42                          } @traces                          } @traces
43                  ],                  ],
44                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
45          ),          ),
46          $q->submit( -value => 'Show trace' ),          $q->submit(
47                    -name => 'show',
48                    -value => 'Show trace'
49            ),
50          $q->br,          $q->br,
51          'Draw as ',          'Draw ',
52          $q->checkbox(          $q->popup_menu(
53                  -name => 'line',                  -name => 'points_filter',
54                    -values => [ 'all', 'every', 'total of' ],
55            ),
56            $q->textfield(
57                    -name => 'points_count',
58                    -value => '',
59                    -size => 2,
60                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
61          ),          ),
62          ' with ',          ' points and ',
63          $q->popup_menu(          $q->popup_menu(
64                  -name => 'placemark_filter',                  -name => 'placemark_filter',
65                  -values => [ 'every', 'total of' ],                  -values => [ 'total of', 'every' ],
66          ),          ),
67          $q->textfield(          $q->textfield(
68                  -name => 'placemark',                  -name => 'placemark_count',
69                  -value => 5,                  -value => 5,
70                  -size => 2,                  -size => 2,
71                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
72          ),          ),
73          ' placemarks',          ' placemarks',
74          $q->end_form,          $q->br,
75  );  );
76    
77    
# Line 72  if ( my $trace = $q->param('trace') ) { Line 81  if ( my $trace = $q->param('trace') ) {
81    
82          $trace = "$trace_path/$trace";          $trace = "$trace_path/$trace";
83    
         my $points = 0;  
84          my $center_point;          my $center_point;
85          my @points;          my @points;
86          my @placemarks;          my @placemarks;
# Line 92  if ( my $trace = $q->param('trace') ) { Line 100  if ( my $trace = $q->param('trace') ) {
100                          html => join('<br/>',                          html => join('<br/>',
101                                  map {                                  map {
102                                          ucfirst($_) . ': ' . $hash->{$_}                                          ucfirst($_) . ': ' . $hash->{$_}
103                                  } ( qw/time lat lon speed course/ )                                  } ( qw/number time lat lon speed course/ )
104                          ),                          ),
105                            %$hash,
106                  };                  };
107    
                 $points++;  
   
108          }          }
109          close($fh);          close($fh);
110    
111          if ( $points > 0 ) {          if ( $#points >= 0 ) {
112    
113                    sub filter_array {
114                            my $o = {@_};
115                            my (     $count,      $filter,      $code  ) =
116                               ( $o->{count}, $o->{filter}, $o->{code} ) ;
117                            confess "no CODE?" unless ref($code) eq 'CODE';
118                            my @array = @{ $o->{array} };
119    
120                            warn "count: $count filter: $filter\n";
121    
122                            my $code_calls = 0;
123    
124                            if ( $count && $filter =~ m/every/ ) {
125                                    foreach my $o ( 0 .. $#array ) {
126                                            next unless $o % $count == 0;
127                                            $code->( $array[$o] );
128                                            $code_calls++;
129                                    }
130                            } elsif ( $count && $filter =~ m/total/ ) {
131                                    # total of
132                                    if ( $count < 2 ) {
133                                            # first
134                                            if ( $array[0]) {
135                                                    $code->( $array[0] );
136                                                    $code_calls++;
137                                            };
138                                            # last
139                                            if ( $count > 1 && $#array > 0 ) {
140                                                    $code->( $array[$#array] );
141                                                    $code_calls++;
142                                            };
143                                            return $code_calls;
144                                    }
145    
146                                    my $d = $#array / ( $count - 1 );
147                                    foreach my $p ( 0 .. $count - 1 ) {
148                                            my $o = int($p * $d);
149                                            die "no element $p at $o from total of ",$#array + 1 unless $array[$o];
150                                            $code->( $array[$o] );
151                                            $code_calls++;
152                                    }
153                            } else {
154                                    # show every
155                                    foreach my $e ( @array ) {
156                                            $code->( $e );
157                                            $code_calls++;
158                                    }
159                            }
160                            return $code_calls;
161                    }
162    
163                  my $map = HTML::GoogleMaps->new(                  my $map = HTML::GoogleMaps->new(
164                          key => $map_key,                          key => $map_key,
165                          width => '800px',                          width => '800px',
166                          height => '600px',                          height => '600px',
167                  );                  );
                 #$map->center(point => "Zagreb, Hrvatska");  
168    
169                  #$map->zoom(10);                  my @poly_points;
170                  $map->v2_zoom(20);                  my $points = filter_array(
171                  $map->controls("large_map_control", "map_type_control");                          count => $q->param('points_count'),
172                  $map->map_type('hybrid');                          filter => $q->param('points_filter'),
173                  $map->center( $center_point ) if $q->param('line') && $center_point;                          code => sub {
174                                    my $point = shift;
175                                    push @poly_points, $point;
176                            },
177                            array => \@points,
178                    );
179    
180                  if ( $q->param('line') ) {                  die "hum?" unless $#poly_points == $points - 1;
                         warn "## points = ",dump( @points );  
                         $map->add_polyline( points => [ @points ] );  
                 }  
181    
182                  my $placemarks = 0;                  my @filtered_placemarks;
183    
184                  if ( my $placemark = $q->param('placemark') ) {                  my $placemarks = filter_array(
185                          if ( $q->param('placemark_filter') eq 'every' ) {                          count => $q->param('placemark_count'),
186                                  foreach my $o ( 0 .. $#placemarks ) {                          filter => $q->param('placemark_filter'),
187                                          next unless $o % $placemark == 0;                          code => sub {
188                                          $map->add_marker( %{ $placemarks[$o] } );                                  my $placemark = shift;
189                                          $placemarks++;                                  $map->add_marker( %$placemark, noformat => 1 );
190                                  }                                  push @filtered_placemarks, $placemark;
191                            },
192                            array => \@placemarks,
193                    );
194    
195                    if ( my $export = $q->param('export') ) {
196                            if ( $export =~ m/KML/i ) {
197                                    print $q->header(
198                                            -type => 'application/vnd.google-earth.kml+xml',
199                                    ),
200                                    KML->output( placemarks => \@filtered_placemarks );
201                                    exit;
202                          } else {                          } else {
203                                  # total of                                  die "unknown export format $export";
                                 my $d = $points / ( $placemark - 1 );  
                                 foreach my $p ( 0 .. $placemark - 2 ) {  
                                         my $o = int($p * $d);  
                                         die "no placemark $p at $o from total of $#placemarks" unless $placemarks[$o];  
                                         $map->add_marker( %{ $placemarks[$o] } );  
                                         $placemarks++;  
                                 }  
                                 # add last one  
                                 $map->add_marker( %{ $placemarks[$#placemarks] } );  
                                 $placemarks++;  
                         }  
                 } else {  
                         # show every placemark  
                         foreach my $marker ( @placemarks ) {  
                                 $map->add_marker( %$marker );  
                                 $placemarks++;  
204                          }                          }
205                  }                  }
206    
207    
208                    #$map->center(point => "Zagreb, Hrvatska");
209    
210                    #$map->zoom(10);
211                    $map->v2_zoom(20);
212                    $map->controls("large_map_control", "map_type_control");
213                    $map->map_type('hybrid');
214                    $map->center( $center_point ) if $q->param('line') && $center_point;
215    
216                    $map->add_polyline( points => [ @poly_points ] ) if @poly_points;
217            
218                  my ( $map_div, $map_script );                  my ( $map_div, $map_script );
219                  ( $head, $map_div, $map_script ) = $map->render;                  ( $head, $map_div, $map_script ) = $map->render;
220    
221                  $html .= join('', qq{                  $html .= join('',
222  $points points from <tt>}, $q->param('trace'), qq{</tt> showing },  $#points + 1, ' points from <tt>', $q->param('trace'), '</tt> showing ',
223          $#points > 0 ? $#points + 1 . ' points' . ( $placemarks ? ' and ' : '' ) : '',          $points ? $points . ' points' . ( $placemarks ? ' and ' : '' ) : '',
224          $placemarks ? $placemarks . ' placemarks' : '',          $placemarks ? $placemarks . ' placemarks' : '',
225            ' export to ',
226            $q->submit(
227                    -name => 'export',
228                    -value => 'KML'
229            ),
230          qq{          qq{
231  $map_div  $map_div
232  $map_script  $map_script
233  <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>  <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>
234                  });                  });
235    
236                    my $stats = NMEA->stats;
237                    $html .= '<table>';
238                    foreach my $n ( keys %$stats ) {
239                            $html .= "<tr><td>$n</td><td>" . $stats->{$n} . "</td></tr>";
240                    }
241                    $html .= '</table>';
242                    
243          } else {          } else {
244                  $html .= '<em>No points found for ' . $q->param('trace') . '</em>';                  $html .= '<em>No points found for ' . $q->param('trace') . '</em>';
245          }          }
246    
247            $html .= $q->end_form;
248  }  }
249    
250    print $q->header;
251  print qq{  print qq{
252  <html>  <html>
253  <head>  <head>

Legend:
Removed from v.24  
changed lines
  Added in v.31

  ViewVC Help
Powered by ViewVC 1.1.26