]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Updated version of bug70
authordseif <david.c.seifried@gmail.com>
Mon, 14 Feb 2011 15:23:22 +0000 (07:23 -0800)
committerAnna Sobiepanek <annaopensource@gmail.com>
Mon, 14 Feb 2011 21:42:26 +0000 (16:42 -0500)
plugins/googlemap/popcorn.googlemap.html
plugins/googlemap/popcorn.googlemap.js

index feb92d4167b1655bf8ed17e9d576bb5761ccf03f..48b6587a651fbcb4dcd67a8624d4e609bb7b4782 100644 (file)
@@ -9,22 +9,33 @@
     document.addEventListener('DOMContentLoaded', function () {
       var p = Popcorn('#video')
       .volume(0)
-      .play() 
+      .play()
       .googlemap({
         start: 0, // seconds
         end: 20, // seconds
-        type: 'ROADMAP',
-        target: 'map',
+        type: "ROADMAP",
+        target: "map",
         lat: 43.665429,
         lng: -79.403323,
         zoom: "10"
       } )
+      .googlemap({
+        start: 0, // seconds
+        end: 20, // seconds
+        type: "STREETVIEW",
+        target: "map1",
+        lat: 43.665429,
+        lng: -79.403323,
+        zoom: "1",
+        heading: "0",
+        pitch: "1"
+      } )
       .googlemap({
         start: 0, // seconds
         end: 30, // seconds
-        type: 'ROADMAP',
-        target: 'map2',
-        location:'boston',
+        type: "ROADMAP",
+        target: "map2",
+        location:"boston",
         zoom: 15
       } );
     }, false);
 <body>
   <h1 id="qunit-header">Popcorn google Map Plug-in Demo</h1>
   <p> A Google Map displaying Toronto, Ontario will appear at 0 seconds and disappear at 20 seconds.</p>
+  <p> A Google StreetView Map displaying Toronto, Ontario will appear at 0 seconds and disappear at 20 seconds.</p>
   <p> A Google Map displaying Boston will appear at 0 seconds and disappear at 30 seconds.</p>
   <div>
-    <video id='video' 
-      controls 
+    <video id='video'
+      controls
       width= '250px'
-      poster="../../test/poster.png"> 
+      poster="../../test/poster.png">
 
       <source id='mp4'
         src="../../test/trailer.mp4"
-        type='video/mp4; codecs="avc1, mp4a"'> 
+        type='video/mp4; codecs="avc1, mp4a"'>
 
       <source id='ogv'
         src="../../test/trailer.ogv"
-        type='video/ogg; codecs="theora, vorbis"'> 
+        type='video/ogg; codecs="theora, vorbis"'>
 
-      <p>Your user agent does not support the HTML5 Video element.</p> 
+      <p>Your user agent does not support the HTML5 Video element.</p>
 
-    </video> 
+    </video>
   </div>
-  <div style="width:700px">
+  <div style="width:1000px">
     <div id="map" style="position:relative;float:left;width:300px;height:400px"><p>Locations in this video:</p></div>
+    <div id="map1" style="position:relative;float:left;width:300px;height:400px"><p>Locations in this video:</p></div>
     <div id="map2" style="position:relative;float:left;width:300px;height:400px"><p>Locations in this video:</p></div>
   </div>
 </body>
