]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Merge commit 'ndoiron/master' into 0.4
authorAnna Sobiepanek <annaopensource@gmail.com>
Thu, 17 Mar 2011 19:47:53 +0000 (15:47 -0400)
committerAnna Sobiepanek <annaopensource@gmail.com>
Thu, 17 Mar 2011 19:47:53 +0000 (15:47 -0400)
1  2 
plugins/openmap/popcorn.openmap.html
plugins/openmap/popcorn.openmap.js
plugins/openmap/popcorn.openmap.unit.html
plugins/openmap/popcorn.openmap.unit.js
plugins/openmap/readme.txt

index 0000000000000000000000000000000000000000,6b25b2e3ab4af5ecb78ee475091d17c4353d5b50..c88b9b158e11d4acadf004b0c34cd7817ddb6d83
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,85 +1,85 @@@
 -                      size: 10
+ <!DOCTYPE html>
+ <html>
+ <head>
+   <title>Popcorn Open Map Plug-in Demo</title>
+   <script src="../../popcorn.js"></script>
+   <script src="popcorn.openmap.js"></script>
+   <script>
+     document.addEventListener('DOMContentLoaded', function () {
+       Popcorn('#video')
+       .volume( 0 )
+       .play()
+       .openmap( {
+         start: 0,
+         end: 20,
+         type: 'ROADMAP',
+         target: 'map',
+         lat: 43.665429,
+         lng: -79.403323,
+         zoom: "10"
+       } )
+       .openmap( {
+         start: 0,
+         end: 30,
+         type: 'SATELLITE',
+         target: 'map2',
+         lat: 42.358544,
+         lng: -71.05957,
+         zoom: 9,
+         markers: [
+           {
+             location: "Cambridge, MA",
+             icon: "http://google-maps-icons.googlecode.com/files/vegetarian.png",
+             text: "Clickable markers",
 -        type='video/mp4;' codecs="avc1, mp4a"'> 
++            size: 10
+           },
+           {
+             lat: 42.358544,
+             lng: -71.05957,
+             icon: "http://google-maps-icons.googlecode.com/files/walking-tour.png",
+             text: "Another clickable marker"
+           }
+         ]
+       } )
+       .openmap( {
+         start: 0,
+         end: 20,
+         type: 'TERRAIN',
+         target: 'map3',
+         lat: 40.943926,
+         lng: -78.968525,
+         zoom: 14
+       } );
+     }, false);
+   </script>
+ </head>
+ <body>
+   <h1 id="qunit-header">Popcorn Open Map Plug-in Demo</h1>
+   <p> An OpenLayers + OpenStreetMap Map displaying Toronto, Ontario will appear at 0 seconds and disappear at 20 seconds.</p>
+   <p> An OpenLayers + NASA LandSat Map displaying Boston and a map marker will appear at 0 seconds and disappear at 30 seconds.</p>
+   <p> An OpenLayers + USGS Topographic Map displaying Punxsutawney, PA will appear at 0 seconds and disappear at 20 seconds.</p>
+   <div>
+     <video id='video' 
+       controls 
+       width= '250px'
+       poster="../../test/poster.png"> 
+ 
+       <source id='mp4'
+         src="../../test/trailer.mp4"
 -        type='video/ogg;' codecs="theora, vorbis"'> 
++        type='video/mp4;' codecs="avc1, mp4a"> 
+ 
+       <source id='ogv'
+         src="../../test/trailer.ogv"
++        type='video/ogg;' codecs="theora, vorbis"> 
+ 
+       <p>Your user agent does not support the HTML5 Video element.</p> 
+ 
+     </video>
+   </div>
+   <div style="width:1000px">
+     <div id="map" style="position:relative;float:left;width:300px;height:400px"><p>Locations in this video:</p></div>
+     <div id="map2" style="position:relative;float:left;width:300px;height:400px"><p>Locations in this video:</p></div>
+     <div id="map3" style="position:relative;float:left;width:300px;height:400px"><p>Locations in this video:</p></div>
+   </div>
+ </body>
+ </html>
index 0000000000000000000000000000000000000000,83392213f53d7ee071f897b0e3385f524cc43e1a..1a65bb7d26162aaa7827470f83fdd1ba69891def
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,276 +1,276 @@@
 -          map,
