From: David Seifried Date: Sun, 15 May 2011 21:15:22 +0000 (-0400) Subject: Added tween stuff X-Git-Tag: v0.6~3^2~1^2~10 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=928e35edab2db1d04d78e78f6cc8b9d6e5b54739;p=popcorn-js.git Added tween stuff --- diff --git a/plugins/googlemap/popcorn.googlemap.js b/plugins/googlemap/popcorn.googlemap.js index b5d2a1d..44be615 100644 --- a/plugins/googlemap/popcorn.googlemap.js +++ b/plugins/googlemap/popcorn.googlemap.js @@ -1,333 +1,349 @@ -// PLUGIN: Google Maps -var googleCallback; -(function (Popcorn) { - - var i = 1, - _mapFired = false, - _mapLoaded = false, - geocoder, loadMaps; - //google api callback - googleCallback = function (data) { - // ensure all of the maps functions needed are loaded - // before setting _maploaded to true - if (typeof google !== "undefined" && google.maps && google.maps.Geocoder && google.maps.LatLng) { - geocoder = new google.maps.Geocoder(); - _mapLoaded = true; - } else { - setTimeout(function () { - googleCallback(data); - }, 1); - } - }; - // function that loads the google api - loadMaps = function () { - // for some reason the Google Map API adds content to the body - if (document.body) { - _mapFired = true; - Popcorn.getScript("http://maps.google.com/maps/api/js?sensor=false&callback=googleCallback"); - } else { - setTimeout(function () { - loadMaps(); - }, 1); - } - }; - - /** - * 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 - * -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, 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. - * @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 - } ) - * - */ - Popcorn.plugin("googlemap", function (options) { - var newdiv, map, location; - - // if this is the firest time running the plugins - // call the function that gets the sctipt - if (!_mapFired) { - loadMaps(); - } - - // create a new div this way anything in the target div is left intact - // this is later passed on to the maps api - newdiv = document.createElement("div"); - newdiv.id = "actualmap" + i; - newdiv.style.width = "100%"; - newdiv.style.height = "100%"; - i++; - - // ensure the target container the user chose exists - if (document.getElementById(options.target)) { - document.getElementById(options.target).appendChild(newdiv); - } else { - throw ("map target container doesn't exist"); - } - - // ensure that google maps and its functions are loaded - // before setting up the map parameters - var isMapReady = function () { - if (_mapLoaded) { - if (options.location) { - // calls an anonymous google function called on separate thread - 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(); - location = new google.maps.LatLng(options.lat, options.lng); - map = new google.maps.Map(newdiv, { - mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID - }); - map.getDiv().style.display = "none"; - } - }); - } else { - location = new google.maps.LatLng(options.lat, options.lng); - map = new google.maps.Map(newdiv, { - mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID - }); - map.getDiv().style.display = "none"; - } - } else { - setTimeout(function () { - isMapReady(); - }, 5); - } - }; - - isMapReady(); - - return { - /** - * @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) { - // ensure the map has been initialized in the setup function above - var isMapSetup = function () { - if (map) { - map.getDiv().style.display = "block"; - // reset the location and zoom just in case the user plaid with the map - google.maps.event.trigger(map, 'resize'); - map.setCenter(location); - - // make sure options.zoom is a number - if (options.zoom && typeof options.zoom !== "number") { - options.zoom = +options.zoom; - } - - options.zoom = options.zoom || 0; // default to 0 - 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; - } - - - - if (options.type === "STREETVIEW") { - // Switch this map into streeview mode - map.setStreetView( - // Pass a new StreetViewPanorama instance into our map - sView = new google.maps.StreetViewPanorama(newdiv, { - position: location, - pov: { - heading: options.heading = options.heading || 0, - pitch: options.pitch = options.pitch || 0, - zoom: options.zoom - } - }) - - - ); - - - - - var tween = function (rM, t) { - - setTimeout(function () { - console.log(rM); - var p = new google.maps.LatLng(rM.position.lat, rM.position.lng); - sView.setPosition(p); - sView.setPov({ - heading: rM.pov.heading, - zoom: 1, - pitch: 1 - }); - }, t); - - } - var tmr = 0; - - if ( !!options.startLoc && !!options.endLoc ){ - - // Create an array to store all the lat/lang values along our route - var checkpoints = []; - - // Helper function to split up each portion on a route into smaller chunks, creating a smoother and more fluent tween - // Also pushes the data into the checkpoints array - var getSteps = function (start, end){ - var latDiff = (end.lat() - start.lat()) / 100, - lngDiff = (end.lng() - start.lng()) / 100, - lat = start.lat(), - lng = start.lng(); - - for(var i = ; i < steps; i++){ - lat += latDiff; - lng += lngDiff; - checkpoints.push(new google.maps.LatLng(lat, lng)); - } - checkpoints.push(new google.maps.LatLng(end.lat(), end.lng())); - } - - var directionsService = new google.maps.DirectionsService(); - - var directionsDisplay = new google.maps.DirectionsRenderer(panorama); - - var request = { - origin: options.startLoc, - destination:options.endLoc, - travelMode: google.maps.TravelMode.DRIVING - }; - - directionsService.route(request, function(response, status) { - if (status == google.maps.DirectionsStatus.OK) { - directionsDisplay.setDirections(response); - showSteps(response); - } - }); - - function showSteps(directionResult) { - for (var j = 0; j < directionResult.routes[0].overview_path.length; j++) { - getSteps(directionResult.routes[0].overview_path[j], directionResult.routes[0].overview_path[j+1]); - } - for ( i = 0; i < checkpoints.length; i++ ) { - tmr = tmr + options.interval; - tween( checkpoints[i], tmr ); - } - } - } - else if ( options.tween.length > 0 ){ - for ( i = 0; i < options.tween.length; i++ ) { - tmr = tmr + options.tween[i].interval; - tween( options.tween[i], tmr ); - } - } - - } - } else { - setTimeout(function () { - isMapSetup(); - }, 13); - } - }; - - isMapSetup(); - }, - /** - * @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 - // case the user seeks back to time b/w start and end - if (map) { - map.getDiv().style.display = "none"; - } - }, - _teardown: function (options) { - // the map must be manually removed - document.getElementById(options.target).removeChild(newdiv); - newdiv = map = location = null; - } - }; - }, { - about: { - name: "Popcorn Google Map Plugin", - version: "0.1", - author: "@annasob", - 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", "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" - } - } - }); -})(Popcorn); +// PLUGIN: Google Maps +var googleCallback; +(function (Popcorn) { + + var i = 1, + _mapFired = false, + _mapLoaded = false, + geocoder, loadMaps; + //google api callback + googleCallback = function (data) { + // ensure all of the maps functions needed are loaded + // before setting _maploaded to true + if (typeof google !== "undefined" && google.maps && google.maps.Geocoder && google.maps.LatLng) { + geocoder = new google.maps.Geocoder(); + _mapLoaded = true; + } else { + setTimeout(function () { + googleCallback(data); + }, 1); + } + }; + // function that loads the google api + loadMaps = function () { + // for some reason the Google Map API adds content to the body + if (document.body) { + _mapFired = true; + Popcorn.getScript("http://maps.google.com/maps/api/js?sensor=false&callback=googleCallback"); + } else { + setTimeout(function () { + loadMaps(); + }, 1); + } + }; + + /** + * 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 + * -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, 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. + * @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 + } ) + * + */ + Popcorn.plugin("googlemap", function (options) { + var newdiv, map, location; + + // if this is the firest time running the plugins + // call the function that gets the sctipt + if (!_mapFired) { + loadMaps(); + } + + // create a new div this way anything in the target div is left intact + // this is later passed on to the maps api + newdiv = document.createElement("div"); + newdiv.id = "actualmap" + i; + newdiv.style.width = "100%"; + newdiv.style.height = "100%"; + i++; + + // ensure the target container the user chose exists + if (document.getElementById(options.target)) { + document.getElementById(options.target).appendChild(newdiv); + } else { + throw ("map target container doesn't exist"); + } + + // ensure that google maps and its functions are loaded + // before setting up the map parameters + var isMapReady = function () { + if (_mapLoaded) { + if (options.location) { + // calls an anonymous google function called on separate thread + 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(); + location = new google.maps.LatLng(options.lat, options.lng); + map = new google.maps.Map(newdiv, { + mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID + }); + map.getDiv().style.display = "none"; + } + }); + } else { + location = new google.maps.LatLng(options.lat, options.lng); + map = new google.maps.Map(newdiv, { + mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID + }); + map.getDiv().style.display = "none"; + } + } else { + setTimeout(function () { + isMapReady(); + }, 5); + } + }; + + isMapReady(); + + return { + /** + * @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) { + // ensure the map has been initialized in the setup function above + var isMapSetup = function () { + if (map) { + map.getDiv().style.display = "block"; + // reset the location and zoom just in case the user plaid with the map + google.maps.event.trigger(map, 'resize'); + map.setCenter(location); + + // make sure options.zoom is a number + if (options.zoom && typeof options.zoom !== "number") { + options.zoom = +options.zoom; + } + + options.zoom = options.zoom || 0; // default to 0 + 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; + } + + + + if (options.type === "STREETVIEW") { + // Switch this map into streeview mode + map.setStreetView( + // Pass a new StreetViewPanorama instance into our map + sView = new google.maps.StreetViewPanorama(newdiv, { + position: location, + pov: { + heading: options.heading = options.heading || 0, + pitch: options.pitch = options.pitch || 0, + zoom: options.zoom + } + }) + + + ); + + + + + var tween = function (rM, t) { + + setTimeout(function () { + console.log(rM); + sView.setPosition(rM); + + }, t); + + } + var tmr = 0; + + if ( !!options.startLoc && !!options.endLoc ){ + + // Create an array to store all the lat/lang values along our route + var checkpoints = []; + + // Helper function to split up each portion on a route into smaller chunks, creating a smoother and more fluent tween + // Also pushes the data into the checkpoints array + var getSteps = function (start, end){ + var latDiff = (end.lat() - start.lat()) / 100, + lngDiff = (end.lng() - start.lng()) / 100, + lat = start.lat(), + lng = start.lng(); + + for(var i = 0; i < 99; i++){ + lat += latDiff; + lng += lngDiff; + checkpoints.push(new google.maps.LatLng(lat, lng)); + } + checkpoints.push(new google.maps.LatLng(end.lat(), end.lng())); + } + + var directionsService = new google.maps.DirectionsService(); + + var directionsDisplay = new google.maps.DirectionsRenderer(sView); + + var request = { + origin: options.startLoc, + destination:options.endLoc, + travelMode: google.maps.TravelMode.DRIVING + }; + + directionsService.route(request, function(response, status) { + if (status == google.maps.DirectionsStatus.OK) { + directionsDisplay.setDirections(response); + showSteps(response); + } + }); + + function showSteps(directionResult) { + for (var j = 0; j < directionResult.routes[0].overview_path.length-1; j++) { + getSteps(directionResult.routes[0].overview_path[j], directionResult.routes[0].overview_path[j+1]); + } + for ( var i = 0; i < checkpoints.length; i++ ) { + tmr = tmr + options.interval; + tween( checkpoints[i], tmr ); + } + + + interval = window.setInterval(function(){ + i++; + // use trig to adjust the heading towards destination + if ( i > 0 ) { + //console.log(k); + var radians = Math.atan2( ( checkpoints[i].lng() - checkpoints[i-1].lng() ), + ( checkpoints[i].lat() - checkpoints[i-1].lat() ) ); + var degrees = Math.round( ( radians / (Math.PI/180) ) ); + var pov = panorama.getPov(); + pov.heading = degrees; + sView.setPov(pov); + } + sView.setPosition(checkpoints[i]); + //console.log(checkpoints.length); + if(i == checkpoints.length-1){ + console.log("DONE"); + window.clearInterval(interval); + } + }, options.interval); + } + } + else if ( options.tween.length > 0 ){ + for ( i = 0; i < options.tween.length; i++ ) { + tmr = tmr + options.tween[i].interval; + tween( options.tween[i], tmr ); + } + } + + } + } else { + setTimeout(function () { + isMapSetup(); + }, 13); + } + }; + + isMapSetup(); + }, + /** + * @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 + // case the user seeks back to time b/w start and end + if (map) { + map.getDiv().style.display = "none"; + } + }, + _teardown: function (options) { + // the map must be manually removed + document.getElementById(options.target).removeChild(newdiv); + newdiv = map = location = null; + } + }; + }, { + about: { + name: "Popcorn Google Map Plugin", + version: "0.1", + author: "@annasob", + 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", "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" + } + } + }); +})(Popcorn); diff --git a/plugins/googlemap/tween.html b/plugins/googlemap/tween.html index 57b5328..d5b04d0 100644 --- a/plugins/googlemap/tween.html +++ b/plugins/googlemap/tween.html @@ -1,100 +1,61 @@ - - - - Popcorn google Map Plug-in Demo - - - - - - - -

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 displaying Boston will appear at 0 seconds and disappear at 30 seconds.

-
- - -
- -
-

Locations in this video:

-

Locations in this video:

-

Locations in this video:

-
- - + + + + Popcorn google Map Plug-in Demo + + + + + + + +

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 displaying Boston will appear at 0 seconds and disappear at 30 seconds.

+
+ + +
+ +
+

Locations in this video:

+

Locations in this video:

+

Locations in this video:

+
+ +