From c1d1fd561592957bcbff96aef35ca50237914748 Mon Sep 17 00:00:00 2001 From: David Seifried Date: Wed, 18 May 2011 13:36:45 -0400 Subject: [PATCH] Fixed all merged conflicts, resulted because I didnt have the most up to date branch --- plugins/googlemap/popcorn.googlemap.html | 92 +++++++++- plugins/googlemap/popcorn.googlemap.js | 159 ++++++++++++++++-- plugins/googlemap/popcorn.googlemap.unit.html | 4 +- plugins/googlemap/popcorn.googlemap.unit.js | 41 +++-- 4 files changed, 261 insertions(+), 35 deletions(-) diff --git a/plugins/googlemap/popcorn.googlemap.html b/plugins/googlemap/popcorn.googlemap.html index 3f19e9e..d0cac64 100644 --- a/plugins/googlemap/popcorn.googlemap.html +++ b/plugins/googlemap/popcorn.googlemap.html @@ -5,7 +5,7 @@ - +

Popcorn google Map Plug-in Demo

A Google Map displaying Toronto, Ontario will appear at 0 seconds and disappear at 20 seconds.

-

A Google StreetView Map displaying Toronto, Ontario will appear at 0 seconds and disappear at 20 seconds.

+

A Google Map Streetview image of Toronto, Ontario will appear at 0 seconds and disaapear at 20 seconds

A Google Map displaying Boston will appear at 0 seconds and disappear at 30 seconds.

+

A Google Map Streetview tweening from Oakville, Ontario to York University will appear at 0 seconds and disaapear at 40 seconds

+

A Google Map Streetview tweening from 217 Fayetteville Street to East Davie Street will appear at 0 seconds and disaapear at 20 seconds - Using hardcoded lat+lng values

+

A Google Map Streetview tweening from Buffallo to Ottawa will appear at 0 seconds and disaapear at 40 seconds

+
-
+ +

Locations in this video:

Locations in this video:

Locations in this video:

+

Locations in this video:

+

Locations in this video:

+

Locations in this video:

