/[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 27 by dpavlin, Fri Dec 7 03:44:12 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    
16  my $trace_path = '/home/dpavlin/x/openmoko/gps/';  my $trace_path = '../nmea/';
17    
18  # http://localhost/  # http://localhost/
19  my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg';  my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg';
# Line 38  my $html = join('', qq{ Line 39  my $html = join('', qq{
39                                  "$_ (" . (stat("$trace_path/$_"))[7] . " bytes)"                                  "$_ (" . (stat("$trace_path/$_"))[7] . " bytes)"
40                          }                          }
41                          sort {                          sort {
42                                  (stat("$trace_path/$a"))[10] <=> (stat("$trace_path/$b"))[10]                                  (stat("$trace_path/$a"))[9] <=> (stat("$trace_path/$b"))[9]
43                          } @traces                          } @traces
44                  ],                  ],
45                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
46          ),          ),
47          $q->submit( -value => 'Show trace' ),          $q->submit( -value => 'Show trace' ),
48          $q->br,          $q->br,
49          'Draw as ',          'Draw ',
50          $q->checkbox(          $q->popup_menu(
51                  -name => 'line',                  -name => 'points_filter',
52                    -values => [ 'all', 'every', 'total of' ],
53            ),
54            $q->textfield(
55                    -name => 'points_count',
56                    -value => '',
57                    -size => 2,
58                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
59          ),          ),
60          ' with ',          ' points and ',
61          $q->popup_menu(          $q->popup_menu(
62                  -name => 'placemark_filter',                  -name => 'placemark_filter',
63                  -values => [ 'every', 'total of' ],                  -values => [ 'total of', 'every' ],
64          ),          ),
65          $q->textfield(          $q->textfield(
66                  -name => 'placemark',                  -name => 'placemark_count',
67                  -value => 5,                  -value => 5,
68                  -size => 2,                  -size => 2,
69                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
# Line 72  if ( my $trace = $q->param('trace') ) { Line 79  if ( my $trace = $q->param('trace') ) {
79    
80          $trace = "$trace_path/$trace";          $trace = "$trace_path/$trace";
81    
         my $points = 0;  
82          my $center_point;          my $center_point;
83          my @points;          my @points;
84          my @placemarks;          my @placemarks;
# Line 92  if ( my $trace = $q->param('trace') ) { Line 98  if ( my $trace = $q->param('trace') ) {
98                          html => join('<br/>',                          html => join('<br/>',
99                                  map {                                  map {
100                                          ucfirst($_) . ': ' . $hash->{$_}                                          ucfirst($_) . ': ' . $hash->{$_}
101                                  } ( qw/time lat lon speed course/ )                                  } ( qw/number time lat lon speed course/ )
102                          ),                          ),
103                  };                  };
104    
                 $points++;  
   
