From 00e6e16243841ad1e59e461ed763d4913067a7ec Mon Sep 17 00:00:00 2001 From: Nick Doiron Date: Thu, 17 Mar 2011 14:38:14 -0400 Subject: [PATCH] * Revised spacing and indentation * Implemented and tested USGS Terraserver TERRAIN map * Replaced setInterval with Popcorn.exec --- popcorn.openmap.html | 13 +++- popcorn.openmap.js | 152 ++++++++++++++++++++------------------ popcorn.openmap.unit.html | 3 +- popcorn.openmap.unit.js | 53 +++++++++---- readme.txt | 2 + 5 files changed, 134 insertions(+), 89 deletions(-) diff --git a/popcorn.openmap.html b/popcorn.openmap.html index 2d1fe14..6b25b2e 100644 --- a/popcorn.openmap.html +++ b/popcorn.openmap.html @@ -40,6 +40,15 @@ text: "Another clickable marker" } ] + } ) + .openmap( { + start: 0, + end: 20, + type: 'TERRAIN', + target: 'map3', + lat: 40.943926, + lng: -78.968525, + zoom: 14 } ); }, false); @@ -48,6 +57,7 @@

Popcorn Open Map Plug-in Demo

An OpenLayers + OpenStreetMap Map displaying Toronto, Ontario will appear at 0 seconds and disappear at 20 seconds.

An OpenLayers + NASA LandSat Map displaying Boston and a map marker will appear at 0 seconds and disappear at 30 seconds.

+

An OpenLayers + USGS Topographic Map displaying Punxsutawney, PA will appear at 0 seconds and disappear at 20 seconds.

-
+

Locations in this video:

Locations in this video:

+

Locations in this video:

\ No newline at end of file diff --git a/popcorn.openmap.js b/popcorn.openmap.js index 83830c5..8339221 100644 --- a/popcorn.openmap.js +++ b/popcorn.openmap.js @@ -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
-
+
+
diff --git a/popcorn.openmap.unit.js b/popcorn.openmap.unit.js index a1a1a0d..2be25a2 100644 --- a/popcorn.openmap.unit.js +++ b/popcorn.openmap.unit.js @@ -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 diff --git a/readme.txt b/readme.txt index 4ea4aa7..aaf8ded 100644 --- a/readme.txt +++ b/readme.txt @@ -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, -- 2.43.0