26 |
|
|
27 |
print $q->header; |
print $q->header; |
28 |
|
|
29 |
print qq{ |
my $head = ''; |
30 |
<html> |
my $html = join('', qq{ |
|
<title>Read GPS - NMEA sentence and display it on GoogleMaps</title> |
|
|
<body> |
|
31 |
<h1>Select GPS NMEA dump</h1> |
<h1>Select GPS NMEA dump</h1> |
32 |
}, |
}, |
33 |
$q->start_form, |
$q->start_form( -id => 'trace_frm' ), |
34 |
$q->popup_menu( |
$q->popup_menu( |
35 |
-name => 'trace', |
-name => 'trace', |
36 |
-values => [ |
-values => [ |
41 |
(stat("$trace_path/$a"))[10] <=> (stat("$trace_path/$b"))[10] |
(stat("$trace_path/$a"))[10] <=> (stat("$trace_path/$b"))[10] |
42 |
} @traces |
} @traces |
43 |
], |
], |
44 |
|
-onChange => 'trace_frm.submit()', |
45 |
), |
), |
46 |
$q->submit( -value => 'Show trace' ), |
$q->submit( -value => 'Show trace' ), |
47 |
$q->end_form; |
$q->br, |
48 |
|
'Draw as ', |
49 |
|
$q->checkbox( |
50 |
|
-name => 'line', |
51 |
|
-onChange => 'trace_frm.submit()', |
52 |
|
), |
53 |
|
' with every ', |
54 |
|
$q->textfield( |
55 |
|
-name => 'nth_placemark', |
56 |
|
-value => 5, |
57 |
|
-size => 2, |
58 |
|
-onChange => 'trace_frm.submit()', |
59 |
|
), |
60 |
|
'<sup>th</sup> placemark', |
61 |
|
$q->end_form, |
62 |
|
); |
63 |
|
|
64 |
|
|
65 |
|
my @points; |
66 |
|
my $center_point; |
67 |
|
|
68 |
if ( my $trace = $q->param('trace') ) { |
if ( my $trace = $q->param('trace') ) { |
69 |
$trace =~ s/\s.+$//; |
$trace =~ s/\s.+$//; |
74 |
$trace = "$trace_path/$trace"; |
$trace = "$trace_path/$trace"; |
75 |
|
|
76 |
my $points = 0; |
my $points = 0; |
77 |
|
my $nth_placemark = $q->param('nth_placemark'); |
78 |
|
|
79 |
open(my $fh, '<', $trace) || die "can't open $trace: $!"; |
open(my $fh, '<', $trace) || die "can't open $trace: $!"; |
80 |
while( <$fh> ) { |
while( <$fh> ) { |
81 |
|
|
82 |
my $hash = NMEA->line( $_ ) || next; |
my $hash = NMEA->line( $_ ) || next; |
83 |
|
|
84 |
$map->add_marker( |
my $point = [ $hash->{lon}, $hash->{lat} ]; |
85 |
point => [ $hash->{lon}, $hash->{lat} ], |
$center_point ||= $point; |
86 |
html => join('<br/>', |
|
87 |
map { |
|
88 |
ucfirst($_) . ': ' . $hash->{$_} |
if ( $q->param('line') ) { |
89 |
} ( qw/time lat lon speed course/ ) |
push @points, $point; |
90 |
), |
} |
91 |
); |
|
92 |
|
if ( ! $q->param('line') || |
93 |
|
$nth_placemark && $points % $nth_placemark == 0 |
94 |
|
) { |
95 |
|
|
96 |
|
$map->add_marker( |
97 |
|
point => $point, |
98 |
|
html => join('<br/>', |
99 |
|
map { |
100 |
|
ucfirst($_) . ': ' . $hash->{$_} |
101 |
|
} ( qw/time lat lon speed course/ ) |
102 |
|
), |
103 |
|
); |
104 |
|
|
105 |
|
} |
106 |
|
|
107 |
$points++; |
$points++; |
108 |
|
|
109 |
} |
} |
110 |
close($fh); |
close($fh); |
111 |
|
|
112 |
#$map->zoom(10); |
if ( $points > 0 ) { |
113 |
#$map->v2_zoom(0); |
|
114 |
$map->controls("large_map_control", "map_type_control"); |
#$map->zoom(10); |
115 |
$map->map_type('hybrid'); |
#$map->v2_zoom(0); |
116 |
|
$map->controls("large_map_control", "map_type_control"); |
117 |
|
$map->map_type('hybrid'); |
118 |
|
$map->center( $center_point ) if $q->param('line') && $center_point; |
119 |
|
|
120 |
|
if ( $q->param('line') ) { |
121 |
|
warn "## points = ",dump( @points ); |
122 |
|
$map->add_polyline( points => [ @points ] ); |
123 |
|
} |
124 |
|
|
125 |
my ($head, $map_div, $map_script) = $map->render; |
my ( $map_div, $map_script ); |
126 |
|
( $head, $map_div, $map_script ) = $map->render; |
127 |
|
|
128 |
print qq{ |
$html .= join('', qq{ |
129 |
<h1>Plotting $points points from }, $q->param('trace'), qq{</h1> |
<h1>Plotting $points points from }, $q->param('trace'), qq{</h1> |
130 |
$map_div |
$map_div |
131 |
$map_script |
$map_script |
132 |
<a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a> |
<a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a> |
133 |
}; |
}); |
134 |
|
|
135 |
|
} else { |
136 |
|
$html .= '<em>No points found for ' . $q->param('trace') . '</em>'; |
137 |
|
} |
138 |
|
|
139 |
} |
} |
140 |
|
|
141 |
print qq{ |
print qq{ |
142 |
|
<html> |
143 |
|
<head> |
144 |
|
<title>Read GPS - NMEA sentence and display it on GoogleMaps</title> |
145 |
|
$head |
146 |
|
</head> |
147 |
|
<body> |
148 |
|
$html |
149 |
</body> |
</body> |
150 |
</html> |
</html> |
151 |
}; |
}; |