]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
finished map with geolocation and testing [#171 state:peer-review-requested]
authorAnna Sobiepanek <annaopensource@gmail.com>
Wed, 22 Dec 2010 19:30:20 +0000 (14:30 -0500)
committerAnna Sobiepanek <annaopensource@gmail.com>
Wed, 22 Dec 2010 19:30:20 +0000 (14:30 -0500)
plugins/googleMap/popcorn.googleMap.html
plugins/googleMap/popcorn.googleMap.js
plugins/googleMap/popcorn.googleMap.unit.html
plugins/googleMap/popcorn.googleMap.unit.js
plugins/googleMap/popcorngoogleMap.unit.js [deleted file]

index 1669ee9c41c18174313e706543d8b69227041f28..e0bd0fb69bec4651a06b501ba134f5acdbbd1950 100644 (file)
@@ -12,7 +12,7 @@
       .play() 
       .googleMap({
         start: 0, // seconds
-        end: 10, // seconds
+        end: 20, // seconds
         type: 'ROADMAP',
         target: 'map',
         lat: 43.665429,
@@ -20,9 +20,9 @@
         zoom: 10
       } )
       .googleMap({
-        start: 15, // seconds
-        end: 50, // seconds
-        type: 'SATELLITE',
+        start: 0, // seconds
+        end: 30, // seconds
+        type: 'ROADMAP',
         target: 'map2',
         location:'boston',
         zoom: 15
@@ -32,8 +32,8 @@
 </head>
 <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 10 seconds.</p>
-  <p> A Google Map  displaying Sao Paulo will appear at 15 seconds and disappear at 50 seconds.</p>
+  <p> A Google 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 
index bbc37857c9d9d9adc6adfb26ab028eda7516f3f7..e36c8c3a759ee1a0150f0cfc93785afcc23bf985 100644 (file)
@@ -1,22 +1,20 @@
 // PLUGIN: Google Maps
-
+var googleCallback;
 (function (Popcorn) {
   
   /**
    * 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, lat and long, zoom
+   * 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 long, 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
-   * attached to, this target element must exist on the DOM
+   * -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 
    * -Zoom [optional] defaults to 0
-   * -Lat and Long: the coordinates of the map
-   * 
-   * Note: 
+   * -Lat and Long: 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/long and location will
+   * cause and error. 
    * @param {Object} options
    * 
    * Example:
         } )
    *
    */
-  // 
-  window.google = window.google || {};
-  google.maps = google.maps || {};
-
-  (function() {
-    var modules = google.maps.modules = {};
-
-    google.maps.__gjsload__ = function(name, text) {
-      modules[name] = text;
-    };
-
-    google.maps.Load = function(apiLoad) {
-      delete google.maps.Load;
-      apiLoad([null,[[["http://mt0.google.com/vt?lyrs=m@140\u0026src=api\u0026hl=en-US\u0026","http://mt1.google.com/vt?lyrs=m@140\u0026src=api\u0026hl=en-US\u0026"]],[["http://khm0.google.com/kh?v=75\u0026hl=en-US\u0026","http://khm1.google.com/kh?v=75\u0026hl=en-US\u0026"],null,null,null,1],[["http://mt0.google.com/vt?lyrs=h@140\u0026src=api\u0026hl=en-US\u0026","http://mt1.google.com/vt?lyrs=h@140\u0026src=api\u0026hl=en-US\u0026"],null,null,"imgtp=png32\u0026"],[["http://mt0.google.com/vt?lyrs=t@126,r@140\u0026src=api\u0026hl=en-US\u0026","http://mt1.google.com/vt?lyrs=t@126,r@140\u0026src=api\u0026hl=en-US\u0026"]],null,[[null,0,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=en-US\u0026"]],[null,0,8,9,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1293600000]],[[354690000,1293600000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=en-US\u0026"]],[null,0,10,19,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=en-US\u0026"]],[null,3,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]],[null,3,8,9,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1293600000]],[[354690000,1293600000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]],[null,3,10,null,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]]],[["http://cbk0.google.com/cbk?","http://cbk1.google.com/cbk?"]],[["http://khmdb0.google.com/kh?v=33\u0026hl=en-US\u0026","http://khmdb1.google.com/kh?v=33\u0026hl=en-US\u0026"]],[["http://mt0.google.com/mapslt?hl=en-US\u0026","http://mt1.google.com/mapslt?hl=en-US\u0026"]],[["http://mt0.google.com/mapslt/ft?hl=en-US\u0026","http://mt1.google.com/mapslt/ft?hl=en-US\u0026"]]],["en-US","US",null,0,null,"http://maps.google.com","http://maps.gstatic.com/intl/en_us/mapfiles/","http://gg.google.com","https://maps.googleapis.com","http://maps.googleapis.com"],["http://maps.gstatic.com/intl/en_us/mapfiles/api-3/3/3a","3.3.3a"],[3023581072],1,null,null,null,null,0,""], loadScriptTime);
-    };
-    var loadScriptTime = (new Date).getTime();
-    var head = document.getElementsByTagName('head')[0];
-    var script = document.createElement('script');
-
-    script.src = "http://maps.gstatic.com/intl/en_us/mapfiles/api-3/3/3a/main.js";
-    script.type = "text/javascript";
-
-    head.insertBefore( script, head.firstChild );  
-  })();
-
-  // IMPORTANT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   Popcorn.plugin( "googleMap" , (function(){
       
-    var newdiv, i = 1;
+    var newdiv, i = 1, _mapFired = false, _mapLoaded = false;
     
     return {
       manifest: {
           website: "annasob.wordpress.com"
         },
         options:{
-          start   : {elem:'input', type:'text', label:'In'},
-          end     : {elem:'input', type:'text', label:'Out'},
-          text    : {elem:'input', type:'text', label:'Text'}
+          start    : {elem:'input', type:'text', label:'In'},
+          end      : {elem:'input', type:'text', label:'Out'},
+          target   : 'map-container',
+          type     : {elem:'select', type:'text', label:'Type'},
+          zoom     : {elem:'input', type:'text', label:'Zoom'},
+          lat      : {elem:'input', type:'text', label:'Lat'},
+          long     : {elem:'input', type:'text', label:'Long'},
+          location : {elem:'input', type:'text', label:'Location'},
         }
       },
       _setup : function( options ) {
-        
-        
-        
-       
-        options.target  = document.getElementById(options.target),
+        // insert google api script once
+        if (!_mapFired) {
+          _mapFired = true;
+          var loadScriptTime = (new Date).getTime();
+          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.appendChild( script, head.firstChild ); 
+        }
+        // callback function fires when the script is run
+        googleCallback = function() {
+          window.google = window.google || {};
+          google.maps   = google.maps || {};
+          _mapLoaded    = true;
+        };
+        // If there is no lat/long, and there is location, geocode the location
+        // you can only do this once google.maps exists
+        // however geocode takes a while so loop this function until lat/long is defined.
+        var isGeoReady = function() {
+          if ( !_mapLoaded && !options.lat) {
+            setTimeout(function () {
+              isGeoReady();
+            }, 13);
+          } else {
+            if (options.location) {
+              var geocoder = new google.maps.Geocoder();
+              geocoder.geocode({ 'address': options.location}, function(results, status) {
+                if (status === google.maps.GeocoderStatus.OK) {
+                  options.lat  = results[0].geometry.location.wa;
+                  options.long = results[0].geometry.location.ya; 
+                } 
+              });
+            }
+          }
+        };
+        isGeoReady();
+        options.target  = document.getElementById(options.target);
         // create a new div this way anything in the target div
         // will stay intack 
         options._newdiv              = document.createElement('div');
@@ -87,6 +98,8 @@
         options._newdiv.style.height = "100%";
         i++;
         options.target.appendChild(options._newdiv);
+        
+        /**/
       },
       /**
        * @member webpage 
        * options variable
        */
       start: function(event, options){
-        var that = this,
-            renderMap = function(){
-            var location = new google.maps.LatLng(options.lat, options.long);
-            options._map = new google.maps.Map(options._newdiv, {mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID });
-            
+        // dont do anything if the information didn't come back from google map
+        var isReady = function () {
+          
+          if ( !google.maps || !options.lat) {
+            setTimeout(function () {
+              isReady();
+            }, 13);
+          } else {
+             
+            if(options._map){
+              options._map.getDiv().style.display = 'block';
+            } else {
+              var location = new google.maps.LatLng(options.lat, options.long);
+              options._map = new google.maps.Map(options._newdiv, {mapTypeId: google.maps.MapTypeId[options.type] || google.maps.MapTypeId.HYBRID });      
+            }
+            // reset the location and zoom just in case the user plaid with the map
             options._map.setCenter(location);
             options._map.setZoom(options.zoom || 0);
           }
-        // If there is no lat/long, and there is location, geocode the location
-        if ( (!options.lat || !options.long || options.lat == 'null' || options.long == 'null') && options.location) {
-          var location ='boston',
-              geocoder = new google.maps.Geocoder(),
-              lat,
-              long;
-
-          geocoder.geocode({
-              address: options.location
-            }, function(results, status) {
-               options.lat = results[0].geometry.location.va;
-               options.long = results[0].geometry.location.wa;
-               renderMap.call(that);  
-          })
-        } else {
-          renderMap();
-        }
-      
+        };
+        
+        isReady();
       },
       /**
        * @member webpage 
        * options variable
        */
       end: function(event, options){
-        // remove the map from the target div
-        options.target.removeChild(options._map.getDiv());
+        // 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 = null;
+          
+        }
       }
       
     };
index 21e2c4faa4bb06d8949cf98b215a55590e002983..850cb9397d3dbe646f1f4ba1a8c4841b92944295 100644 (file)
@@ -38,6 +38,7 @@
     <p>Your user agent does not support the HTML5 Video element.</p> 
 
   </video> 
-  <div id="map"></div>  
+  <div id="map" style="position:relative;float:left;width:300px;height:400px"></div> 
+  <div id="map2" style="position:relative;float:left;width:300px;height:400px"></div>   
 </body>
 </html>
index 7877ca1dd3b032ee4a0f4120902b5843de7a029a..172c26ed6373de6b1fceecfa831bdeadb462307d 100644 (file)
@@ -1,12 +1,12 @@
 test("Popcorn Google Map Plugin", function () {
   
   var popped = Popcorn("#video"),
-      expects = 5, 
+      expects = 10, 
       count = 0,
-      iframeInterval,
-      iframeInterval2,
-      iframeInterval3,
-      iframeInterval4;
+      mapInterval,
+      mapInterval2,
+      mapInterval3,
+      mapInterval4;
   
   expect(expects);
   
@@ -18,49 +18,65 @@ test("Popcorn Google Map Plugin", function () {
   
   stop();
    
-  ok ('footnote' in popped, "footnote is a mehtod of the popped instance");
+  ok ('googleMap' in popped, "googleMap is a mehtod of the popped instance");
   plus();
   
-  ok ( document.getElementById('footnotediv').innerHTML === "", "initially, there is nothing inside the footnotediv" );
+  ok ( document.getElementById('map').innerHTML === "", "initially, there is nothing inside the map" );
   plus();
-  //equals( actual, expected, message ) instead of ok( boolean true, message )
-  popped.footnote({
-      start: 5, // seconds
-      end: 15, // seconds
-      text: 'This video made exclusively for drumbeat.org',
-      target: 'footnotediv'
-    } )
-    .footnote({
-      start: 35, // seconds
-      end: 45, // seconds
-      text: 'Visit webmademovies.org for more details',
-      target: 'footnotediv'
-    } )
+  
+  ok ( document.getElementById('map2').innerHTML === "", "initially, there is nothing inside the map2" );
+  plus();
+  
+  popped.googleMap({
+        start: 0, // seconds
+        end: 5, // seconds
+        type: 'ROADMAP',
+        target: 'map',
+        lat: 43.665429,
+        long: -79.403323,
+        zoom: 10
+      } )
+      .googleMap({
+        start: 0, // seconds
+        end: 5, // seconds
+        type: 'SATELLITE',
+        target: 'map2',
+        location:'boston',
+        zoom: 15
+      } )
+    .volume(0)
     .play();
   
   
-  interval = setInterval( function() {
-    if( popped.currentTime() > 5 && popped.currentTime() <= 15 ) {
-      ok (document.getElementById('footnotediv').innerHTML === "This video made exclusively for drumbeat.org", "footnote displaing correct information" );
+  mapInterval = setInterval( function() {
+    if( popped.currentTime() > 3 && popped.currentTime() <= 5 ) {
+      ok(google.maps, "Google maps is available");
+      plus();
+      ok(google.maps.Geocoder, "Google maps Geocoder is available");
+      plus();
+      ok (document.getElementById('actualmap1'), "First map is on the page" );
       plus();
-      clearInterval( interval );
+      equals (document.getElementById('actualmap1').offsetParent.id, "map", "First map is inside the 'map' div" );
+      plus();
+      clearInterval( mapInterval );
     }
-  }, 5000);
-  
-  interval2 = setInterval( function() {
-    if( popped.currentTime() > 15 && popped.currentTime() < 35  ) {
-      ok (document.getElementById('footnotediv').innerHTML === "", "footnote cleared properly" );
+  }, 1000);
+  mapInterval2 = setInterval( function() {
+    if( popped.currentTime() > 3 && popped.currentTime() <= 5 ) {
+      ok (document.getElementById('actualmap2'), "Second map is on the page" );
       plus();
-      clearInterval( interval2 );
+      equals (document.getElementById('actualmap2').offsetParent.id, "map2", "Second map is inside the 'map2' div" );
+      plus();
+      clearInterval( mapInterval2 );
     }
-  }, 5000);
-  
-  interval3 = setInterval( function() {
-    if( popped.currentTime() > 35 && popped.currentTime() < 45 ) {
-      ok (document.getElementById('footnotediv').innerHTML === "Visit webmademovies.org for more details", "footnote displaing correct information" );
+  }, 1000);
+  mapInterval3 = setInterval( function() {
+    if( popped.currentTime() > 5  ) {
+      ok (document.getElementById('actualmap2').style.display === "none" && 
+          document.getElementById('actualmap1').style.display === "none", "Both maps are no longer visible" );
       plus();
-      clearInterval( interval3 );
+      clearInterval( mapInterval3 );
     }
-  }, 5000);
+  }, 1000);
   
 });
diff --git a/plugins/googleMap/popcorngoogleMap.unit.js b/plugins/googleMap/popcorngoogleMap.unit.js
deleted file mode 100644 (file)
index 7877ca1..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-test("Popcorn Google Map Plugin", function () {
-  
-  var popped = Popcorn("#video"),
-      expects = 5, 
-      count = 0,
-      iframeInterval,
-      iframeInterval2,
-      iframeInterval3,
-      iframeInterval4;
-  
-  expect(expects);
-  
-  function plus() {
-    if ( ++count===expects) {
-      start();
-    }
-  }
-  
-  stop();
-   
-  ok ('footnote' in popped, "footnote is a mehtod of the popped instance");
-  plus();
-  
-  ok ( document.getElementById('footnotediv').innerHTML === "", "initially, there is nothing inside the footnotediv" );
-  plus();
-  //equals( actual, expected, message ) instead of ok( boolean true, message )
-  popped.footnote({
-      start: 5, // seconds
-      end: 15, // seconds
-      text: 'This video made exclusively for drumbeat.org',
-      target: 'footnotediv'
-    } )
-    .footnote({
-      start: 35, // seconds
-      end: 45, // seconds
-      text: 'Visit webmademovies.org for more details',
-      target: 'footnotediv'
-    } )
-    .play();
-  
-  
-  interval = setInterval( function() {
-    if( popped.currentTime() > 5 && popped.currentTime() <= 15 ) {
-      ok (document.getElementById('footnotediv').innerHTML === "This video made exclusively for drumbeat.org", "footnote displaing correct information" );
-      plus();
-      clearInterval( interval );
-    }
-  }, 5000);
-  
-  interval2 = setInterval( function() {
-    if( popped.currentTime() > 15 && popped.currentTime() < 35  ) {
-      ok (document.getElementById('footnotediv').innerHTML === "", "footnote cleared properly" );
-      plus();
-      clearInterval( interval2 );
-    }
-  }, 5000);
-  
-  interval3 = setInterval( function() {
-    if( popped.currentTime() > 35 && popped.currentTime() < 45 ) {
-      ok (document.getElementById('footnotediv').innerHTML === "Visit webmademovies.org for more details", "footnote displaing correct information" );
-      plus();
-      clearInterval( interval3 );
-    }
-  }, 5000);
-  
-});