6 Generic Google Maps front end.
8 <& /elements/gmap.html,
10 { id => 'svc_acct/12',
13 coordinates => [ -86, 40 ], # optionally altitude as the third coord
16 # see https://developers.google.com/maps/documentation/javascript/3.exp/reference#Data.StyleOptions
20 fillColor => 'orange',
23 # content of popup info box (might AJAX this later)
24 content => '<a href="view/svc_acct.cgi?12">username@example.com</a>',
29 { url => 'https://localhost/freeside/view/sector_map-png.html?102',
34 }, # make a ground overlay
41 $_->{type} = 'Feature';
42 # any other per-feature massaging can go here
45 type => 'FeatureCollection',
46 features => \@features
49 my $apikey = FS::Conf->new->config('google_maps_api_key');
52 <div id="map_canvas"></div>
54 <style type="text/css">
57 body { height: 100%; margin: 0px; padding: 0px }
59 #map_canvas { height: 100%; }
62 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3<% $apikey ? "&key=$apikey" : '' %>">
65 <script type="text/javascript">
67 var data_geojson = <% encode_json($tree) %>;
68 var data_overlays = <% encode_json(\@overlays) %>;
73 path: google.maps.SymbolPath.CIRCLE,
82 var featureStyle = function(feature) {
83 // jQuery.extend(): merge properties of objects
84 // 'true' makes it a deep copy; start the merge with {} so that
85 // baseStyle doesn't get overwritten
86 return $.extend(true, {}, baseStyle, feature.getProperty('style'));
92 var canvas = $('#map_canvas');
93 map = new google.maps.Map(canvas[0], { zoom: 6 });
95 map.data.addGeoJson(data_geojson);
97 console.log(ex.toString);
101 // construct bounds around all of the features
102 var bounds = new google.maps.LatLngBounds;
103 map.data.forEach(function(feature) {
104 var b = feature.getProperty('bounds');
105 if (b) { // if it specifies an ROI, include all of it
108 var g = feature.getGeometry();
109 if (g.getType() == 'Point') {
110 bounds.extend(g.get());
111 } else if (g.getArray) {
112 g.getArray().forEach(function(point) { bounds.extend(point); });
117 map.fitBounds(bounds);
118 map.data.setStyle(featureStyle);
120 var info = new google.maps.InfoWindow;
121 map.data.addListener('click', function(ev) {
122 var feature = ev.feature;
123 if ( feature.getGeometry().getType() == 'Point' ) {
124 // then pop up an info box with the feature content
126 info.setPosition(feature.getGeometry().get());
127 info.setContent(feature.getProperty('content'));
131 // snap to feature ROI if it has one
132 if ( feature.getProperty('bounds') ) {
133 map.fitBounds( feature.getProperty('bounds') );
138 data_overlays.forEach(function(x) {
141 var overlay = new google.maps.GroundOverlay( url, x );
143 overlay.setOpacity(0.4);
144 overlays.push(overlay);
148 $().ready( initMap );