+ diff --git a/plugins/googlemap/popcorn.googlemap.js b/plugins/googlemap/popcorn.googlemap.js index 954eea1..5d714f3 100644 --- a/plugins/googlemap/popcorn.googlemap.js +++ b/plugins/googlemap/popcorn.googlemap.js @@ -45,23 +45,36 @@ var googleCallback; * -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. + * -Location: the adress you want the map to display, must be present if lat and lng are not specified. * Note: using location requires extra loading time, also not specifying both lat/lng and location will * cause and error. + * + * Tweening works using the following specifications: + * -location is the start point when using an auto generated route + * -tween when used in this context is a string which specifies the end location for your route + * Note that both location and tween must be present when using an auto generated route, or the map will not tween + * -interval is the speed in which the tween will be executed, a reasonable time is 1000 ( time in milliseconds ) + * Heading, Zoom, and Pitch streetview values are also used in tweening with the autogenerated route + * + * -tween is an array of objects, each containing data for one frame of a tween + * -position is an object with has two paramaters, lat and lng, both which are mandatory for a tween to work + * -pov is an object which houses heading, pitch, and zoom paramters, which are all optional, if undefined, these values default to 0 + * -interval is the speed in which the tween will be executed, a reasonable time is 1000 ( time in milliseconds ) + * * @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 - } ) - * - */ + 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( options ) { var newdiv, map, @@ -125,6 +138,9 @@ var googleCallback; * options variable */ start: function(event, options){ + var that = this, + sView; + // ensure the map has been initialized in the setup function above var isMapSetup = function () { if ( map ) { @@ -164,6 +180,125 @@ var googleCallback; } } ) ); + + // Function to handle tweening using a set timeout + var tween = function ( rM, t ) { + + setTimeout( function () { + + // Checks whether this is a generated route or not + + if( typeof options.tween === "object" ){ + + for ( var i = 0; i < rM.length; 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 ) ){ + + sView3.setPosition( new google.maps.LatLng( rM[ i ].position.lat, rM[ i ].position.lng ) ); + + sView3.setPov({ + heading: rM[ i ].pov.heading || 0, + zoom: rM[ i ].pov.zoom || 0, + pitch: rM[ i ].pov.pitch || 0 + }); + + } + + } + + // Calls the tween function again at the interval set by the user + tween( rM, rM[ 0 ].interval ); + } + else{ + + for ( var k = 0; k < rM.length; 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 ] ); + + sView2.setPov({ + heading: options.heading || 0, + zoom: options.zoom, + pitch: options.pitch || 0 + }); + } + + } + + tween( checkpoints, options.interval ); + } + }, t ); + + }; + + + // Determines if we should use hardcoded values ( using options.tween ), + // or if we should use a start and end location and let google generate + // the route for us + if ( options.location && typeof options.tween === "string" ){ + + // Creating another variable to hold the streetview map for tweening, + // Doing this because if there was more then one streetview map, the tweening would sometimes appear in other maps + var sView2 = sView; + + // Create an array to store all the lat/lang values along our route + var checkpoints = []; + + // Creates a new direction service, later used to create a route + var directionsService = new google.maps.DirectionsService(); + + // Creates a new direction renderer using the current map + // This enables us to access all of the route data that is returned to us + var directionsDisplay = new google.maps.DirectionsRenderer( sView2 ); + + var request = { + origin: options.location, + destination: options.tween, + travelMode: google.maps.TravelMode.DRIVING + }; + + // Create the route using the direction service and renderer + directionsService.route( request, function( response, status ) { + + if ( status == google.maps.DirectionsStatus.OK ) { + directionsDisplay.setDirections( response ); + showSteps( response, that ); + } + + }); + + 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() ) ); + } + + // Check to make sure the interval exists, if not, set to a default of 1000 + options.interval = options.interval || 1000; + tween( checkpoints, 10); + + }; + } + else if( typeof options.tween === "object" ){ + + // 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++ ) { + + // Make sure interval exists, if not, set to 1000 + options.tween[ i ].interval = options.tween[ i ].interval || 1000; + tween( options.tween, 10 ); + } + + } } } else { setTimeout( function () { diff --git a/plugins/googlemap/popcorn.googlemap.unit.html b/plugins/googlemap/popcorn.googlemap.unit.html index 476d0bf..e37ab4f 100644 --- a/plugins/googlemap/popcorn.googlemap.unit.html +++ b/plugins/googlemap/popcorn.googlemap.unit.html @@ -39,6 +39,8 @@
-
+
+
+ diff --git a/plugins/googlemap/popcorn.googlemap.unit.js b/plugins/googlemap/popcorn.googlemap.unit.js index 515bce6..ad5a5a2 100644 --- a/plugins/googlemap/popcorn.googlemap.unit.js +++ b/plugins/googlemap/popcorn.googlemap.unit.js @@ -24,6 +24,9 @@ test("Popcorn Google Map Plugin", function () { ok ( document.getElementById('map2').innerHTML === "", "initially, there is nothing inside the map2" ); plus(); + ok ( document.getElementById('map3').innerHTML === "", "initially, there is nothing inside the map3" ); + plus(); + popped.googlemap({ start: 0, // seconds end: 5, // seconds @@ -34,23 +37,26 @@ test("Popcorn Google Map Plugin", function () { zoom: 10 }) .googlemap({ - start: 0, // seconds - end: 5, // seconds - type: 'SATELLITE', - target: 'map2', - location:'boston', - zoom: 15 - }) - .volume(0); - - popped.googlemap({ start: 0, // seconds end: 10, // seconds type: 'SATELLITE', target: 'map2', location:'toronto', zoom: 15 - }); + }); + var mapz = popped.googlemap({ + start: 0, // seconds + end: 15, // seconds + type: "STREETVIEW", + target: "map3", + location: "6th Line, Oakville, Ontario", + zoom: "1", + heading: "180", + pitch: "1", + interval: 1000, + tween: "York university" + }) + .volume(0); setupId = popped.getLastTrackEventId(); @@ -72,16 +78,23 @@ test("Popcorn Google Map Plugin", function () { plus(); }); - popped.exec( 6, function() { + popped.exec( 4, function() { + equals (document.getElementById('actualmap3').offsetParent.id, "map3", "Tweening map is inside the 'map3' div" ); + plus(); + }); + + popped.exec( 20, function() { ok (document.getElementById('actualmap2').style.display === "none" && - document.getElementById('actualmap1').style.display === "none", "Both maps are no longer visible" ); + document.getElementById('actualmap1').style.display === "none" && + document.getElementById('actualmap3').style.display === "none", "All maps are no longer visible" ); plus(); popped.pause().removeTrackEvent( setupId ); - ok( !document.getElementById('actualmap3'), "removed map was properly destroyed" ); + ok( !document.getElementById('actualmap4'), "removed map was properly destroyed" ); plus(); }); popped.play(); }); + -- 2.43.0