/[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 23 by dpavlin, Thu Dec 6 14:03:00 2007 UTC revision 24 by dpavlin, Fri Dec 7 00:59:05 2007 UTC
# Line 50  my $html = join('', qq{ Line 50  my $html = join('', qq{
50                  -name => 'line',                  -name => 'line',
51                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
52          ),          ),
53          ' with every ',          ' with ',
54            $q->popup_menu(
55                    -name => 'placemark_filter',
56                    -values => [ 'every', 'total of' ],
57            ),
58          $q->textfield(          $q->textfield(
59                  -name => 'nth_placemark',                  -name => 'placemark',
60                  -value => 5,                  -value => 5,
61                  -size => 2,                  -size => 2,
62                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
63          ),          ),
64          '<sup>th</sup> placemark',          ' placemarks',
65          $q->end_form,          $q->end_form,
66  );  );
67    
68    
 my @points;  
 my $center_point;  
69    
70  if ( my $trace = $q->param('trace') ) {  if ( my $trace = $q->param('trace') ) {
71          $trace =~ s/\s.+$//;          $trace =~ s/\s.+$//;
72    
         my $map = HTML::GoogleMaps->new(key => $map_key);  
         #$map->center(point => "Zagreb, Hrvatska");  
   
73          $trace = "$trace_path/$trace";          $trace = "$trace_path/$trace";
74    
75          my $points = 0;          my $points = 0;
76          my $nth_placemark = $q->param('nth_placemark');          my $center_point;
77            my @points;
78            my @placemarks;
79    
80          open(my $fh, '<', $trace) || die "can't open $trace: $!";          open(my $fh, '<', $trace) || die "can't open $trace: $!";
81          while( <$fh> ) {          while( <$fh> ) {
# Line 84  if ( my $trace = $q->param('trace') ) { Line 85  if ( my $trace = $q->param('trace') ) {
85                  my $point = [ $hash->{lon}, $hash->{lat} ];                  my $point = [ $hash->{lon}, $hash->{lat} ];
86                  $center_point ||= $point;                  $center_point ||= $point;
87    
88                    push @points, $point;
89    
90                  if ( $q->param('line') ) {                  push @placemarks, {
91                          push @points, $point;                          point => $point,
92                  }                          html => join('<br/>',
93                                    map {
94                  if ( ! $q->param('line') ||                                          ucfirst($_) . ': ' . $hash->{$_}
95                          $nth_placemark && $points % $nth_placemark == 0                                  } ( qw/time lat lon speed course/ )
96                  ) {                          ),
97                    };
                         $map->add_marker(  
                                 point => $point,  
                                 html => join('<br/>',  
                                         map {  
                                                 ucfirst($_) . ': ' . $hash->{$_}  
                                         } ( qw/time lat lon speed course/ )  
                                 ),  
                         );  
   
                 }  
98    
99                  $points++;                  $points++;
100    
# Line 111  if ( my $trace = $q->param('trace') ) { Line 103  if ( my $trace = $q->param('trace') ) {
103    
104          if ( $points > 0 ) {          if ( $points > 0 ) {
105    
106                    my $map = HTML::GoogleMaps->new(
107                            key => $map_key,
108                            width => '800px',
109                            height => '600px',
110                    );
111                    #$map->center(point => "Zagreb, Hrvatska");
112    
113                  #$map->zoom(10);                  #$map->zoom(10);
114                  #$map->v2_zoom(0);                  $map->v2_zoom(20);
115                  $map->controls("large_map_control", "map_type_control");                  $map->controls("large_map_control", "map_type_control");
116                  $map->map_type('hybrid');                  $map->map_type('hybrid');
117                  $map->center( $center_point ) if $q->param('line') && $center_point;                  $map->center( $center_point ) if $q->param('line') && $center_point;
# Line 122  if ( my $trace = $q->param('trace') ) { Line 121  if ( my $trace = $q->param('trace') ) {
121                          $map->add_polyline( points => [ @points ] );                          $map->add_polyline( points => [ @points ] );
122                  }                  }
123    
124                    my $placemarks = 0;
125    
126                    if ( my $placemark = $q->param('placemark') ) {
127                            if ( $q->param('placemark_filter') eq 'every' ) {
128                                    foreach my $o ( 0 .. $#placemarks ) {
129                                            next unless $o % $placemark == 0;
130                                            $map->add_marker( %{ $placemarks[$o] } );
131                                            $placemarks++;
132                                    }
133                            } else {
134                                    # total of
135                                    my $d = $points / ( $placemark - 1 );
136                                    foreach my $p ( 0 .. $placemark - 2 ) {
137                                            my $o = int($p * $d);
138                                            die "no placemark $p at $o from total of $#placemarks" unless $placemarks[$o];
139                                            $map->add_marker( %{ $placemarks[$o] } );
140                                            $placemarks++;
141                                    }
142                                    # add last one
143                                    $map->add_marker( %{ $placemarks[$#placemarks] } );
144                                    $placemarks++;
145                            }
146                    } else {
147                            # show every placemark
148                            foreach my $marker ( @placemarks ) {
149                                    $map->add_marker( %$marker );
150                                    $placemarks++;
151                            }
152                    }
153    
154                  my ( $map_div, $map_script );                  my ( $map_div, $map_script );
155                  ( $head, $map_div, $map_script ) = $map->render;                  ( $head, $map_div, $map_script ) = $map->render;
156    
157                  $html .= join('', qq{                  $html .= join('', qq{
158  <h1>Plotting $points points from }, $q->param('trace'), qq{</h1>  $points points from <tt>}, $q->param('trace'), qq{</tt> showing },
159            $#points > 0 ? $#points + 1 . ' points' . ( $placemarks ? ' and ' : '' ) : '',
160            $placemarks ? $placemarks . ' placemarks' : '',
161            qq{
162  $map_div  $map_div
163  $map_script  $map_script
164  <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>  <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>

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

  ViewVC Help
Powered by ViewVC 1.1.26