b3459dc1f0dd1293e412536e2efc11cc35b4e33e
[freeside.git] / httemplate / view / map.html
1 % if ( $apikey ) {
2
3 %# the actual page
4 <& /elements/header-popup.html, {
5      title => '',#$name,
6      head  => include('.head'),
7      etc   => 'onload="initialize()"',
8      nobr  => 1,
9    }
10 &>
11
12 <div id="map_canvas"></div>
13
14 % } else {
15 <& /elements/header-popup.html &>
16 <& /elements/google_maps_api_key.html &>
17 % }
18
19 <%def .head>
20 <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
21
22 <style type="text/css">
23 html { height: 100% }
24
25 body { height: 100%; margin: 0px; padding: 0px }
26
27 #map_canvas { height: 100%; }
28
29 @media print { #map_canvas { height: 500px; margin: 0; } }
30 </style>
31
32 <script type="text/javascript" src="https://maps.google.com/maps/api/js?v=3&key=<% $apikey %>">
33 </script>
34
35 <script type="text/javascript">
36 var lengthLine=0;
37 var map;
38
39 // function name specified by google maps api, special hook for auth errors
40 function gm_authFailure () {
41   document.body.innerHTML = 
42 <% include('/elements/google_maps_api_key.html', autherror => 1) |js_string%>;
43 }
44
45
46 function initialize() {
47   var latlng = new google.maps.LatLng(<%$lat%>, <%$lon%>);
48   var myOptions = {
49     center: latlng,
50     zoom: 14,
51     rotateControl: true,
52     mapTypeId: google.maps.MapTypeId.ROADMAP
53   };
54
55   map = new google.maps.Map(
56     document.getElementById("map_canvas"),
57     myOptions
58   );
59   map.setOptions( {rotateControl : true });
60
61   var markerOptions = {
62     map: map,
63     position: latlng,
64     title: <%$name |js_string%>
65   };
66   var marker = new google.maps.Marker(markerOptions);
67 }
68 </script>
69 </%def>
70 <%shared>
71 my ($lat, $lon, $name);
72 my $conf = new FS::Conf;
73 my $apikey = $conf->config('google_maps_api_key');
74 </%shared>
75 <%init>
76
77 $name = $cgi->param('name');
78
79 $lat = $cgi->param('lat');
80 $lon = $cgi->param('lon');
81 $lat =~ /^-?\d+(\.\d+)?$/ or die "bad latitude: $lat";
82 $lon =~ /^-?\d+(\.\d+)?$/ or die "bad longitude: $lat";
83
84 </%init>