--- web/googlemap.cgi 2007/12/07 04:05:07 29 +++ web/googlemap.cgi 2007/12/07 15:53:41 30 @@ -12,6 +12,7 @@ use lib '../lib'; use blib; use NMEA; +use KML; my $trace_path = '../nmea/'; @@ -25,8 +26,6 @@ my $q = CGI->new; -print $q->header; - my $head = ''; my $html = join('', qq{

Select GPS NMEA dump

@@ -44,7 +43,15 @@ ], -onChange => 'trace_frm.submit()', ), - $q->submit( -value => 'Show trace' ), + $q->submit( + -name => 'show', + -value => 'Show trace' + ), + ' Export to ', + $q->submit( + -name => 'export', + -value => 'KML' + ), $q->br, 'Draw ', $q->popup_menu( @@ -100,6 +107,7 @@ ucfirst($_) . ': ' . $hash->{$_} } ( qw/number time lat lon speed course/ ) ), + %$hash, }; } @@ -107,19 +115,6 @@ 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; - sub filter_array { my $o = {@_}; my ( $count, $filter, $code ) = @@ -170,6 +165,12 @@ return $code_calls; } + my $map = HTML::GoogleMaps->new( + key => $map_key, + width => '800px', + height => '600px', + ); + my @poly_points; my $points = filter_array( count => $q->param('points_count'), @@ -183,7 +184,7 @@ die "hum?" unless $#poly_points == $points - 1; - $map->add_polyline( points => [ @poly_points ] ) if @poly_points; + my @filtered_placemarks; my $placemarks = filter_array( count => $q->param('placemark_count'), @@ -191,10 +192,34 @@ code => sub { my $placemark = shift; $map->add_marker( %$placemark, noformat => 1 ); + push @filtered_placemarks, $placemark; }, array => \@placemarks, ); + if ( my $export = $q->param('export') ) { + if ( $export eq 'KML' ) { + print $q->header( + -type => 'application/xhtml+xml', + ), + KML->output( placemarks => \@filtered_placemarks ); + exit; + } else { + die "unknown export format $export"; + } + } + + + #$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; + + $map->add_polyline( points => [ @poly_points ] ) if @poly_points; + my ( $map_div, $map_script ); ( $head, $map_div, $map_script ) = $map->render; @@ -221,6 +246,7 @@ } +print $q->header; print qq{