]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
* Updated to Popcorn 0.4 plugin format
authorNick Doiron <ndoiron@mapmeld.com>
Sun, 13 Mar 2011 21:16:55 +0000 (17:16 -0400)
committerNick Doiron <ndoiron@mapmeld.com>
Sun, 13 Mar 2011 21:16:55 +0000 (17:16 -0400)
* markers are added at start and removed at end, no synchronization
* markers can have popup
* marker size can be changed

popcorn.openmap.html
popcorn.openmap.js
popcorn.openmap.unit.html
popcorn.openmap.unit.js
readme.txt

index ba3b4735f2749ced2f5431daaf5b1dde5c2a6a12..2d1fe147aca59312c6feb4c19e7b6d97dc1a29fa 100644 (file)
@@ -5,14 +5,13 @@
   <script src="../../popcorn.js"></script>
   <script src="popcorn.openmap.js"></script>
   <script>
-    this.popped="";
     document.addEventListener('DOMContentLoaded', function () {
-      this.popped = Popcorn('#video')
+      Popcorn('#video')
       .volume( 0 )
       .play()
       .openmap( {
-        start: 0, // seconds
-        end: 20, // seconds
+        start: 0,
+        end: 20,
         type: 'ROADMAP',
         target: 'map',
         lat: 43.665429,
         zoom: "10"
       } )
       .openmap( {
-        start: 0, // seconds
-        end: 30, // seconds
+        start: 0,
+        end: 30,
         type: 'SATELLITE',
         target: 'map2',
         lat: 42.358544,
         lng: -71.05957,
-        zoom: 8,
+        zoom: 9,
         markers: [
           {
-            start: 0,
-            end: 100000000000000,
-            popcorn: this,
-            lat: 42.358,
-            lng: -71.0595,
-            icon: "http://google-maps-icons.googlecode.com/files/palace.png"
+            location: "Cambridge, MA",
+            icon: "http://google-maps-icons.googlecode.com/files/vegetarian.png",
+            text: "Clickable markers",
+                       size: 10
+          },
+          {
+            lat: 42.358544,
+            lng: -71.05957,
+            icon: "http://google-maps-icons.googlecode.com/files/walking-tour.png",
+            text: "Another clickable marker"
           }
         ]
       } );
index 45c10cb4f4d0bcab56868c9439b5ec41192873bb..5d104a48f3be00e517177a86c6acc3fd60216eac 100644 (file)
@@ -1,28 +1,34 @@
 // PLUGIN: OPENMAP
-var openlayersCallback;
+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, except location option not available
+   * 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)... Coming Soon: TERRAIN (USGS)
+   * -Type [optional] either: ROADMAP (OpenStreetMap), SATELLITE (NASA WorldWind / LandSat). Coming Soon: TERRAIN (USGS)
    * -Zoom [optional] defaults to 2
-   * -Lat and Lng: the coordinates of the map must be present if location is not specified.
-   * -Markers: array of marker objects to be added to the map at given times
+   * -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' )
-        .googlemap({
-          start: 5, // seconds
-          end: 15, // seconds
+        .openmap({
+          start: 5,
+          end: 15,
           type: 'ROADMAP',
           target: 'map',
           lat: 43.665429,
@@ -30,91 +36,83 @@ var openlayersCallback;
         } )
    *
    */
-  Popcorn.plugin( "openmap" , (function(){
-      
-    var newdiv, i = 1, _mapFired = false, _mapLoaded = false;
-    
-    return {
-      manifest: {
-        about:{
-          name: "Popcorn OpenMap Plugin",
-          version: "0.1",
-          author: "@mapmeld",
-          website: "mapuganda.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'], label:'Type'},
-          zoom     : {elem:'input', type:'text', label:'Zoom'},
-          lat      : {elem:'input', type:'text', label:'Lat'},
-          lng     : {elem:'input', type:'text', label:'Lng'},
-                 markers  : {elem:'input', type:'text', label:'List Markers'},
-          location : {elem:'input', type:'text', label:'Location'}
+  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 ){
+    // create a new div within 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%";
+    i++;
+    if (document.getElementById(options.target)) {
+      document.getElementById(options.target).appendChild(options._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
+          options._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 ) {
+              options._location = new OpenLayers.LonLat( latlng[1], latlng[0] );
+              options._map.setCenter( options._location );
+            }
+          );
+        } else {
+          options._location = new OpenLayers.LonLat( options.lng, options.lat );
         }
-      },
-      _setup : function( options ) {
-        // 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%";
-        i++;
-        if (document.getElementById(options.target)) {
-          document.getElementById(options.target).appendChild(options._newdiv);
+        if( options.type == "ROADMAP" ) {
+          // add OpenStreetMap layer
+          options._projection = new OpenLayers.Projection( 'EPSG:900913' );
+          options._displayProjection = new OpenLayers.Projection( 'EPSG:4326' );
+          options._location = options._location.transform( options._displayProjection, options._projection );
+          options._map = new OpenLayers.Map( { div: options._newdiv, projection: options._projection, "displayProjection": options._displayProjection } );
+          var osm = new OpenLayers.Layer.OSM();
+          options._map.addLayer( osm );
         }
-        
-        // insert openlayers 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://openlayers.org/api/OpenLayers.js";
-          script.onload = function() {
-                   _mapLoaded    = true;
-          };
-          script.type = "text/javascript";
-          head.insertBefore( script, head.firstChild ); 
-                 /*Popcorn.getScript("http://openlayers.org/api/OpenLayers.js",
-                       function() {
-                               _mapLoaded    = true;
-                       }); */
+        else if( options.type == "SATELLITE" ) {
+          // add NASA WorldWind / LANDSAT map
+          options._map = new OpenLayers.Map( { div: options._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" } );
+          options._map.addLayer( worldwind );
+          options._displayProjection = new OpenLayers.Projection( "EPSG:4326" );
+          options._projection = new OpenLayers.Projection( "EPSG:4326" );
         }
-        // callback function fires when the script is run
-        // geolocation to be added through Yahoo Maps JSONP
-        var isGeoReady = function() {
-          if ( !_mapLoaded ) {
-            setTimeout( function () {
-              isGeoReady();
-            }, 5);
-          } else {
+        else if( options.type == "TERRAIN" ) {
+          // add terrain map ( CC-BY-SA National Geographic Society ) - coming soon
+          options._map = new OpenLayers.Map( options._newdiv );
+          var relief = new OpenLayers.Layer.ArcGIS93Rest( "National Geographic Society", "http://server.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer/export"); 
+          options._map.addLayer( relief );
+          options._displayProjection = new OpenLayers.Projection( "EPSG:4326" );
+          options._projection = new OpenLayers.Projection( "EPSG:4326" );
+        }
+        options._map.div.style.display = "none";
+      }
+    };
+    isGeoReady();
 
-            options._location = new OpenLayers.LonLat( options.lng, options.lat );
-            if( options.type == "ROADMAP" ) {
-              // add OpenStreetMap layer
-              options._projection = new OpenLayers.Projection( 'EPSG:900913' );
-              options._displayProjection = new OpenLayers.Projection( 'EPSG:4326' );
-              options._location = options._location.transform( options._displayProjection, options._projection );
-              options._map = new OpenLayers.Map( { div: options._newdiv, projection: options._projection, 'displayProjection': options._displayProjection } );
-              var osm = new OpenLayers.Layer.OSM();
-              options._map.addLayer( osm );
-            }
-            else if( options.type == "SATELLITE" ) {
-              // add NASA WorldWind / LANDSAT map
-              options._map = new OpenLayers.Map( { div: options._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" } );
-              options._map.addLayer( worldwind );
-              options._displayProjection = new OpenLayers.Projection( 'EPSG:4326' );
-              options._projection = new OpenLayers.Projection( 'EPSG:4326' );
-            }
-            options._map.div.style.display = 'none';
-          }
-        };
-        isGeoReady();
-      },
+    return {
       /**
        * @member openmap 
        * The start function will be executed when the currentTime 
@@ -122,15 +120,14 @@ var openlayersCallback;
        * options variable
        */
       start: function( event, options ) {
-        // wait until OpenLayers is loaded, then check repeatedly if markers need to be added/removed
-               
-        var isReady = function () {    
+        var isReady = function () {
+          // wait until OpenLayers has been loaded, and the start function is run, before adding map
           if (!options._map) {
             setTimeout(function () {
               isReady();
             }, 13);
           } else {
-            options._map.div.style.display = 'block';
+            options._map.div.style.display = "block";
             // make sure options.zoom is a number
             if ( options.zoom && typeof options.zoom !== "number" ) {
               options.zoom = +options.zoom;
@@ -140,36 +137,91 @@ var openlayersCallback;
             // reset the location and zoom just in case the user played with the map
             options._map.setCenter( options._location, options.zoom );
             if( options.markers ){
-              setInterval( function() {
-                for( var m=0; m<options.markers.length; m++ ) {
-                  var myMarker = options.markers[ m ];
-                  if( myMarker.isOn ) {
-                    //marker is shown; check if marker should be removed
-                    if( ( myMarker.popcorn.popped.currentTime() < myMarker.start ) || ( myMarker.popcorn.popped.currentTime() > myMarker.end ) ){
-                      options._pointLayer.removeFeatures( [ myMarker.isOn ] );
-                      myMarker.isOn = false;
-                    }
+              var layerStyle = OpenLayers.Util.extend( {} , OpenLayers.Feature.Vector.style[ 'default' ] );
+              options._pointLayer = new OpenLayers.Layer.Vector( "Point Layer", { style: layerStyle } );
+              options._map.addLayer( options._pointLayer );
+              for( var m=0; m<options.markers.length; m++ ) {
+                var myMarker = options.markers[ m ];
+                if( myMarker.text ){
+                  if( !options._selectControl ){
+                    options._selectControl = new OpenLayers.Control.SelectFeature( options._pointLayer );
+                    options._map.addControl( options._selectControl );
+                    options._selectControl.activate();
+                    options._pointLayer.events.on( {
+                      "featureselected": function( clickInfo ) {
+                        clickedFeature = clickInfo.feature;
+                        if( !clickedFeature.attributes.text ){
+                          return;
+                        }
+                        options._popup = new OpenLayers.Popup.FramedCloud(
+                          "featurePopup",
+                          clickedFeature.geometry.getBounds().getCenterLonLat(),
+                          new OpenLayers.Size( 120, 250 ),
+                          clickedFeature.attributes.text,
+                          null,
+                          true,
+                          function( closeInfo ) {
+                            options._selectControl.unselect(this.feature);
+                          }
+                        );
+                        clickedFeature.popup = options._popup;
+                        options._popup.feature = clickedFeature;
+                        options._map.addPopup(options._popup);
+                      },
+                      "featureunselected": function( clickInfo ) {
+                        feature = clickInfo.feature;
+                        if ( feature.popup ) {
+                          options._popup.feature = null;
+                          options._map.removePopup( feature.popup );
+                          feature.popup.destroy();
+                          feature.popup = null;
+                        }
+                      }
+                    } );
                   }
-                  else {
-                    //marker is hidden; check if marker should be added
-                    if( ( myMarker.popcorn.popped.currentTime() > myMarker.start ) && ( myMarker.popcorn.popped.currentTime() < myMarker.end ) ) {
-                      var layerStyle = OpenLayers.Util.extend( {} , OpenLayers.Feature.Vector.style[ 'default' ] );
-                      if( !options._pointLayer ) {
-                        options._pointLayer = new OpenLayers.Layer.Vector( "Point Layer", { style: layerStyle } );
-                        options._map.addLayer( options._pointLayer );
+                }
+                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( options._displayProjection, options._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
+                          };
+                        }
+                        options._pointLayer.addFeatures( [ myPointFeature ] );
                       }
-                      var myPoint = new OpenLayers.Geometry.Point( myMarker.lng, myMarker.lat ).transform( options._displayProjection, options._projection );
-                      var myPointStyle = OpenLayers.Util.extend( {}, layerStyle );
-                      myPointStyle.pointRadius = 18;
-                      myPointStyle.graphicOpacity = 1;
-                      myPointStyle.externalGraphic = myMarker.icon;
-                      var myPointFeature = new OpenLayers.Feature.Vector( myPoint, null, myPointStyle );
-                      options._pointLayer.addFeatures( [ myPointFeature ] );
-                      myMarker.isOn = myPointFeature;
-                    }
+                    );
+                  };
+                  geocodeThenPlotMarker(myMarker);
+                } else {
+                  var myPoint = new OpenLayers.Geometry.Point( myMarker.lng, myMarker.lat ).transform( options._displayProjection, options._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
+                    };
+                  }
+                  options._pointLayer.addFeatures( [ myPointFeature ] );
                 }
-              }, 300);
+              }
             }
           }
         };
@@ -191,7 +243,24 @@ var openlayersCallback;
       }
 
     };
-    
-  })());
-
+  },
+  {
+    about:{
+      name: "Popcorn OpenMap Plugin",
+      version: "0.2",
+      author: "@mapmeld",
+      website: "mapuganda.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' ], 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 38e3c5aadafe1c87b383a061c62a1bf6913b5eb1..ad69ba03e5d2ecc1ad468e28520e4675da1068e3 100644 (file)
@@ -10,9 +10,9 @@
   -->
   
   <script src="../../popcorn.js"></script>
-  <script src="popcorn.googlemap.js"></script>
+  <script src="popcorn.openmap.js"></script>
 
-  <script src="popcorn.googlemap.unit.js"></script>
+  <script src="popcorn.openmap.unit.js"></script>
 </head>
 <body>
   <h1 id="qunit-header">Popcorn Open Map Plugin</h1>
index c0990690d4cc01f4be5c702bfc24eadf2e527c9c..a1a1a0d1eca934b3bb5d081438035415a72669bb 100644 (file)
@@ -1,4 +1,4 @@
-test("Popcorn Open Map Plugin", function () {
+test("Popcorn OpenMap Plugin", function () {
   
   var popped = Popcorn("#video"),
     expects = 10, 
@@ -28,17 +28,17 @@ test("Popcorn Open Map Plugin", function () {
   plus();
   
   popped.openmap({
-    start: 0, // seconds
-    end: 5, // seconds
+    start: 0,
+    end: 5,
     type: 'ROADMAP',
     target: 'map',
     lat: 43.665429,
     lng: -79.403323,
     zoom: 10
   } )
-  .googlemap({
-    start: 0, // seconds
-    end: 5, // seconds
+  .openmap({
+    start: 0,
+    end: 5,
     type: 'SATELLITE',
     target: 'map2',
     lat: 0,
index 8b9ed6a7ea3de44a054ad0e3a49c7e7e56abcf63..4ea4aa7ec5838808e69ecddc2fed282f683c9ad7 100644 (file)
@@ -3,10 +3,10 @@ An open source JavaScript library which connects and synchronizes the <video> ta
 
 * Project page: https://wiki.mozilla.org/PopcornOpenVideoAPI
 
-* Source code on Github: https://github.com/mozilla/popcorn-js/
+* Source code on Github: https://github.com/annasob/popcorn-js/
 
 ## What does the OpenMap plugin add? ##
-You can add markers at any point during the video's runtime.  For example, you can map places you've traveled as you talk about them in a video, or give a "top 10" places to go in your city, revealing each point one by one along with your video..
+You can add clickable markers with custom icons
 
 As an alternative to Google Maps, the OpenMap plugin offers:
 
@@ -14,4 +14,32 @@ As an alternative to Google Maps, the OpenMap plugin offers:
 
 * 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
\ No newline at end of file
+* SATELLITE using NASA Landsat / World Wind - satellite images 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
+    }
+  ]
+});
\ No newline at end of file