]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
* Revised spacing and indentation
authorNick Doiron <ndoiron@mapmeld.com>
Thu, 17 Mar 2011 18:38:14 +0000 (14:38 -0400)
committerNick Doiron <ndoiron@mapmeld.com>
Thu, 17 Mar 2011 18:38:14 +0000 (14:38 -0400)
* Implemented and tested USGS Terraserver TERRAIN map
* Replaced setInterval with Popcorn.exec

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

index 2d1fe147aca59312c6feb4c19e7b6d97dc1a29fa..6b25b2e3ab4af5ecb78ee475091d17c4353d5b50 100644 (file)
             text: "Another clickable marker"
           }
         ]
+      } )
+      .openmap( {
+        start: 0,
+        end: 20,
+        type: 'TERRAIN',
+        target: 'map3',
+        lat: 40.943926,
+        lng: -78.968525,
+        zoom: 14
       } );
     }, false);
   </script>
@@ -48,6 +57,7 @@
   <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 
 
     </video>
   </div>
-  <div style="width:700px">
+  <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>
\ No newline at end of file
index 83830c55eb03e811f9a880090a93ab49e5970f6a..83392213f53d7ee071f897b0e3385f524cc43e1a 100644 (file)
@@ -1,6 +1,6 @@
 // PLUGIN: OPENMAP
 var openmapCallback;
