--- web/googlemap.cgi 2007/12/03 19:16:55 19 +++ web/googlemap.cgi 2007/12/06 14:03:00 23 @@ -44,9 +44,27 @@ -onChange => 'trace_frm.submit()', ), $q->submit( -value => 'Show trace' ), + $q->br, + 'Draw as ', + $q->checkbox( + -name => 'line', + -onChange => 'trace_frm.submit()', + ), + ' with every ', + $q->textfield( + -name => 'nth_placemark', + -value => 5, + -size => 2, + -onChange => 'trace_frm.submit()', + ), + 'th placemark', $q->end_form, ); + +my @points; +my $center_point; + if ( my $trace = $q->param('trace') ) { $trace =~ s/\s.+$//; @@ -56,22 +74,38 @@ $trace = "$trace_path/$trace"; my $points = 0; + my $nth_placemark = $q->param('nth_placemark'); open(my $fh, '<', $trace) || die "can't open $trace: $!"; while( <$fh> ) { my $hash = NMEA->line( $_ ) || next; - $map->add_marker( - point => [ $hash->{lon}, $hash->{lat} ], - html => join('
', - map { - ucfirst($_) . ': ' . $hash->{$_} - } ( qw/time lat lon speed course/ ) - ), - ); + my $point = [ $hash->{lon}, $hash->{lat} ]; + $center_point ||= $point; + + + if ( $q->param('line') ) { + push @points, $point; + } + + if ( ! $q->param('line') || + $nth_placemark && $points % $nth_placemark == 0 + ) { + + $map->add_marker( + point => $point, + html => join('
', + map { + ucfirst($_) . ': ' . $hash->{$_} + } ( qw/time lat lon speed course/ ) + ), + ); + + } $points++; + } close($fh); @@ -81,6 +115,12 @@ #$map->v2_zoom(0); $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 ( $map_div, $map_script ); ( $head, $map_div, $map_script ) = $map->render;