/[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

Annotation of /web/googlemap.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (hide annotations)
Fri Dec 7 00:59:05 2007 UTC (11 years, 5 months ago) by dpavlin
File size: 3750 byte(s)
- filter every nth placemark of select total number of placemarks to plot
- bigger map (800*600px)
- report number of points and placemarks
1 dpavlin 13 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     use HTML::GoogleMaps;
7 dpavlin 14 use CGI;
8 dpavlin 13 use CGI::Carp qw/fatalsToBrowser/;
9 dpavlin 14 use File::Find;
10 dpavlin 13 use Data::Dump qw/dump/;
11    
12 dpavlin 14 use lib '../';
13     use NMEA;
14    
15     my $trace_path = '/home/dpavlin/x/openmoko/gps/';
16    
17 dpavlin 13 # http://localhost/
18     my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg';
19    
20 dpavlin 14 my @traces;
21     find({ wanted => sub {
22     push @traces, $_ if -f $_;
23     }}, $trace_path);
24 dpavlin 13
25 dpavlin 14 my $q = CGI->new;
26 dpavlin 13
27 dpavlin 14 print $q->header;
28 dpavlin 13
29 dpavlin 15 my $head = '';
30     my $html = join('', qq{
31 dpavlin 14 <h1>Select GPS NMEA dump</h1>
32     },
33 dpavlin 19 $q->start_form( -id => 'trace_frm' ),
34 dpavlin 14 $q->popup_menu(
35     -name => 'trace',
36     -values => [
37     map {
38     "$_ (" . (stat("$trace_path/$_"))[7] . " bytes)"
39     }
40     sort {
41     (stat("$trace_path/$a"))[10] <=> (stat("$trace_path/$b"))[10]
42     } @traces
43     ],
44 dpavlin 19 -onChange => 'trace_frm.submit()',
45 dpavlin 14 ),
46     $q->submit( -value => 'Show trace' ),
47 dpavlin 23 $q->br,
48     'Draw as ',
49     $q->checkbox(
50     -name => 'line',
51     -onChange => 'trace_frm.submit()',
52     ),
53 dpavlin 24 ' with ',
54     $q->popup_menu(
55     -name => 'placemark_filter',
56     -values => [ 'every', 'total of' ],
57     ),
58 dpavlin 23 $q->textfield(
59 dpavlin 24 -name => 'placemark',
60 dpavlin 23 -value => 5,
61     -size => 2,
62     -onChange => 'trace_frm.submit()',
63     ),
64 dpavlin 24 ' placemarks',
65 dpavlin 15 $q->end_form,
66     );
67 dpavlin 13
68 dpavlin 23
69    
70 dpavlin 14 if ( my $trace = $q->param('trace') ) {
71     $trace =~ s/\s.+$//;
72 dpavlin 13
73 dpavlin 14 $trace = "$trace_path/$trace";
74 dpavlin 13
75 dpavlin 14 my $points = 0;
76 dpavlin 24 my $center_point;
77     my @points;
78     my @placemarks;
79 dpavlin 13
80 dpavlin 14 open(my $fh, '<', $trace) || die "can't open $trace: $!";
81     while( <$fh> ) {
82 dpavlin 13
83 dpavlin 14 my $hash = NMEA->line( $_ ) || next;
84 dpavlin 13
85 dpavlin 23 my $point = [ $hash->{lon}, $hash->{lat} ];
86     $center_point ||= $point;
87 dpavlin 13
88 dpavlin 24 push @points, $point;
89 dpavlin 23
90 dpavlin 24 push @placemarks, {
91     point => $point,
92     html => join('<br/>',
93     map {
94     ucfirst($_) . ': ' . $hash->{$_}
95     } ( qw/time lat lon speed course/ )
96     ),
97     };
98 dpavlin 23
99 dpavlin 14 $points++;
100 dpavlin 23
101 dpavlin 14 }
102     close($fh);
103 dpavlin 13
104 dpavlin 18 if ( $points > 0 ) {
105 dpavlin 13
106 dpavlin 24 my $map = HTML::GoogleMaps->new(
107     key => $map_key,
108     width => '800px',
109     height => '600px',
110     );
111     #$map->center(point => "Zagreb, Hrvatska");
112    
113 dpavlin 18 #$map->zoom(10);
114 dpavlin 24 $map->v2_zoom(20);
115 dpavlin 18 $map->controls("large_map_control", "map_type_control");
116     $map->map_type('hybrid');
117 dpavlin 23 $map->center( $center_point ) if $q->param('line') && $center_point;
118 dpavlin 13
119 dpavlin 23 if ( $q->param('line') ) {
120     warn "## points = ",dump( @points );
121     $map->add_polyline( points => [ @points ] );
122     }
123    
124 dpavlin 24 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 dpavlin 18 my ( $map_div, $map_script );
155     ( $head, $map_div, $map_script ) = $map->render;
156    
157     $html .= join('', qq{
158 dpavlin 24 $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 dpavlin 14 $map_div
163     $map_script
164     <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>
165 dpavlin 18 });
166    
167     } else {
168     $html .= '<em>No points found for ' . $q->param('trace') . '</em>';
169     }
170 dpavlin 13
171     }
172    
173     print qq{
174 dpavlin 15 <html>
175     <head>
176     <title>Read GPS - NMEA sentence and display it on GoogleMaps</title>
177     $head
178     </head>
179     <body>
180     $html
181 dpavlin 13 </body>
182     </html>
183     };

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26