--- web/googlemap.cgi 2007/12/03 14:25:40 14 +++ web/googlemap.cgi 2007/12/07 00:59:05 24 @@ -26,13 +26,11 @@ print $q->header; -print qq{ - -Read GPS - NMEA sentence and display it on GoogleMaps - +my $head = ''; +my $html = join('', qq{

Select GPS NMEA dump

}, - $q->start_form, + $q->start_form( -id => 'trace_frm' ), $q->popup_menu( -name => 'trace', -values => [ @@ -43,55 +41,143 @@ (stat("$trace_path/$a"))[10] <=> (stat("$trace_path/$b"))[10] } @traces ], + -onChange => 'trace_frm.submit()', ), $q->submit( -value => 'Show trace' ), - $q->end_form; + $q->br, + 'Draw as ', + $q->checkbox( + -name => 'line', + -onChange => 'trace_frm.submit()', + ), + ' with ', + $q->popup_menu( + -name => 'placemark_filter', + -values => [ 'every', 'total of' ], + ), + $q->textfield( + -name => 'placemark', + -value => 5, + -size => 2, + -onChange => 'trace_frm.submit()', + ), + ' placemarks', + $q->end_form, +); + + if ( my $trace = $q->param('trace') ) { $trace =~ s/\s.+$//; - my $map = HTML::GoogleMaps->new(key => $map_key); - #$map->center(point => "Zagreb, Hrvatska"); - $trace = "$trace_path/$trace"; my $points = 0; + my $center_point; + my @points; + my @placemarks; open(my $fh, '<', $trace) || die "can't open $trace: $!"; while( <$fh> ) { my $hash = NMEA->line( $_ ) || next; - $map->add_marker( - point => [ $hash->{lon}, $hash->{lat} ], + my $point = [ $hash->{lon}, $hash->{lat} ]; + $center_point ||= $point; + + push @points, $point; + + push @placemarks, { + point => $point, html => join('
', map { ucfirst($_) . ': ' . $hash->{$_} } ( qw/time lat lon speed course/ ) ), - ); + }; $points++; + } close($fh); - #$map->zoom(10); - #$map->v2_zoom(0); - $map->controls("large_map_control", "map_type_control"); - $map->map_type('hybrid'); + if ( $points > 0 ) { + + my $map = HTML::GoogleMaps->new( + key => $map_key, + width => '800px', + height => '600px', + ); + #$map->center(point => "Zagreb, Hrvatska"); + + #$map->zoom(10); + $map->v2_zoom(20); + $map->controls("large_map_control", "map_type_control"); + $map->map_type('hybrid'); + $map->center( $center_point ) if $q->param('line') && $center_point; + + if ( $q->param('line') ) { + warn "## points = ",dump( @points ); + $map->add_polyline( points => [ @points ] ); + } + + my $placemarks = 0; + + if ( my $placemark = $q->param('placemark') ) { + if ( $q->param('placemark_filter') eq 'every' ) { + foreach my $o ( 0 .. $#placemarks ) { + next unless $o % $placemark == 0; + $map->add_marker( %{ $placemarks[$o] } ); + $placemarks++; + } + } else { + # total of + my $d = $points / ( $placemark - 1 ); + foreach my $p ( 0 .. $placemark - 2 ) { + my $o = int($p * $d); + die "no placemark $p at $o from total of $#placemarks" unless $placemarks[$o]; + $map->add_marker( %{ $placemarks[$o] } ); + $placemarks++; + } + # add last one + $map->add_marker( %{ $placemarks[$#placemarks] } ); + $placemarks++; + } + } else { + # show every placemark + foreach my $marker ( @placemarks ) { + $map->add_marker( %$marker ); + $placemarks++; + } + } - my ($head, $map_div, $map_script) = $map->render; + my ( $map_div, $map_script ); + ( $head, $map_div, $map_script ) = $map->render; - print qq{ -

Plotting $points points from }, $q->param('trace'), qq{

+ $html .= join('', qq{ +$points points from }, $q->param('trace'), qq{ showing }, + $#points > 0 ? $#points + 1 . ' points' . ( $placemarks ? ' and ' : '' ) : '', + $placemarks ? $placemarks . ' placemarks' : '', + qq{ $map_div $map_script GPS - NMEA sentence information - }; + }); + + } else { + $html .= 'No points found for ' . $q->param('trace') . ''; + } } print qq{ + + +Read GPS - NMEA sentence and display it on GoogleMaps +$head + + +$html };