credit silk (famfamfam)
[maps-routes-comparison] / googlemaps.js.php
1 <?php
2
3 include("i18n.phpi");
4
5 ?>
6
7 // Copyright (c) Guillaume Cottenceau and licensed under the Apache 2.0 License
8
9 function debug(txt) {
10     document.getElementById("debugbox").innerHTML += new Date() + txt + "<br/>";
11 }
12
13 function getIcon(filename) {
14     return new google.maps.MarkerImage("images/" + filename + ".png",
15                                        new google.maps.Size(32, 32),
16                                        new google.maps.Point(0, 0),
17                                        new google.maps.Point(16, 32));
18 }
19 function getSelectedIcon(filename) {
20     return new google.maps.MarkerImage("images/" + filename + "h.png",
21                                        new google.maps.Size(32, 32),
22                                        new google.maps.Point(0, 0),
23                                        new google.maps.Point(16, 32));
24 }
25
26 function getShadow(filename) {
27     return new google.maps.MarkerImage("images/" + filename + "s.png",
28                                        new google.maps.Size(56, 32),
29                                        new google.maps.Point(0, 0),
30                                        new google.maps.Point(16, 32));
31 }
32
33 function getNameRegion(name, region) {
34     return region.length > 0 ? name + ", " + region : name;
35 }
36
37
38 function displayDirectionsMoreinfo(route, node) {
39     var total_distance = 0, total_duration = 0;
40     for (i = 0; i < route.legs.length; i++) {
41         total_distance += route.legs[i].distance.value;
42         total_duration += route.legs[i].duration.value;
43     }
44     total_distance = Math.round(total_distance / 1000.0);
45     var total_hours = parseInt(total_duration / 60.0 / 60.0);
46     var total_minutes = Math.round(total_duration / 60.0 - total_hours * 60);
47     if (total_hours > 0 && total_minutes < 10) {
48         total_minutes = '0' + total_minutes;
49     }
50     var base_sentence = total_hours == 0 ? '<?php echo t('route.summary.short') ?>'
51                                          : '<?php echo t('route.summary.long') ?>';
52     node.innerHTML = base_sentence.replace('{1}', total_distance)
53                                   .replace('{2}', total_minutes)
54                                   .replace('{3}', total_hours);
55 }