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

Contents of /web/googlemap.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26