From 391be944b451419e2683dcd0471e3532d728d8d5 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Sat, 12 Mar 2016 18:59:05 -0800 Subject: [PATCH] show map of svc_broadband and tower locations, #37802 --- httemplate/images/antenna-square-21x51.png | Bin 0 -> 1475 bytes httemplate/search/elements/gmap.html | 123 ++++++++++++++++++++ httemplate/search/svc_broadband-map.html | 178 +++++++++++++++++++++++++++++ httemplate/search/svc_broadband.cgi | 4 + 4 files changed, 305 insertions(+) create mode 100644 httemplate/images/antenna-square-21x51.png create mode 100644 httemplate/search/elements/gmap.html create mode 100755 httemplate/search/svc_broadband-map.html diff --git a/httemplate/images/antenna-square-21x51.png b/httemplate/images/antenna-square-21x51.png new file mode 100644 index 0000000000000000000000000000000000000000..0ba5e73d27f4dcc6850656da7002a4dadd65b2bb GIT binary patch literal 1475 zcmXw3dpOf;9AA;J;z>vzx21^8T*ujRpK7_Y#XPBIer(1z+uVkBT)J!&MTDZ(A>`5p zrQ=?5BINEM_gD>wTyk25XgS)8H_vF z6~HozM@$Fn2A%foDYFSZBWpB+wQ z0+8_VaD57m$|4aNfIgiWkUf7=86?SXlW-Jv5C9?4*Z_@2)L?~#f&!=cSXmI4-NtP~ z*sIOdiw!y|9#amSGL1I0 z;~z~hIDSN0pe8u_Esv8@pr&jh8GlMo`pVyWTRNQ__)S%0*eKs)bqy zqb7ziHY6Hauj~I&_K$azIzR|qwzK-spgnLSnE~bJi?SeUiFmJsPNnO-HOT#%Juwid zXkb0Rx&OPwGCHZ{J9^QA_QxWQt*Sugym;BD8a8HG{C+XhYe=#@8RbGqUw?K$v%6g5 z;41EB2ew0G<6&Daemzj58LL~&WXTr7KOlj=yT66_r>Yj8fWrLXtT#e2SxRZ>V??KN)s zSOtFVAV%!)tw}4)-^kAu3go@W@g9}rCNuBF!6O?T2}xSK1@wZp<*dSELGFB`M0NTD zhi4Z|X0KKwq1@_%-0m20I{p21HBy?ZlCCZE6o^jneJ#&TDzq&R)^|sRxYXwA z$$9YK8JW)|w{8u3xS&7!$Tzu$q|Kg*vifj>KOxShrW9*hCklj#&=7adYN5FWk3X1M zS@Wv=IKMJ|e9{QEp#JezWjwEC@yNG%Gw7Mnl!ZYuJ!i}mjqK_CCQ z${YiGLeY2h_DDHC=81OUR)nK4GRCy5H`N~+(~drp z9ctY@B8woZ&lhDBNZIN>T8wm)?>33#3+}?^#l^ZG+P!a4g~GCHf62+YR}-J8qQ502 zfR{E-l~*J#70+E-6U6p>eX;+gRx{Lo6`fiq>e;Y!%j@Tlhy7_KT0r`!wB`w2QOvM}dA_n1vN8+OW|*mB5uWmP+*v2Y)v<@-T&?>9TBt#ZBvHK1L}j(@`Fj6j z!Y=^9S*MkmTJ%`2bq*l3D`q4G-{pCF=rF2=iBX(Y~`d!|g+ULKo7M8wUliI;rvceAG&F_gjSk7kGq)>v@>;_^-mixllCM zSq-L7ti#t+pIcQ(2kBf@i|tH!L@aFZ(Ye1_Qtutt=NC?6j`Z#;{ +@features + +<%doc> +Generic Google Maps front end. + +<& /elements/gmap.html, + features => [ + { id => 'svc_acct/12', + geometry => { + type => 'Point', + coordinates => [ -86, 40 ], # optionally altitude as the third coord + }, + properties => { + # see https://developers.google.com/maps/documentation/javascript/3.exp/reference#Data.StyleOptions + style => { + icon => { + scale => 4, + fillColor => 'orange', + } + }, + # content of popup info box (might AJAX this later) + content => 'username@example.com', + } + }, # end of feature + ], +&> + + +<%init> +foreach (@features) { + $_->{type} = 'Feature'; + # any other per-feature massaging can go here +} +my $tree = { + type => 'FeatureCollection', + features => \@features +}; + + +
+ + + + + + + diff --git a/httemplate/search/svc_broadband-map.html b/httemplate/search/svc_broadband-map.html new file mode 100755 index 000000000..4c660b016 --- /dev/null +++ b/httemplate/search/svc_broadband-map.html @@ -0,0 +1,178 @@ +<& /elements/header.html, 'Broadband Search Results' &> + +<& elements/gmap.html, features => \@features &> + +<& /elements/footer.html &> +<%init> + +die "access denied" unless + $FS::CurrentUser::CurrentUser->access_right('List services'); + +my $conf = new FS::Conf; + +my @features; # geoJSON structure + +# accept all the search logic from svc_broadband.cgi... +my %search_hash; +if ( $cgi->param('magic') eq 'unlinked' ) { + %search_hash = ( 'unlinked' => 1 ); +} else { + foreach (qw( custnum agentnum svcpart cust_fields )) { + $search_hash{$_} = $cgi->param($_) if $cgi->param($_); + } + foreach (qw(pkgpart routernum towernum sectornum)) { + $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_); + } +} + +if ( $cgi->param('sortby') =~ /^(\w+)$/ ) { + $search_hash{'order_by'} = "ORDER BY $1"; +} + +my $sql_query = FS::svc_broadband->search(\%search_hash); + +my %routerbyblock = (); + +my @rows = qsearch($sql_query); +my %sectors; +my %towers; +my %tower_coord; +my %tower_bounds; +foreach my $svc_broadband (@rows) { + # don't try to show it if coords aren't set + next if !$svc_broadband->latitude || !$svc_broadband->longitude; + # coerce coordinates to numbers + my @coord = ( + $svc_broadband->longitude + 0, + $svc_broadband->latitude + 0, + ); + push @coord, $svc_broadband->altitude + 0 + if length($svc_broadband->altitude); # it's optional + + push @features, + { + id => 'svc_broadband/'.$svc_broadband->svcnum, + geometry => { + type => 'Point', + coordinates => \@coord, + }, + properties => { + content => include('.svc_broadband', $svc_broadband), + }, + }; + # look up tower location and draw connecting line + next if !$svc_broadband->sectornum; + my $sector = $sectors{$svc_broadband->sectornum} ||= $svc_broadband->tower_sector; + my $towernum = $sector->towernum; + my $tower = $towers{$towernum}; + + if (!$tower) { + $tower = $towers{$towernum} = $sector->tower; + $tower_coord{$towernum} = + [ $tower->longitude + 0, + $tower->latitude + 0, + ($tower->altitude || 0) + 0, + ]; + + } + + my $tower = $towers{$towernum}; + if ( $tower->latitude and $tower->longitude ) { + push @features, + { + geometry => { + type => 'LineString', + coordinates => [ \@coord, $tower_coord{$towernum} ], + }, + properties => { + style => { + strokeColor => ($tower->color || 'green'), + strokeWeight => 2, + }, + }, + }; + + # also extend tower's ROI to include this point + # (this is experimental; might get better results using the centroid of + # all connected services or something) + my $bounds = $tower_bounds{$towernum} ||= { + east => $tower->longitude, + west => $tower->longitude, + north => $tower->latitude, + south => $tower->latitude, + }; + if ($coord[0] > $bounds->{east}) { + $bounds->{east} = $coord[0]; + } elsif ($coord[0] < $bounds->{west}) { + $bounds->{west} = $coord[0]; + } + if ($coord[1] > $bounds->{north}) { + $bounds->{north} = $coord[1] + } elsif ($coord[1] < $bounds->{south}) { + $bounds->{south} = $coord[1] + } + + } # if tower has coords +} # foreach $svc_broadband + +foreach my $tower (values(%towers)) { + my $towernum = $tower->towernum; + my $bounds = $tower_bounds{$towernum}; + # add some padding for easier reading + my $dx = 0.1 * ($bounds->{east} - $bounds->{west}); + my $dy = 0.1 * ($bounds->{north} - $bounds->{south}); + $bounds->{east} += $dx; + $bounds->{west} -= $dx; + $bounds->{north} += $dy; + $bounds->{south} -= $dy; + push @features, + { + id => 'tower/'.$towernum, + geometry => { + type => 'Point', + coordinates => $tower_coord{$towernum}, + }, + properties => { + style => { + icon => { + path => undef, + url => $fsurl.'images/jcartier-antenna-square-21x51.png', + anchor => { x => 10, y => 4 } + }, + }, + content => include('.tower', $tower), + bounds => $tower_bounds{$towernum}, + }, + }; +} + + +<%def .svc_broadband> +% my $svc = shift; +% my @label = $svc->cust_svc->label; +

+ + <% $label[0] |h %> #<% $svc->svcnum %> | <% $label[1] %> + +

+% my $cust_main = $svc->cust_main; + +<& /elements/small_custview.html, { + cust_main => $svc->cust_main, + #url => $fsurl.'view/cust_main.cgi', +} &> + + +<%def .tower> +% my $tower = shift; +% my $can_edit = $FS::CurrentUser::CurrentUser->access_right('Configuration'); +

+% if ( $can_edit ) { + +% } +Tower #<% $tower->towernum %> | <% $tower->towername %> +% if ( $can_edit ) { + +% } +

+ diff --git a/httemplate/search/svc_broadband.cgi b/httemplate/search/svc_broadband.cgi index 6b16ace78..ff2538c93 100755 --- a/httemplate/search/svc_broadband.cgi +++ b/httemplate/search/svc_broadband.cgi @@ -121,5 +121,9 @@ my $html_init = include('/elements/email-link.html', 'search_hash' => \%search_hash, 'table' => 'svc_broadband' ); +$html_init .= ' | ' . + '' . emt('View a map of these services') . ''; -- 2.11.0