105          }          }
106          close($fh);          close($fh);
107    
108          if ( $points > 0 ) {          if ( $#points >= 0 ) {
109    
110                  my $map = HTML::GoogleMaps->new(                  my $map = HTML::GoogleMaps->new(
111                          key => $map_key,                          key => $map_key,
# Line 116  if ( my $trace = $q->param('trace') ) { Line 120  if ( my $trace = $q->param('trace') ) {
120                  $map->map_type('hybrid');                  $map->map_type('hybrid');
121                  $map->center( $center_point ) if $q->param('line') && $center_point;                  $map->center( $center_point ) if $q->param('line') && $center_point;
122    
123                  if ( $q->param('line') ) {                  sub filter_array {
124                          warn "## points = ",dump( @points );                          my $o = {@_};
125                          $map->add_polyline( points => [ @points ] );                          my (     $count,      $filter,      $code  ) =
126                  }                             ( $o->{count}, $o->{filter}, $o->{code} ) ;
127                            confess "no CODE?" unless ref($code) eq 'CODE';
128                  my $placemarks = 0;                          my @array = @{ $o->{array} };
129    
130                  if ( my $placemark = $q->param('placemark') ) {                          warn "count: $count filter: $filter\n";
131                          if ( $q->param('placemark_filter') eq 'every' ) {  
132                                  foreach my $o ( 0 .. $#placemarks ) {                          my $code_calls = 0;
133                                          next unless $o % $placemark == 0;  
134                                          $map->add_marker( %{ $placemarks[$o] } );                          if ( $count && $filter =~ m/every/ ) {
135                                          $placemarks++;                                  foreach my $o ( 0 .. $#array ) {
136                                            next unless $o % $count == 0;
137                                            $code->( $array[$o] );
138                                            $code_calls++;
139                                  }                                  }
140                          } else {                          } elsif ( $count && $filter =~ m/total/ ) {
141                                  # total of                                  # total of
142                                  my $d = $points / ( $placemark - 1 );                                  if ( $count < 2 ) {
143                                  foreach my $p ( 0 .. $placemark - 2 ) {                                          # first
144                                            if ( $array[0]) {
145                                                    $code->( $array[0] );
146                                                    $code_calls++;
147                                            };
148                                            # last
149                                            if ( $count > 1 && $#array > 0 ) {
150                                                    $code->( $array[$#array] );
151                                                    $code_calls++;
152                                            };
153                                            return $code_calls;
154                                    }
155    
156                                    my $d = $#array / ( $count - 1 );
157                                    foreach my $p ( 0 .. $count - 1 ) {
158                                          my $o = int($p * $d);                                          my $o = int($p * $d);
159                                          die "no placemark $p at $o from total of $#placemarks" unless $placemarks[$o];                                          die "no element $p at $o from total of ",$#array + 1 unless $array[$o];
160                                          $map->add_marker( %{ $placemarks[$o] } );                                          $code->( $array[$o] );
161                                          $placemarks++;                                          $code_calls++;
162                                    }
163                            } else {
164                                    # show every
165                                    foreach my $e ( @array ) {
166                                            $code->( $e );
167                                            $code_calls++;
168                                  }                                  }
                                 # add last one  
                                 $map->add_marker( %{ $placemarks[$#placemarks] } );  
                                 $placemarks++;  
                         }  
                 } else {  
                         # show every placemark  
                         foreach my $marker ( @placemarks ) {  
                                 $map->add_marker( %$marker );  
                                 $placemarks++;  
169                          }                          }
170                            return $code_calls;
171                  }                  }
172    
173                    my @poly_points;
174                    my $points = filter_array(
175                            count => $q->param('points_count'),
176                            filter => $q->param('points_filter'),
177                            code => sub {
178                                    my $point = shift;
179                                    push @poly_points, $point;
180                            },
181                            array => \@points,
182                    );
183    
184                    die "hum?" unless $#poly_points == $points - 1;
185    
186                    $map->add_polyline( points => [ @poly_points ] ) if @poly_points;
187    
188                    my $placemarks = filter_array(
189                            count => $q->param('placemark_count'),
190                            filter => $q->param('placemark_filter'),
191                            code => sub {
192                                    my $placemark = shift;
193                                    $map->add_marker( %$placemark, noformat => 1 );
194                            },
195                            array => \@placemarks,
196                    );
197    
198                  my ( $map_div, $map_script );                  my ( $map_div, $map_script );
199                  ( $head, $map_div, $map_script ) = $map->render;                  ( $head, $map_div, $map_script ) = $map->render;
200    
201                  $html .= join('', qq{                  $html .= join('',
202  $points points from <tt>}, $q->param('trace'), qq{</tt> showing },  $#points + 1, ' points from <tt>', $q->param('trace'), '</tt> showing ',
203          $#points > 0 ? $#points + 1 . ' points' . ( $placemarks ? ' and ' : '' ) : '',          $points ? $points . ' points' . ( $placemarks ? ' and ' : '' ) : '',
204          $placemarks ? $placemarks . ' placemarks' : '',          $placemarks ? $placemarks . ' placemarks' : '',
205          qq{          qq{
206  $map_div  $map_div

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

  ViewVC Help
Powered by ViewVC 1.1.26