2 type => 'FeatureCollection',
7 die "access denied" unless
8 $FS::CurrentUser::CurrentUser->access_right('List services');
10 my $conf = new FS::Conf;
12 my @features; # geoJSON structure
14 # accept all the search logic from svc_broadband.cgi...
16 if ( $cgi->param('magic') eq 'unlinked' ) {
17 %search_hash = ( 'unlinked' => 1 );
19 foreach (qw( custnum agentnum svcpart cust_fields )) {
20 $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
22 foreach (qw(pkgpart routernum towernum sectornum)) {
23 $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
27 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
28 $search_hash{'order_by'} = "ORDER BY $1";
31 my $sql_query = FS::svc_broadband->search(\%search_hash);
33 my %routerbyblock = ();
35 my @rows = qsearch($sql_query);
40 foreach my $svc_broadband (@rows) {
41 # don't try to show it if coords aren't set
42 next if !$svc_broadband->latitude || !$svc_broadband->longitude;
43 # coerce coordinates to numbers
45 $svc_broadband->longitude + 0,
46 $svc_broadband->latitude + 0,
48 push @coord, $svc_broadband->altitude + 0
49 if length($svc_broadband->altitude); # it's optional
51 my $svcnum = $svc_broadband->svcnum;
52 my $color = $svc_broadband->addr_status_color;
57 id => 'svc_broadband/'.$svcnum,
60 coordinates => \@coord,
63 #content => include('.svc_broadband', $svc_broadband),
64 url => $fsurl . 'view/svc_broadband-popup.html?' . $svcnum,
72 # look up tower location and draw connecting line
73 next if !$svc_broadband->sectornum;
74 my $sector = $sectors{$svc_broadband->sectornum} ||= $svc_broadband->tower_sector;
75 my $towernum = $sector->towernum;
76 my $tower = $towers{$towernum};
79 $tower = $towers{$towernum} = $sector->tower;
80 $tower_coord{$towernum} =
81 [ $tower->longitude + 0,
83 ($tower->altitude || 0) + 0,
88 if ( $tower->latitude and $tower->longitude ) {
92 id => 'svc_broadband/'.$svcnum.'/line',
95 coordinates => [ \@coord, $tower_coord{$towernum} ],
100 strokeColor => $color,
106 } # if tower has coords
107 } # foreach $svc_broadband