// PLUGIN: OPENMAP
var openmapCallback;
-(function (Popcorn) {
+( function ( Popcorn ) {
/**
* openmap popcorn plug-in
* -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
_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() {
} 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();
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 ),
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;
}
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;
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;
text: myMarker.text
};
}
- options._pointLayer.addFeatures( [ myPointFeature ] );
+ pointLayer.addFeatures( [ myPointFeature ] );
}
}
}
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';
}
}
{
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 );
test("Popcorn OpenMap Plugin", function () {
var popped = Popcorn("#video"),
- expects = 10,
+ expects = 12,
count = 0,
mapInterval,
mapInterval2,
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({
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();
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();
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