+ // PLUGIN: OPENMAP
+ var openmapCallback;
+ ( function ( Popcorn ) {
+   
+   /**
+    * openmap popcorn plug-in 
+    * Adds an OpenLayers + OpenStreetMap map to the target div centered on the location specified by the user
+    * Based on the googlemap popcorn plug-in. No StreetView support
+    * Options parameter will need a start, end, target, type, zoom, lat and lng
+    * -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: ROADMAP (OpenStreetMap), SATELLITE (NASA WorldWind / LandSat), or TERRAIN (USGS)
+    * -Zoom [optional] defaults to 2
+    * -Lat and Lng are the coordinates of the map if location is not named
+    * -Location is a name of a place to center the map, geocoded to coordinates using TinyGeocoder.com
+    * -Markers [optional] is an array of map marker objects, with the following properties:
+    * --Icon is the URL of a map marker image
+    * --Size [optional] is the radius in pixels of the scaled marker image (default is 14)
+    * --Text [optional] is the HTML content of the map marker -- if your popcorn instance is named 'popped', use <script>popped.currentTime(10);</script> to control the video
+    * --Lat and Lng are coordinates of the map marker if location is not specified
+    * --Location is a name of a place for the map marker, geocoded to coordinates using TinyGeocoder.com
+    *  Note: using location requires extra loading time, also not specifying both lat/lng and location will
+    * cause a JavaScript error. 
+    * @param {Object} options
+    * 
+    * Example:
+      var p = Popcorn( '#video' )
+         .openmap({
+           start: 5,
+           end: 15,
+           type: 'ROADMAP',
+           target: 'map',
+           lat: 43.665429,
+           lng: -79.403323
+         } )
+    *
+    */
+   var newdiv,
+       i = 1,
+       _mapFired = false,
+       _mapLoaded = false;
+ 
+   // insert openlayers api script once
+   if ( !_mapFired ) {
+     _mapFired = true;
+     Popcorn.getScript('http://openlayers.org/api/OpenLayers.js',
+     function() {
+       _mapLoaded = true;
+     } );
+   }
+ 
+   Popcorn.plugin( "openmap" , function( options ){
+     var newdiv,
++        map,
+         centerlonlat,
+         projection,
+         displayProjection,
+         pointLayer,
+         selectControl,
+         popup;
+ 
+     // create a new div within the target div
+     // 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++;
+     if ( document.getElementById( options.target ) ) {
+       document.getElementById( options.target ).appendChild( newdiv );
+     }
+     // callback function fires when the script is run
+     var isGeoReady = function() {
+       if ( !_mapLoaded ) {
+         setTimeout( function () {
+           isGeoReady();
+         }, 50);
+       } else {
+         if( options.location ){
+           // set a dummy center at start
+           location = new OpenLayers.LonLat( 0, 0 );
+           // query TinyGeocoder and re-center in callback
+           Popcorn.getJSONP(
+             "http://tinygeocoder.com/create-api.php?q=" + options.location + "&callback=jsonp",
+             function( latlng ) {
+               centerlonlat = new OpenLayers.LonLat( latlng[1], latlng[0] );
+               map.setCenter( centerlonlat );
+             }
+           );
+         } else {
+           centerlonlat = new OpenLayers.LonLat( options.lng, options.lat );
+         }
+         if( options.type == "ROADMAP" ) {
+           // add OpenStreetMap layer
+           projection = new OpenLayers.Projection( 'EPSG:900913' );
+           displayProjection = new OpenLayers.Projection( 'EPSG:4326' );
+           centerlonlat = centerlonlat.transform( displayProjection, projection );
+           map = new OpenLayers.Map( { div: newdiv, projection: projection, "displayProjection": displayProjection } );
+           var osm = new OpenLayers.Layer.OSM();
+           map.addLayer( osm );
+         }
+         else if( options.type == "SATELLITE" ) {
+           // add NASA WorldWind / LANDSAT map
+           map = new OpenLayers.Map( { div: newdiv, "maxResolution": .28125, tileSize: new OpenLayers.Size( 512, 512 ) } );
+           var worldwind = new OpenLayers.Layer.WorldWind( "LANDSAT", "http://worldwind25.arc.nasa.gov/tile/tile.aspx", 2.25, 4, { T: "105" } );
+           map.addLayer( worldwind );
+           displayProjection = new OpenLayers.Projection( "EPSG:4326" );
+           projection = new OpenLayers.Projection( "EPSG:4326" );
+         }
+         else if( options.type == "TERRAIN" ) {
+           // add terrain map ( USGS )
+           displayProjection = new OpenLayers.Projection( "EPSG:4326" );
+           projection = new OpenLayers.Projection( "EPSG:4326" );
+           map = new OpenLayers.Map( {div: newdiv, projection: projection } );
+           var relief = new OpenLayers.Layer.WMS( "USGS Terraserver", "http://terraserver-usa.org/ogcmap.ashx?", { layers: 'DRG' } ); 
+           map.addLayer( relief );
+         }
+         map.div.style.display = "none";
+       }
+     };
+     isGeoReady();
+ 
+     return {
+       /**
+        * @member openmap 
+        * 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 ) {
+         var isReady = function () {
+           // wait until OpenLayers has been loaded, and the start function is run, before adding map
+           if ( !map ) {
+             setTimeout( function () {
+               isReady();
+             }, 13 );
+           } else {
+             map.div.style.display = "block";
+             // make sure options.zoom is a number
+             if ( options.zoom && typeof options.zoom !== "number" ) {
+               options.zoom = +options.zoom;
+             }
+             // default zoom is 2
+             options.zoom = options.zoom || 2;
+ 
+             // reset the location and zoom just in case the user played with the map
+             map.setCenter( centerlonlat, options.zoom );
+             if( options.markers ){
+               var layerStyle = OpenLayers.Util.extend( {} , OpenLayers.Feature.Vector.style[ 'default' ] );
+               pointLayer = new OpenLayers.Layer.Vector( "Point Layer", { style: layerStyle } );
+               map.addLayer( pointLayer );
+               for( var m = 0; m < options.markers.length; m++ ) {
+                 var myMarker = options.markers[ m ];
+                 if( myMarker.text ){
+                   if( !selectControl ){
+                     selectControl = new OpenLayers.Control.SelectFeature( pointLayer );
+                     map.addControl( selectControl );
+                     selectControl.activate();
+                     pointLayer.events.on( {
+                       "featureselected": function( clickInfo ) {
+                         clickedFeature = clickInfo.feature;
+                         if( !clickedFeature.attributes.text ){
+                           return;
+                         }
+                         popup = new OpenLayers.Popup.FramedCloud(
+                           "featurePopup",
+                           clickedFeature.geometry.getBounds().getCenterLonLat(),
+                           new OpenLayers.Size( 120, 250 ),
+                           clickedFeature.attributes.text,
+                           null,
+                           true,
+                           function( closeInfo ) {
+                             selectControl.unselect( this.feature );
+                           }
+                         );
+                         clickedFeature.popup = popup;
+                         popup.feature = clickedFeature;
+                         map.addPopup( popup );
+                       },
+                       "featureunselected": function( clickInfo ) {
+                         feature = clickInfo.feature;
+                         if ( feature.popup ) {
+                           popup.feature = null;
+                           map.removePopup( feature.popup );
+                           feature.popup.destroy();
+                           feature.popup = null;
+                         }
+                       }
+                     } );
+                   }
+                 }
+                 if( myMarker.location ){
+                   var geocodeThenPlotMarker = function( myMarker ){
+                     Popcorn.getJSONP(
+                       "http://tinygeocoder.com/create-api.php?q=" + myMarker.location + "&callback=jsonp",
+                       function( latlng ){
+                         var myPoint = new OpenLayers.Geometry.Point( latlng[1], latlng[0] ).transform( displayProjection, projection ),
+                             myPointStyle = OpenLayers.Util.extend( {}, layerStyle );
+                         if( !myMarker.size || isNaN( myMarker.size ) ) {
+                           myMarker.size = 14;
+                         }
+                         myPointStyle.pointRadius = myMarker.size;
+                         myPointStyle.graphicOpacity = 1;
+                         myPointStyle.externalGraphic = myMarker.icon;
+                         var myPointFeature = new OpenLayers.Feature.Vector( myPoint, null, myPointStyle );
+                         if( myMarker.text ) {
+                           myPointFeature.attributes = { 
+                             text: myMarker.text
+                           };
+                         }
+                         pointLayer.addFeatures( [ myPointFeature ] );
+                       }
+                     );
+                   };
+                   geocodeThenPlotMarker(myMarker);
+                 } else {
+                   var myPoint = new OpenLayers.Geometry.Point( myMarker.lng, myMarker.lat ).transform( displayProjection, projection ),
+                       myPointStyle = OpenLayers.Util.extend( {}, layerStyle );
+                   if( !myMarker.size || isNaN( myMarker.size ) ) {
+                     myMarker.size = 14;
+                   }
+                   myPointStyle.pointRadius = myMarker.size;
+                   myPointStyle.graphicOpacity = 1;
+                   myPointStyle.externalGraphic = myMarker.icon;
+                   var myPointFeature = new OpenLayers.Feature.Vector( myPoint, null, myPointStyle );
+                   if( myMarker.text ) {
+                     myPointFeature.attributes = { 
+                       text: myMarker.text
+                     };
+                   }
+                   pointLayer.addFeatures( [ myPointFeature ] );
+                 }
+               }
+             }
+           }
+         };
+         
+         isReady();
+       },
+       /**
+        * @member openmap
+        * 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.div.style.display = 'none';          
+         }
+       }
+ 
+     };
+   },
+   {
+     about:{
+       name: "Popcorn OpenMap Plugin",
+       version: "0.3",
+       author: "@mapmeld",
+       website: "mapadelsur.blogspot.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', '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'},
+       markers  : { elem: 'input', type: 'text', label: 'List Markers'}
+     }
+   } );
+ } ) ( Popcorn );
index 0000000000000000000000000000000000000000,6bc96a42fdae561de11f4e5c18b87d357bebe47b..0df8f2b1992c79c267901b0a445aca5757eefe4f
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,45 +1,45 @@@
 -    popcorn-api-draft.js
+ <!DOCTYPE html>
+ <html>
+ <head>
+   <title>Popcorn API</title>
+   <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+   <script src="../../test/qunit/qunit.js"></script>
+   <!-- 
+     do not move - this must be called immediately prior to 
 -      type='video/mp4;' codecs="avc1, mp4a"'> 
++    popcorn.js
+   -->
+   
+   <script src="../../popcorn.js"></script>
+   <script src="popcorn.openmap.js"></script>
+ 
+   <script src="popcorn.openmap.unit.js"></script>
+ </head>
+ <body>
+   <h1 id="qunit-header">Popcorn Open Map Plugin</h1>
+   <h2 id="qunit-banner"></h2>
+   <div id="qunit-testrunner-toolbar"></div>
+   <h2 id="qunit-userAgent"></h2>
+   <ol id="qunit-tests"></ol>
+   <div id="qunit-fixture">  </div>
+   
+   <video id='video' 
+     controls preload='none' 
+     width= '250px'
+     poster="../../test/poster.png"> 
+ 
+     <source id='mp4'
+       src="../../test/trailer.mp4"
 -      type='video/ogg;' codecs="theora, vorbis"'> 
++      type='video/mp4;' codecs="avc1, mp4a"> 
+ 
+     <source id='ogv'
+       src="../../test/trailer.ogv"
++      type='video/ogg;' codecs="theora, vorbis"> 
+ 
+     <p>Your user agent does not support the HTML5 Video element.</p> 
+ 
+   </video> 
+   <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>
+   <div id="map3" style="position:relative;float:left;width:300px;height:400px"></div>
+ </body>
+ </html>
index 0000000000000000000000000000000000000000,2be25a2916ef82f222b40cf6396ac8e7c59431cd..2be25a2916ef82f222b40cf6396ac8e7c59431cd
mode 000000,100644..100644
--- /dev/null
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..aaf8ded294024217631d1c7c5c6f696c3e390a0a
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,47 @@@
++## What is Popcorn.js? ##
++An open source JavaScript library which connects and synchronizes the <video> tag to other resources, such as these maps.
++
++* Project page: https://wiki.mozilla.org/PopcornOpenVideoAPI
++
++* Source code on Github: https://github.com/annasob/popcorn-js/
++
++## What does the OpenMap plugin add? ##
++You can add clickable markers with custom icons
++
++As an alternative to Google Maps, the OpenMap plugin offers:
++
++* An interactive map using OpenLayers.js - free, open source, and compatible with many mapping formats - http://openlayers.org
++
++* ROADMAP using OpenStreetMap - a free, open data source which is editable by anyone.  Due to its free license, it has received data from many governmental, commercial, and academic sources.  Editors can use Yahoo and Bing Maps to trace information onto the map.  In many parts of the world, OpenStreetMap has better coverage and more up-to-date data than major providers such as Google Maps.  - http://opensteetmap.org
++
++* SATELLITE using NASA Landsat / World Wind - satellite images in the public domain
++
++* TERRAIN using USGS Topographic Maps in the public domain
++
++## Sample code for Popcorn.js ##
++popped.openmap({
++  start: 0,
++  end: 15,
++  type: 'ROADMAP', // OpenStreetMap
++  target: 'map',
++  lat: 43.665429,
++  lng: -79.403323,
++  zoom: 10
++})
++.openmap( {
++  start: 0,
++  end: 30,
++  type: 'SATELLITE', // NASA World Wind / LANDSAT
++  target: 'map2',
++  location: 'Boston, MA',
++  zoom: 9,
++  markers: [
++    {
++      lat: 42.358544,
++      lng: -71.05957,
++      icon: 'http://google-maps-icons.googlecode.com/files/vegetarian.png',
++      text: 'Clickable markers',
++      size: 10
++    }
++  ]
++});