From: dseif Date: Mon, 14 Feb 2011 15:23:22 +0000 (-0800) Subject: Updated version of bug70 X-Git-Tag: v0.4~53 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=6b1050be8b9c233dce22b3f78fa4e7a3f15f3d48;p=popcorn-js.git Updated version of bug70 --- diff --git a/plugins/googlemap/popcorn.googlemap.html b/plugins/googlemap/popcorn.googlemap.html index feb92d4..48b6587 100644 --- a/plugins/googlemap/popcorn.googlemap.html +++ b/plugins/googlemap/popcorn.googlemap.html @@ -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); @@ -33,28 +44,30 @@

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:

- + \ No newline at end of file diff --git a/plugins/googlemap/popcorn.googlemap.js b/plugins/googlemap/popcorn.googlemap.js index 26ff866..84cf031 100644 --- a/plugins/googlemap/popcorn.googlemap.js +++ b/plugins/googlemap/popcorn.googlemap.js @@ -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"; } }