summaryrefslogtreecommitdiff
path: root/httemplate/view/directions.html
blob: f14a11a0754ef59c50cbd1271d720581a65049cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
%# the actual page
<& /elements/header-popup.html, {
     title => '',#$name,
     head  => include('.head'),
     etc   => 'onload="initialize()"',
     nobr  => 1,
   }
&>

<div id="directions_panel"></div>
<div id="map_canvas"></div>

<%def .head>
% my $lat = $cgi->param('lat');
% my $lon = $cgi->param('lon');
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

<style type="text/css">
html { height: 100% }

body { height: 100%; margin: 0px; padding: 0px }

#map_canvas {
  height: 100%;
}

#directions_panel {
  height: 100%;
  float: right;
  width: 310px;
  overflow: auto;
  font-size: 80%;
}

@media print {
  #map_canvas { height: 500px; margin: 0; }
  #directions_panel { float: none; width: auto; }
}
</style>

<script type="text/javascript" 
src="https://maps.google.com/maps/api/js?v=3.4&sensor=false">
</script>

<script type="text/javascript">
var lengthLine=0;
var map;

function show_route() {
  var panel = document.getElementById('directions_panel');
  var directionsService = new google.maps.DirectionsService;
  var directionsDisplay = new google.maps.DirectionsRenderer;
  directionsDisplay.setMap(map);
  directionsDisplay.setPanel(panel);

  var directionsRequest = {
    origin: <%$origin |js_string%>,
    destination: <% $lat %>+","+<% $lon %>,
    travelMode: google.maps.TravelMode.DRIVING
  };

  directionsService.route(directionsRequest, function(result, status) {
    if ( status == google.maps.DirectionsStatus.OK ) {
      directionsDisplay.setDirections(result);
    }
  });
}

function initialize() {
  var myOptions = {
    zoom: 14,
    rotateControl: true,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  map = new google.maps.Map(
    document.getElementById("map_canvas"),
    myOptions
  );
  map.setOptions( {rotateControl : true });

  show_route();
}
</script>
</%def>
<%shared>
my ($lat, $lon, $name, $origin);
</%shared>
<%init>

$name = $cgi->param('name');

$lat = $cgi->param('lat');
$lon = $cgi->param('lon');
$lat =~ /^-?\d+(\.\d+)?$/ or die "bad latitude: $lat";
$lon =~ /^-?\d+(\.\d+)?$/ or die "bad longitude: $lat";

$origin = $cgi->param('origin') or die "no origin specified";

</%init>