提交 | 用户 | 时间
|
58d006
|
1 |
<!DOCTYPE html> |
A |
2 |
<html> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<title>GMaps.js — Elevation Routes</title> |
|
6 |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> |
|
7 |
<script type="text/javascript" src="http://www.google.com/jsapi"></script> |
|
8 |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script> |
|
9 |
<script type="text/javascript" src="../gmaps.js"></script> |
|
10 |
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" /> |
|
11 |
<link rel="stylesheet" type="text/css" href="examples.css" /> |
|
12 |
<script type="text/javascript"> |
|
13 |
var map; |
|
14 |
var mousemarker = null; |
|
15 |
|
|
16 |
// Load the Visualization API and the piechart package. |
|
17 |
google.load("visualization", "1", {packages: ["columnchart"]}); |
|
18 |
|
|
19 |
$(document).ready(function(){ |
|
20 |
map = new GMaps({ |
|
21 |
el: '#map', |
|
22 |
lat: -12.043333, |
|
23 |
lng: -77.028333, |
|
24 |
zoom: 12 |
|
25 |
}); |
|
26 |
|
|
27 |
//load google visualization chart |
|
28 |
chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); |
|
29 |
|
|
30 |
var polygone = map.drawRoute({ |
|
31 |
origin: [-12.044012922866312, -77.02470665341184], |
|
32 |
destination: [-12.090814532191756, -77.02271108990476], |
|
33 |
travelMode: 'walking', |
|
34 |
strokeColor: '#131540', |
|
35 |
strokeOpacity: 0.6, |
|
36 |
strokeWeight: 6, |
|
37 |
callback : function(polygones){ |
|
38 |
|
|
39 |
//elevation for the path |
|
40 |
map.getElevations({ |
|
41 |
locations : polygones.overview_path, |
|
42 |
path: true, |
|
43 |
callback : function (result, status){ |
|
44 |
if (status == google.maps.ElevationStatus.OK) { |
|
45 |
|
|
46 |
var elevations = result; |
|
47 |
|
|
48 |
//set the google visualization |
|
49 |
var data = new google.visualization.DataTable(); |
|
50 |
data.addColumn('string', 'Sample'); |
|
51 |
data.addColumn('number', 'Elevation'); |
|
52 |
for (var i = 0; i < result.length; i++) { |
|
53 |
data.addRow(['', elevations[i].elevation]); |
|
54 |
} |
|
55 |
|
|
56 |
//add to the dom |
|
57 |
document.getElementById('chart_div').style.display = 'block'; |
|
58 |
chart.draw(data, { |
|
59 |
width: 340, |
|
60 |
height: 200, |
|
61 |
legend: 'none', |
|
62 |
titleY: 'Elevation (m)', |
|
63 |
focusBorderColor: '#00ff00' |
|
64 |
}); |
|
65 |
|
|
66 |
//add mouseover |
|
67 |
google.visualization.events.addListener(chart, 'onmouseover', function(e) { |
|
68 |
if (mousemarker == null) { |
|
69 |
mousemarker = map.addMarker({ |
|
70 |
lat: elevations[e.row].location.lat(), |
|
71 |
lng: elevations[e.row].location.lng() |
|
72 |
}); |
|
73 |
} else { |
|
74 |
mousemarker.setPosition(elevations[e.row].location); |
|
75 |
} |
|
76 |
}); |
|
77 |
} |
|
78 |
} |
|
79 |
}); |
|
80 |
} |
|
81 |
}); |
|
82 |
}); |
|
83 |
</script> |
|
84 |
</head> |
|
85 |
<body> |
|
86 |
<h1>GMaps.js — Elevation Routes</h1> |
|
87 |
<div class="row"> |
|
88 |
<div class="span11"> |
|
89 |
<div id="map"></div> |
|
90 |
</div> |
|
91 |
<div class="span6"> |
|
92 |
<p>With GMaps.js you can calculate the elevation for a route like this:</p> |
|
93 |
<pre>map.getElevations({ |
|
94 |
locations : [[-12.040397656836609,-77.03373871559225], [-12.040248585302038,-77.03993927003302], [-12.050047116528843,-77.02448169303511], [-12.044804866577001,-77.02154422636042]], |
|
95 |
path: true, |
|
96 |
callback : function (result, status){ |
|
97 |
if (status == google.maps.ElevationStatus.OK) { |
|
98 |
console.log(result, status); |
|
99 |
} |
|
100 |
} |
|
101 |
});</pre> |
|
102 |
<div id="chart_div"></div> |
|
103 |
</div> |
|
104 |
</div> |
|
105 |
</body> |
|
106 |
</html> |