-</html>
+</html>
\ No newline at end of file
index 26ff8664a34e3a8392d75519009638b4a6a9e31b..84cf031ead2a53a134bb86ae2993616622b3cf7b 100644 (file)
@@ -3,32 +3,34 @@ var googleCallback;
 (function (Popcorn) {
   
   /**
-   * googlemap popcorn plug-in 
+   * googlemap popcorn plug-in
    * Adds a map to the target div centered on the location specified by the user
    * Options parameter will need a start, end, target, type, zoom, lat and lng, and location
    * -Start is the time that you want this plug-in to execute
-   * -End is the time that you want this plug-in to stop executing 
+   * -End is the time that you want this plug-in to stop executing
    * -Target is the id of the DOM element that you want the map to appear in. This element must be in the DOM
-   * -Type [optional] either: HYBRID (default), ROADMAP, SATELLITE, TERRAIN 
+   * -Type [optional] either: HYBRID (default), ROADMAP, SATELLITE, TERRAIN, STREETVIEW 
    * -Zoom [optional] defaults to 0
+   * -Heading [optional] STREETVIEW orientation of camera in degrees relative to true north (0 north, 90 true east, ect)
+   * -Pitch [optional] STREETVIEW vertical orientation of the camera (between 1 and 3 is recommended)
    * -Lat and Lng: the coordinates of the map must be present if location is not specified.
    * -Location: the adress you want the map to display, bust be present if lat and log are not specified.
-   *  Note: using location requires extra loading time, also not specifying both lat/lng and location will
-   * cause and error. 
+   * Note: using location requires extra loading time, also not specifying both lat/lng and location will
+   * cause and error.
    * @param {Object} options
-   * 
-   * Example:
-     var p = Popcorn('#video')
-        .googlemap({
-          start: 5, // seconds
-          end: 15, // seconds
-          type: 'ROADMAP',
-          target: 'map',
-          lat: 43.665429,
-          lng: -79.403323
-        } )
    *
-   */
+   * Example:
+    var p = Popcorn("#video")
+      .googlemap({
+       start: 5, // seconds
+       end: 15, // seconds
+       type: "ROADMAP",
+       target: "map",
+       lat: 43.665429,
+       lng: -79.403323
+    } )
+  *
+  */
   Popcorn.plugin( "googlemap" , (function(){
       
     var newdiv, i = 1, _mapFired = false, _mapLoaded = false;
@@ -42,23 +44,25 @@ var googleCallback;
           website: "annasob.wordpress.com"
         },
         options:{
-          start    : {elem:'input', type:'text', label:'In'},
-          end      : {elem:'input', type:'text', label:'Out'},
-          target   : 'map-container',
-          type     : {elem:'select', options:['ROADMAP','SATELLITE', 'HYBRID', 'TERRAIN'], label:'Type'},
-          zoom     : {elem:'input', type:'text', label:'Zoom'},
-          lat      : {elem:'input', type:'text', label:'Lat'},
-          lng     : {elem:'input', type:'text', label:'Lng'},
-          location : {elem:'input', type:'text', label:'Location'}
+          start    : {elem:"input", type:"text", label:"In"},
+          end      : {elem:"input", type:"text", label:"Out"},
+          target   : "map-container",
+          type     : {elem:"select", options:["ROADMAP","SATELLITE", "STREETVIEW", "HYBRID", "TERRAIN"], label:"Type"},
+          zoom     : {elem:"input", type:"text", label:"Zoom"},
+          lat      : {elem:"input", type:"text", label:"Lat"},
+          lng      : {elem:"input", type:"text", label:"Lng"},
+          location : {elem:"input", type:"text", label:"Location"},
+          heading  : {elem:"input", type:"text", label:"Heading"},
+          pitch    : {elem:"input", type:"text", label:"Pitch"}
         }
       },
       _setup : function( options ) {
-        // create a new div this way anything in the target div 
+        // create a new div this way anything in the target div
         // this is later passed on to the maps api
-        options._newdiv               = document.createElement('div');
-        options._newdiv.id            = "actualmap"+i;
-        options._newdiv.style.width   = "100%";
-        options._newdiv.style.height  = "100%";
+        options._newdiv = document.createElement("div");
+        options._newdiv.id = "actualmap"+i;
+        options._newdiv.style.width = "100%";
+        options._newdiv.style.height = "100%";
         i++;
         if (document.getElementById(options.target)) {
           document.getElementById(options.target).appendChild(options._newdiv);
@@ -68,16 +72,16 @@ var googleCallback;
         if (!_mapFired) {
           _mapFired = true;
           var loadScriptTime = (new Date).getTime();
-          var head = document.getElementsByTagName('head')[0];
-          var script = document.createElement('script');
+          var head = document.getElementsByTagName("head")[0];
+          var script = document.createElement("script");
          
           script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=googleCallback";
           script.type = "text/javascript";
-          head.insertBefore( script, head.firstChild ); 
+          head.insertBefore( script, head.firstChild );
         }
         // callback function fires when the script is run
         googleCallback = function() {
-          _mapLoaded    = true;
+          _mapLoaded = true;
         };
         // If there is no lat/lng, and there is location, geocode the location
         // you can only do this once google.maps exists
@@ -90,19 +94,19 @@ var googleCallback;
             if (options.location) {
               var geocoder = new google.maps.Geocoder();
               // calls an anonymous function called on separate thread
-              geocoder.geocode({ 'address': options.location}, function(results, status) {
+              geocoder.geocode({ "address": options.location}, function(results, status) {
                 if (status === google.maps.GeocoderStatus.OK) {
-                  options.lat  = results[0].geometry.location.lat();
-                  options.lng = results[0].geometry.location.lng(); 
+                  options.lat = results[0].geometry.location.lat();
+                  options.lng = results[0].geometry.location.lng();
                   options._location = new google.maps.LatLng(options.lat, options.lng);
-                  options._map = new google.maps.Map(options._newdiv, {mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID }); 
-                  options._map.getDiv().style.display = 'none';
-                } 
+                  options._map = new google.maps.Map(options._newdiv, {mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID });
+                  options._map.getDiv().style.display = "none";
+                }
               });
             } else {
               options._location = new google.maps.LatLng(options.lat, options.lng);
-              options._map = new google.maps.Map(options._newdiv, {mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID });  
-              options._map.getDiv().style.display = 'none';
+              options._map = new google.maps.Map(options._newdiv, {mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID });
+              options._map.getDiv().style.display = "none";
             }
           }
         };
@@ -110,20 +114,20 @@ var googleCallback;
         
       },
       /**
-       * @member webpage 
-       * The start function will be executed when the currentTime 
-       * of the video  reaches the start time provided by the 
+       * @member webpage
+       * The start function will be executed when the currentTime
+       * of the video reaches the start time provided by the
        * options variable
        */
       start: function(event, options){
         // dont do anything if the information didn't come back from google map
-        var isReady = function () {    
+        var isReady = function () {
           if (!options._map) {
             setTimeout(function () {
               isReady();
             }, 13);
           } else {
-            options._map.getDiv().style.display = 'block';
+            options._map.getDiv().style.display = "block";
             // reset the location and zoom just in case the user plaid with the map
             options._map.setCenter(options._location);
 
@@ -131,26 +135,51 @@ var googleCallback;
             if ( options.zoom && typeof options.zoom !== "number" ) {
               options.zoom = +options.zoom;
             }
+            
             options.zoom = options.zoom || 0; // default to 0
             options._map.setZoom( options.zoom );
+            
+            //Make sure heading is a number
+            if ( options.heading && typeof options.heading !== "number" ) {
+              options.heading = +options.heading;
+            }
+            //Make sure pitch is a number
+            if ( options.pitch && typeof options.pitch !== "number" ) {
+              options.pitch = +options.pitch;
+            }
 
             google.maps.event.trigger(options._map, 'resize');
+            
+            if ( options.type === "STREETVIEW" ) {
+              // Switch this map into streeview mode
+              options._map.setStreetView( 
+                // Pass a new StreetViewPanorama instance into our map
+                new google.maps.StreetViewPanorama( options._newdiv, {
+                  position: options._location,
+                  pov: {
+                    heading: options.heading = options.heading || 0,
+                    pitch: options.pitch = options.pitch || 0,
+                    zoom: options.zoom
+                  }    
+                })
+              );
+            }
           }
         };
         
         isReady();
       },
       /**
-       * @member webpage 
-       * The end function will be executed when the currentTime 
-       * of the video  reaches the end time provided by the 
+       * @member webpage
+       * The end function will be executed when the currentTime
+       * of the video reaches the end time provided by the
        * options variable
        */
       end: function(event, options){
-        // if the map exists hide it do not delete the map just in 
+        // if the map exists hide it do not delete the map just in
         // case the user seeks back to time b/w start and end
         if (options._map) {
-          options._map.getDiv().style.display = 'none';          
+          options._map.getDiv().style.display = "none";
         }
       }