-(function (Popcorn) {
+( function ( Popcorn ) {
   
   /**
    * openmap popcorn plug-in 
@@ -10,7 +10,7 @@ var openmapCallback;
    * -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), 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
@@ -42,24 +42,33 @@ var openmapCallback;
       _mapLoaded = false;
 
   // insert openlayers api script once
-  if (!_mapFired) {
-  _mapFired = true;
-  Popcorn.getScript('http://openlayers.org/api/OpenLayers.js',
+  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
-    options._newdiv               = document.createElement('div');
-    options._newdiv.id            = "actualmap"+i;
-    options._newdiv.style.width   = "100%";
-    options._newdiv.style.height  = "100%";
+    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(options._newdiv);
+    if ( document.getElementById( options.target ) ) {
+      document.getElementById( options.target ).appendChild( newdiv );
     }
     // callback function fires when the script is run
     var isGeoReady = function() {
@@ -70,44 +79,44 @@ var openmapCallback;
       } else {
         if( options.location ){
           // set a dummy center at start
-          options._location = new OpenLayers.LonLat( 0, 0 );
+          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 );
+              centerlonlat = new OpenLayers.LonLat( latlng[1], latlng[0] );
+              map.setCenter( centerlonlat );
             }
           );
         } else {
-          options._location = new OpenLayers.LonLat( options.lng, options.lat );
+          centerlonlat = 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 } );
+          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();
-          options._map.addLayer( osm );
+          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 ) } );
+          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" } );
-          options._map.addLayer( worldwind );
-          options._displayProjection = new OpenLayers.Projection( "EPSG:4326" );
-          options._projection = new OpenLayers.Projection( "EPSG:4326" );
+          map.addLayer( worldwind );
+          displayProjection = new OpenLayers.Projection( "EPSG:4326" );
+          projection = new OpenLayers.Projection( "EPSG:4326" );
         }
         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" );
+          // 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 );
         }
-        options._map.div.style.display = "none";
+        map.div.style.display = "none";
       }
     };
     isGeoReady();
@@ -122,38 +131,39 @@ var openmapCallback;
       start: function( event, options ) {
         var isReady = function () {
           // wait until OpenLayers has been loaded, and the start function is run, before adding map
-          if (!options._map) {
-            setTimeout(function () {
+          if ( !map ) {
+            setTimeout( function () {
               isReady();
-            }, 13);
+            }, 13 );
           } else {
-            options._map.div.style.display = "block";
+            map.div.style.display = "block";
             // make sure options.zoom is a number
             if ( options.zoom && typeof options.zoom !== "number" ) {
               options.zoom = +options.zoom;
             }
-            options.zoom = options.zoom || 2; // default to 2
+            // default zoom is 2
+            options.zoom = options.zoom || 2;
 
             // reset the location and zoom just in case the user played with the map
-            options._map.setCenter( options._location, options.zoom );
+            map.setCenter( centerlonlat, options.zoom );
             if( options.markers ){
               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++ ) {
+              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( !options._selectControl ){
-                    options._selectControl = new OpenLayers.Control.SelectFeature( options._pointLayer );
-                    options._map.addControl( options._selectControl );
-                    options._selectControl.activate();
-                    options._pointLayer.events.on( {
+                  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;
                         }
-                        options._popup = new OpenLayers.Popup.FramedCloud(
+                        popup = new OpenLayers.Popup.FramedCloud(
                           "featurePopup",
                           clickedFeature.geometry.getBounds().getCenterLonLat(),
                           new OpenLayers.Size( 120, 250 ),
@@ -161,18 +171,18 @@ var openmapCallback;
                           null,
                           true,
                           function( closeInfo ) {
-                            options._selectControl.unselect(this.feature);
+                            selectControl.unselect( this.feature );
                           }
                         );
-                        clickedFeature.popup = options._popup;
-                        options._popup.feature = clickedFeature;
-                        options._map.addPopup(options._popup);
+                        clickedFeature.popup = popup;
+                        popup.feature = clickedFeature;
+                        map.addPopup( popup );
                       },
                       "featureunselected": function( clickInfo ) {
                         feature = clickInfo.feature;
                         if ( feature.popup ) {
-                          options._popup.feature = null;
-                          options._map.removePopup( feature.popup );
+                          popup.feature = null;
+                          map.removePopup( feature.popup );
                           feature.popup.destroy();
                           feature.popup = null;
                         }
@@ -185,7 +195,7 @@ var openmapCallback;
                     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 ),
+                        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;
@@ -199,13 +209,13 @@ var openmapCallback;
                             text: myMarker.text
                           };
                         }
-                        options._pointLayer.addFeatures( [ myPointFeature ] );
+                        pointLayer.addFeatures( [ myPointFeature ] );
                       }
                     );
                   };
                   geocodeThenPlotMarker(myMarker);
                 } else {
-                  var myPoint = new OpenLayers.Geometry.Point( myMarker.lng, myMarker.lat ).transform( options._displayProjection, options._projection ),
+                  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;
@@ -219,7 +229,7 @@ var openmapCallback;
                       text: myMarker.text
                     };
                   }
-                  options._pointLayer.addFeatures( [ myPointFeature ] );
+                  pointLayer.addFeatures( [ myPointFeature ] );
                 }
               }
             }
@@ -237,8 +247,8 @@ var openmapCallback;
       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 (options._map) {
-          options._map.div.style.display = 'none';          
+        if ( map ) {
+          map.div.style.display = 'none';          
         }
       }
 
@@ -247,20 +257,20 @@ var openmapCallback;
   {
     about:{
       name: "Popcorn OpenMap Plugin",
-      version: "0.2",
+      version: "0.3",
       author: "@mapmeld",
-      website: "mapuganda.blogspot.com"
+      website: "mapadelsur.blogspot.com"
     },
     options:{
-      start    : {elem:'input', type:'text', label:'In'},
-      end      : {elem:'input', type:'text', label:'Out'},
+      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'}
+      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 );
+  } );
+} ) ( Popcorn );
index ad69ba03e5d2ecc1ad468e28520e4675da1068e3..6bc96a42fdae561de11f4e5c18b87d357bebe47b 100644 (file)
@@ -39,6 +39,7 @@
 
   </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="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 a1a1a0d1eca934b3bb5d081438035415a72669bb..2be25a2916ef82f222b40cf6396ac8e7c59431cd 100644 (file)
@@ -1,7 +1,7 @@
 test("Popcorn OpenMap Plugin", function () {
   
   var popped = Popcorn("#video"),
-    expects = 10, 
+    expects = 12, 
     count = 0,
     mapInterval,
     mapInterval2,
@@ -21,10 +21,13 @@ test("Popcorn OpenMap Plugin", function () {
   ok ('openmap' in popped, "openmap is a method of the popped instance");
   plus();
   
-  ok ( document.getElementById('map').innerHTML === "", "initially, there is nothing inside the map" );
+  ok ( document.getElementById('map').innerHTML === "", "initially, there is nothing inside map" );
   plus();
   
-  ok ( document.getElementById('map2').innerHTML === "", "initially, there is nothing inside the map2" );
+  ok ( document.getElementById('map2').innerHTML === "", "initially, there is nothing inside map2" );
+  plus();
+
+  ok ( document.getElementById('map3').innerHTML === "", "initially, there is nothing inside map3" );
   plus();
   
   popped.openmap({
@@ -41,14 +44,23 @@ test("Popcorn OpenMap Plugin", function () {
     end: 5,
     type: 'SATELLITE',
     target: 'map2',
-    lat: 0,
-    lng: 0,
-    zoom: 4
+    lat: 40.943926,
+    lng: -78.968525,
+    zoom: 9
+  } )
+  .openmap( {
+    start: 0,
+    end: 5,
+    type: 'TERRAIN',
+    target: 'map3',
+    lat: 40.943926,
+    lng: -78.968525,
+    zoom: 14
   } )
   .volume(0)
   .play();
 
-  mapInterval = setInterval( function() {
+  mapInterval = popped.exec( 4, function() {
     if( popped.currentTime() > 3 && popped.currentTime() <= 5 ) {
       ok(OpenLayers, "OpenLayers is available");
       plus();
@@ -58,8 +70,8 @@ test("Popcorn OpenMap Plugin", function () {
       plus();
       clearInterval( mapInterval );
     }
-  }, 1000);
-  mapInterval2 = setInterval( function() {
+  } );
+  mapInterval2 = popped.exec( 4, function() {
     if( popped.currentTime() > 3 && popped.currentTime() <= 5 ) {
       ok (document.getElementById('actualmap2'), "Second map is on the page" );
       plus();
@@ -67,14 +79,23 @@ test("Popcorn OpenMap Plugin", function () {
       plus();
       clearInterval( mapInterval2 );
     }
-  }, 1000);
-  mapInterval3 = setInterval( function() {
+  } );
+  mapInterval3 = popped.exec( 4, function() {
+    if( popped.currentTime() > 3 && popped.currentTime() <= 5 ) {
+      ok (document.getElementById('actualmap3'), "Third map is on the page" );
+      plus();
+      equals (document.getElementById('actualmap3').offsetParent.id, "map3", "Third map is inside the 'map3' div" );
+      plus();
+      clearInterval( mapInterval3 );
+    }
+  } );
+  mapInterval4 = popped.exec( 6, function() {
     if( popped.currentTime() > 5  ) {
       ok (document.getElementById('actualmap2').style.display === "none" && 
-          document.getElementById('actualmap1').style.display === "none", "Both maps are no longer visible" );
+          document.getElementById('actualmap3').style.display === "none" && 
+          document.getElementById('actualmap1').style.display === "none", "All three maps are no longer visible" );
       plus();
-      clearInterval( mapInterval3 );
+      clearInterval( mapInterval4 );
     }
-  }, 1000);
-  
-});
\ No newline at end of file
+  } );
+} );
\ No newline at end of file
index 4ea4aa7ec5838808e69ecddc2fed282f683c9ad7..aaf8ded294024217631d1c7c5c6f696c3e390a0a 100644 (file)
@@ -16,6 +16,8 @@ As an alternative to Google Maps, the OpenMap plugin offers:
 
 * 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,