replace ajax downloadurl disallowed on IE (not same domain?) by PHP
[maps-routes-comparison] / googlemaps.js
1 // Copyright (c) Guillaume Cottenceau and licensed under the Apache 2.0 License
2
3 function debug(txt) {
4     document.getElementById("debugbox").innerHTML += new Date() + txt + "<br/>";
5 }
6
7 function getIcon(filename) {
8     return new google.maps.MarkerImage("icons/" + filename + ".png",
9                                        new google.maps.Size(32, 32),
10                                        new google.maps.Point(0, 0),
11                                        new google.maps.Point(16, 32));
12 }
13 function getSelectedIcon(filename) {
14     return new google.maps.MarkerImage("icons/" + filename + "h.png",
15                                        new google.maps.Size(32, 32),
16                                        new google.maps.Point(0, 0),
17                                        new google.maps.Point(16, 32));
18 }
19
20 function getShadow(filename) {
21     return new google.maps.MarkerImage("icons/" + filename + "s.png",
22                                        new google.maps.Size(56, 32),
23                                        new google.maps.Point(0, 0),
24                                        new google.maps.Point(16, 32));
25 }
26
27 function getNameRegion(name, region) {
28     return region.length > 0 ? name + ", " + region : name;
29 }
30
31
32 function displayDirectionsMoreinfo(route, node) {
33     var total_distance = 0, total_duration = 0;
34     for (i = 0; i < route.legs.length; i++) {
35         total_distance += route.legs[i].distance.value;
36         total_duration += route.legs[i].duration.value;
37     }
38     total_distance = Math.round(total_distance / 1000.0);
39     var total_hours = parseInt(total_duration / 60.0 / 60.0);
40     var total_minutes = Math.round(total_duration / 60.0 - total_hours * 60);
41     var base_sentence = total_hours == 0 ? '{1} km, about {2} minutes'
42                                          : '{1} km, about {3} hours and {2} minutes';
43     node.innerHTML = base_sentence.replace('{1}', total_distance)
44                                   .replace('{2}', total_minutes)
45                                   .replace('{3}', total_hours);
46 }