--- web/googlemap.cgi 2007/12/06 14:03:00 23 +++ web/googlemap.cgi 2007/12/07 00:59:05 24 @@ -50,31 +50,32 @@ -name => 'line', -onChange => 'trace_frm.submit()', ), - ' with every ', + ' with ', + $q->popup_menu( + -name => 'placemark_filter', + -values => [ 'every', 'total of' ], + ), $q->textfield( - -name => 'nth_placemark', + -name => 'placemark', -value => 5, -size => 2, -onChange => 'trace_frm.submit()', ), - 'th placemark', + ' placemarks', $q->end_form, ); -my @points; -my $center_point; 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 $nth_placemark = $q->param('nth_placemark'); + my $center_point; + my @points; + my @placemarks; open(my $fh, '<', $trace) || die "can't open $trace: $!"; while( <$fh> ) { @@ -84,25 +85,16 @@ my $point = [ $hash->{lon}, $hash->{lat} ]; $center_point ||= $point; + push @points, $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/ ) - ), - ); - - } + push @placemarks, { + point => $point, + html => join('
', + map { + ucfirst($_) . ': ' . $hash->{$_} + } ( qw/time lat lon speed course/ ) + ), + }; $points++; @@ -111,8 +103,15 @@ 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(0); + $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; @@ -122,11 +121,44 @@ $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 ( $map_div, $map_script ); ( $head, $map_div, $map_script ) = $map->render; $html .= join('', qq{ -

Plotting $points points from }, $q->param('trace'), 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