/[maps]/web/googlemap.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /web/googlemap.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by dpavlin, Fri Dec 7 00:59:05 2007 UTC revision 25 by dpavlin, Fri Dec 7 02:38:47 2007 UTC
# Line 45  my $html = join('', qq{ Line 45  my $html = join('', qq{
45          ),          ),
46          $q->submit( -value => 'Show trace' ),          $q->submit( -value => 'Show trace' ),
47          $q->br,          $q->br,
48          'Draw as ',          'Draw ',
49          $q->checkbox(          $q->popup_menu(
50                  -name => 'line',                  -name => 'points_filter',
51                    -values => [ 'all', 'every', 'total of' ],
52            ),
53            $q->textfield(
54                    -name => 'points_count',
55                    -value => '',
56                    -size => 2,
57                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
58          ),          ),
59          ' with ',          ' points and ',
60          $q->popup_menu(          $q->popup_menu(
61                  -name => 'placemark_filter',                  -name => 'placemark_filter',
62                  -values => [ 'every', 'total of' ],                  -values => [ 'total of', 'every' ],
63          ),          ),
64          $q->textfield(          $q->textfield(
65                  -name => 'placemark',                  -name => 'placemark_count',
66                  -value => 5,                  -value => 5,
67                  -size => 2,                  -size => 2,
68                  -onChange => 'trace_frm.submit()',                  -onChange => 'trace_frm.submit()',
# Line 72  if ( my $trace = $q->param('trace') ) { Line 78  if ( my $trace = $q->param('trace') ) {
78    
79          $trace = "$trace_path/$trace";          $trace = "$trace_path/$trace";
80    
         my $points = 0;  
81          my $center_point;          my $center_point;
82          my @points;          my @points;
83          my @placemarks;          my @placemarks;
# Line 96  if ( my $trace = $q->param('trace') ) { Line 101  if ( my $trace = $q->param('trace') ) {
101                          ),                          ),
102                  };                  };
103    
                 $points++;  
   
104          }          }
105          close($fh);          close($fh);
106    
107          if ( $points > 0 ) {          if ( $#points >= 0 ) {
108    
109                  my $map = HTML::GoogleMaps->new(                  my $map = HTML::GoogleMaps->new(
110                          key => $map_key,                          key => $map_key,
# Line 116  if ( my $trace = $q->param('trace') ) { Line 119  if ( my $trace = $q->param('trace') ) {
119                  $map->map_type('hybrid');                  $map->map_type('hybrid');
120                  $map->center( $center_point ) if $q->param('line') && $center_point;                  $map->center( $center_point ) if $q->param('line') && $center_point;
121    
122                  if ( $q->param('line') ) {                  sub filter_array {
123                          warn "## points = ",dump( @points );                          my $o = {@_};
124                          $map->add_polyline( points => [ @points ] );                          my (     $count,      $filter,      $code  ) =
125                  }                             ( $o->{count}, $o->{filter}, $o->{code} ) ;
126                            confess "no CODE?" unless ref($code) eq 'CODE';
127                  my $placemarks = 0;                          my @array = @{ $o->{array} };
128    
129                  if ( my $placemark = $q->param('placemark') ) {                          warn "count: $count filter: $filter\n";
130                          if ( $q->param('placemark_filter') eq 'every' ) {  
131                                  foreach my $o ( 0 .. $#placemarks ) {                          my $code_calls = 0;
132                                          next unless $o % $placemark == 0;  
133                                          $map->add_marker( %{ $placemarks[$o] } );                          if ( $count && $filter =~ m/every/ ) {
134                                          $placemarks++;                                  foreach my $o ( 0 .. $#array ) {
135                                            next unless $o % $count == 0;
136                                            $code->( $array[$o] );
137                                            $code_calls++;
138                                  }                                  }
139                          } else {                          } elsif ( $count && $filter =~ m/total/ ) {
140                                  # total of                                  # total of
141                                  my $d = $points / ( $placemark - 1 );                                  if ( $count < 2 ) {
142                                  foreach my $p ( 0 .. $placemark - 2 ) {                                          # first
143                                            if ( $array[0]) {
144                                                    $code->( $array[0] );
145                                                    $code_calls++;
146                                            };
147                                            # last
148                                            if ( $count > 1 && $#array > 0 ) {
149                                                    $code->( $array[$#array] );
150                                                    $code_calls++;
151                                            };
152                                            return $code_calls;
153                                    }
154    
155                                    my $d = $#array / ( $count - 1 );
156                                    foreach my $p ( 0 .. $count - 1 ) {
157                                          my $o = int($p * $d);                                          my $o = int($p * $d);
158                                          die "no placemark $p at $o from total of $#placemarks" unless $placemarks[$o];                                          die "no element $p at $o from total of ",$#array + 1 unless $array[$o];
159                                          $map->add_marker( %{ $placemarks[$o] } );                                          $code->( $array[$o] );
160                                          $placemarks++;                                          $code_calls++;
161                                    }
162                            } else {
163                                    # show every
164                                    foreach my $e ( @array ) {
165                                            $code->( $e );
166                                            $code_calls++;
167                                  }                                  }
                                 # add last one  
                                 $map->add_marker( %{ $placemarks[$#placemarks] } );  
                                 $placemarks++;  
                         }  
                 } else {  
                         # show every placemark  
                         foreach my $marker ( @placemarks ) {  
                                 $map->add_marker( %$marker );  
                                 $placemarks++;  
168                          }                          }
169                            return $code_calls;
170                  }                  }
171    
172                    my @poly_points;
173                    my $points = filter_array(
174                            count => $q->param('points_count'),
175                            filter => $q->param('points_filter'),
176                            code => sub {
177                                    my $point = shift;
178                                    push @poly_points, $point;
179                            },
180                            array => \@points,
181                    );
182    
183                    die "hum?" unless $#poly_points == $points - 1;
184    
185                    $map->add_polyline( points => [ @poly_points ] ) if @poly_points;
186    
187                    my $placemarks = filter_array(
188                            count => $q->param('placemark_count'),
189                            filter => $q->param('placemark_filter'),
190                            code => sub {
191                                    my $placemark = shift;
192                                    $map->add_marker( %$placemark, noformat => 1 );
193                            },
194                            array => \@placemarks,
195                    );
196    
197                  my ( $map_div, $map_script );                  my ( $map_div, $map_script );
198                  ( $head, $map_div, $map_script ) = $map->render;                  ( $head, $map_div, $map_script ) = $map->render;
199    
200                  $html .= join('', qq{                  $html .= join('',
201  $points points from <tt>}, $q->param('trace'), qq{</tt> showing },  $#points + 1, ' points from <tt>', $q->param('trace'), '</tt> showing ',
202          $#points > 0 ? $#points + 1 . ' points' . ( $placemarks ? ' and ' : '' ) : '',          $points ? $points . ' points' . ( $placemarks ? ' and ' : '' ) : '',
203          $placemarks ? $placemarks . ' placemarks' : '',          $placemarks ? $placemarks . ' placemarks' : '',
204          qq{          qq{
205  $map_div  $map_div

Legend:
Removed from v.24  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26