Revert "RT#41671 Fix double click prevention for all legacy buttons [renamed all...
[freeside.git] / httemplate / search / svc_broadband-map.html
1 <& /elements/header.html, 'Broadband Search Results' &>
2   
3 <& elements/gmap.html, features => \@features &>
4
5 <& /elements/footer.html &>
6 <%init>
7
8 die "access denied" unless
9   $FS::CurrentUser::CurrentUser->access_right('List services');
10
11 my $conf = new FS::Conf;
12
13 my @features; # geoJSON structure
14
15 # accept all the search logic from svc_broadband.cgi...
16 my %search_hash;
17 if ( $cgi->param('magic') eq 'unlinked' ) {
18   %search_hash = ( 'unlinked' => 1 );
19 } else {
20   foreach (qw( custnum agentnum svcpart cust_fields )) {
21     $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
22   }
23   foreach (qw(pkgpart routernum towernum sectornum)) {
24     $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
25   }
26 }
27
28 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
29   $search_hash{'order_by'} = "ORDER BY $1";
30 }
31
32 my $sql_query = FS::svc_broadband->search(\%search_hash);
33
34 my %routerbyblock = ();
35
36 my @rows = qsearch($sql_query);
37 my %sectors;
38 my %towers;
39 my %tower_coord;
40 my %tower_bounds;
41 foreach my $svc_broadband (@rows) {
42   # don't try to show it if coords aren't set
43   next if !$svc_broadband->latitude || !$svc_broadband->longitude;
44   # coerce coordinates to numbers
45   my @coord = (
46     $svc_broadband->longitude + 0,
47     $svc_broadband->latitude + 0,
48   );
49   push @coord, $svc_broadband->altitude + 0
50     if length($svc_broadband->altitude); # it's optional
51
52   push @features,
53   {
54     id        => 'svc_broadband/'.$svc_broadband->svcnum,
55     geometry  => {
56       type        => 'Point',
57       coordinates => \@coord,
58     },
59     properties => {
60       content => include('.svc_broadband', $svc_broadband),
61     },
62   };
63   # look up tower location and draw connecting line
64   next if !$svc_broadband->sectornum;
65   my $sector = $sectors{$svc_broadband->sectornum} ||= $svc_broadband->tower_sector;
66   my $towernum = $sector->towernum;
67   my $tower = $towers{$towernum};
68
69   if (!$tower) {
70     $tower = $towers{$towernum} = $sector->tower;
71     $tower_coord{$towernum} =
72       [ $tower->longitude + 0,
73         $tower->latitude + 0,
74         ($tower->altitude || 0) + 0,
75       ];
76
77   }
78
79   my $tower = $towers{$towernum};
80   if ( $tower->latitude and $tower->longitude ) {
81     push @features,
82     {
83       geometry => {
84         type        => 'LineString',
85         coordinates => [ \@coord, $tower_coord{$towernum} ],
86       },
87       properties  => {
88         style       => {
89           strokeColor  => ($tower->color || 'green'),
90           strokeWeight => 2,
91         },
92       },
93     };
94
95     # also extend tower's ROI to include this point
96     # (this is experimental; might get better results using the centroid of
97     # all connected services or something)
98     my $bounds = $tower_bounds{$towernum} ||= {
99       east => $tower->longitude,
100       west => $tower->longitude,
101       north => $tower->latitude,
102       south => $tower->latitude,
103     };
104     if ($coord[0] > $bounds->{east}) {
105       $bounds->{east} = $coord[0];
106     } elsif ($coord[0] < $bounds->{west}) {
107       $bounds->{west} = $coord[0];
108     }
109     if ($coord[1] > $bounds->{north}) {
110       $bounds->{north} = $coord[1]
111     } elsif ($coord[1] < $bounds->{south}) {
112       $bounds->{south} = $coord[1]
113     }
114
115   } # if tower has coords
116 } # foreach $svc_broadband
117
118 foreach my $tower (values(%towers)) {
119   my $towernum = $tower->towernum;
120   my $bounds = $tower_bounds{$towernum};
121   # add some padding for easier reading
122   my $dx = 0.1 * ($bounds->{east} - $bounds->{west});
123   my $dy = 0.1 * ($bounds->{north} - $bounds->{south});
124   $bounds->{east} += $dx; 
125   $bounds->{west} -= $dx;
126   $bounds->{north} += $dy;
127   $bounds->{south} -= $dy;
128   push @features,
129   {
130     id        => 'tower/'.$towernum,
131     geometry  => {
132       type        => 'Point',
133       coordinates => $tower_coord{$towernum},
134     },
135     properties => {
136       style     => {
137         icon => {
138           path        => undef,
139           url         => $fsurl.'images/jcartier-antenna-square-21x51.png',
140           anchor      => { x => 10, y => 4 }
141         },
142       },
143       content   => include('.tower', $tower),
144       bounds    => $tower_bounds{$towernum},
145     },
146   };
147 }
148
149 </%init>
150 <%def .svc_broadband>
151 % my $svc = shift;
152 % my @label = $svc->cust_svc->label;
153 <H3>
154   <a target="_blank" href="<% $fsurl %>view/svc_broadband.cgi?<% $svc->svcnum %>">
155     <% $label[0] |h %> #<% $svc->svcnum %> | <% $label[1] %>
156   </a>
157 </H3>
158 % my $cust_main = $svc->cust_main;
159 <a target="_blank" href="<% $fsurl %>view/cust_main.cgi?<% $cust_main->custnum %>">
160 <& /elements/small_custview.html, {
161   cust_main => $svc->cust_main,
162   #url => $fsurl.'view/cust_main.cgi',
163 } &>
164 </a>
165 </%def>
166 <%def .tower>
167 % my $tower = shift;
168 % my $can_edit = $FS::CurrentUser::CurrentUser->access_right('Configuration');
169 <H3>
170 % if ( $can_edit ) {
171   <a target="_blank" href="<% $fsurl %>edit/tower.html?<% $tower->towernum %>">
172 % }
173 Tower #<% $tower->towernum %> | <% $tower->towername %>
174 % if ( $can_edit ) {
175   </a>
176 % }
177 </H3>
178 </%def>