summaryrefslogtreecommitdiff
path: root/index.html
blob: 0279d5ad637d6f91182b73c6dc191ba37d49e619 (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
<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 fenway = new google.maps.LatLng(42.345573,-71.098326);
        var mapOptions = {
          center: fenway,
          zoom: 14,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(
            document.getElementById('map_canvas'), mapOptions);
        var panoramaOptions = {
          position: fenway,
          pov: {
            heading: 34,
            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" />
  </body>
</html>