blob: 9348559c49c844776544dd27073a9fe83483aea9 (
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
|
<html>
<head>
<title>Streetview Cruising</title>
</head>
<body>
<h1>Streetview Cruising</h1>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
var map, panorama;
// what's our preferred direction
var lastheading = Math.random() * 360.0;
// this function ripped almost verbatim from the docs. including the boring-ass starting place.
function initialize() {
var viewpoint = new google.maps.LatLng(47.646157,-122.333799);
var mapOptions = {
center: viewpoint,
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(
document.getElementById('map_canvas'), mapOptions);
var panoramaOptions = {
position: viewpoint,
pov: {
heading: 180,
pitch: 10,
zoom: 1
}
};
panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'),panoramaOptions);
map.setStreetView(panorama);
setInterval(function(){navigate()},10000);
}
// pick a direction and go
function navigate() {
var links = map.getStreetView().getLinks();
var next = links[ 1 ];
var dir = panorama.getPov();
links.forEach( function(el) {
// choose direction closest to our preferred heading
// fails to account for 360 -> 0 wraparound, whatever
if ( Math.abs(el.heading - lastheading) < Math.abs(next.heading - lastheading) ) {
next = el;
}
} );
// sit up and face front like a normal passenger ... kids ...
dir.heading = next.heading;
// if we're not going the right direction enoughly, pick a new "right direction"
if (Math.abs(dir.heading - lastheading) > 45) { lastheading = Math.random() * 360.0 ; }
panorama.setPano(next.pano);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 400px; height: 300px"></div>
<div id="pano" style="position:absolute; left:410px; top: 8px; width: 800px; height: 600px;"></div>
<input type="button" onclick="javascript:navigate()" value="take a step" />
<a href="https://github.com/chronomex/streetcruise">source code</a>
</body>
</html>
|