]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Added functionality to generate a logical heading between two points in a tween....
authorDavid Seifried <david.c.seifried@gmail.com>
Thu, 25 Aug 2011 19:11:10 +0000 (15:11 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Thu, 25 Aug 2011 19:11:10 +0000 (15:11 -0400)
plugins/googlemap/popcorn.googlemap.js

index f2b2bec0738b632d80c85e9fbb170fd960130a69..4d6589446eae959eaa4543ee144567d8c5019804 100755 (executable)
@@ -197,17 +197,17 @@ var googleCallback;
 
                   if( typeof options.tween === "object" ) {
 
-                    for ( var i = 0; i < rM.length; i++ ) {
+                    for ( var i = 0, m = rM.length; i < m; i++ ) {
 
                       //  Checks if this position along the tween should be displayed or not
                       if ( that.media.currentTime >= ( rM[ i ].interval * ( i + 1 ) ) / 1000 &&
                          ( that.media.currentTime <= ( rM[ i ].interval * ( i + 2 ) ) / 1000 || 
-                           that.media.currentTime >= rM[ i ].interval * ( rM.length ) / 1000 ) ) {
+                           that.media.currentTime >= rM[ i ].interval * ( m ) / 1000 ) ) {
 
                         sView3.setPosition( new google.maps.LatLng( rM[ i ].position.lat, rM[ i ].position.lng ) );
 
                         sView3.setPov({
-                          heading: rM[ i ].pov.heading || 0,
+                          heading: rM[ i ].pov.heading || google.maps.geometry.spherical.computeHeading( rM[ k ], rM[ k + 1 ] ) || 0,
                           zoom: rM[ i ].pov.zoom || 0,
                           pitch: rM[ i ].pov.pitch || 0
                         });
@@ -218,19 +218,18 @@ var googleCallback;
                     tween( rM, rM[ 0 ].interval );
                   } else {
 
-                    for ( var k = 0; k < rM.length; k++ ) {
+                    for ( var k = 0, l = rM.length; k < l; k++ ) {
 
                       if( that.media.currentTime >= (options.interval * ( k + 1 ) ) / 1000 &&
                         ( that.media.currentTime <= (options.interval * ( k + 2 ) ) / 1000 ||
-                          that.media.currentTime >= options.interval * ( rM.length ) / 1000 ) ) {
-
-                        sView2.setPosition( checkpoints[ k ] );
+                          that.media.currentTime >= options.interval * ( l ) / 1000 ) ) {
 
                         sView2.setPov({
-                          heading: options.heading || 0,
+                          heading: google.maps.geometry.spherical.computeHeading( rM[ k ], rM[ k + 1 ] ) || 0,
                           zoom: options.zoom,
                           pitch: options.pitch || 0
                         }); 
+                        sView2.setPosition( checkpoints[ k ] );
                       }
                     }
 
@@ -276,9 +275,10 @@ var googleCallback;
 
                 var showSteps = function ( directionResult, that ) {
                 
-                  //  Push new google map lat and lng values into an array from our list of lat and lng values
-                  for ( var j = 0; j < directionResult.routes[ 0 ].overview_path.length; j++ ) {
-                    checkpoints.push( new google.maps.LatLng( directionResult.routes[ 0 ].overview_path[ j ].lat(), directionResult.routes[ 0 ].overview_path[ j ].lng() ) );
+                  //  Push new google map lat and lng values into an array from our list of lat and lng values    
+                  var routes = directionResult.routes[ 0 ].overview_path;
+                  for ( var j = 0, k = routes.length; j < k; j++ ) {
+                    checkpoints.push( new google.maps.LatLng( routes[ j ].lat(), routes[ j ].lng() ) );
                   }   
                   
                   //  Check to make sure the interval exists, if not, set to a default of 1000
@@ -291,7 +291,7 @@ var googleCallback;
                 //  Same as the above to stop streetview maps from overflowing into one another
                 var sView3 = sView;
 
-                for ( var i = 0; i < options.tween.length; i++ ) {
+                for ( var i = 0, l = options.tween.length; i < l; i++ ) {
                  
                   //  Make sure interval exists, if not, set to 1000
                   options.tween[ i ].interval = options.tween[ i ].interval || 1000;