Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

ImageDownload testing now via permalink

Mike McGann36e67db258a9
diff --git a/src/js/imageDownload.js b/src/js/imageDownload.js
index ed37127a7..1c5ceccb3 100644
--- a/src/js/imageDownload.js
+++ b/src/js/imageDownload.js
@@ -8,34 +8,43 @@ SOTE.namespace("SOTE.widget.ImageDownload");
* @class ImageDownload
* @constructor
* @this {imageDownload}
- * @param {String} containerId is the container id of the div in which to render the object
+ * @param {String} containerId is the container id of the div in which to render the object
* @param {Object} [config] is a hash allowing configuration of this component
* @augments SOTE.widget.Component
- *
+ *
*/
SOTE.widget.ImageDownload = function(containerId, config){
- this.container=document.getElementById(containerId);
-
+ this.BASE_URL = "http://map2.vis.earthdata.nasa.gov/imagegen/index";
+ this.log = Logging.getLogger("Worldview.ImageDownload");
+
+ this.container=document.getElementById(containerId);
+
if (this.container==null){
this.setStatus("Error: element '"+containerId+"' not found!",true);
return;
}
-
+
if(config===undefined) {
config={};
}
-
+
this.alignTo = config.alignTo;
this.id = containerId;
this.m = config.m;
-
-
+
+
if (config.baselayer === undefined)
{
config.baselayer = null;
}
- this.baseLayer = config.baselayer;
+ this.baseLayer = config.baselayer;
+ this.config = config.config;
this.value = "";
+
+ if ( this.config.parameters.imagegen ) {
+ this.log.warn("Redirecting image download to: " + this.BASE_URL +
+ "-" + this.config.parameters.imagegen + ".php");
+ }
this.init();
};
@@ -44,21 +53,21 @@ SOTE.widget.ImageDownload.prototype = new SOTE.widget.Component;
/**
* Initialize a map object in Lat/Long projection, and add a "fake" layer to compute the map math.
- * Display the HTML UI with UI options. *
+ * Display the HTML UI with UI options. *
* @this {Download}
* @requires SOTE.widget.Map
*/
SOTE.widget.ImageDownload.prototype.init = function(){
this.container.setAttribute("class","imagedownload");
-
+
var self = this;
-
+
SOTE.widget.ImageDownload.setPosition(this);
$(window).resize(function() {
SOTE.widget.ImageDownload.setPosition(self);
});
-
- if(REGISTRY){
+
+ if(REGISTRY){
REGISTRY.register(this.id,this);
REGISTRY.markComponentReady(this.id);
}
@@ -69,13 +78,13 @@ SOTE.widget.ImageDownload.prototype.init = function(){
var htmlElements = "<div>Resolution (per pixel): <select id='selImgResolution'><option value='1'>250m</option><option value='2'>500m</option><option value='4'>1km</option><option value='20'>5km</option><option value='40'>10km</option></select>";
htmlElements +="<br />Format: <select id='selImgFormat'><option value='image/jpeg'>JPEG</option><option value='image/png'>PNG</option><option value='image/geotiff'>GeoTIFF</option></select>";
htmlElements +="<br />Raw Image Size: ~ <span id='imgFileSize'> </span> MB <br />(<span id='imgWidth''></span> x <span id='imgHeight'></span> pixels)";
- htmlElements += "<br /><span style='font-size:10px; color:#aaa; font-style:italic;'>(Max Size: 250 MB)</span> ";//(<span id='imgWidth''></span> x <span id='imgHeight'></span> pixels)
- htmlElements += "<br /><input type='button' id='btnImgDownload' value='Download'/>";
+ htmlElements += "<br /><span style='font-size:10px; color:#aaa; font-style:italic;'>(Max Size: 250 MB)</span> ";//(<span id='imgWidth''></span> x <span id='imgHeight'></span> pixels)
+ htmlElements += "<br /><input type='button' id='btnImgDownload' value='Download'/>";
htmlElements +="</div>";
-
- $("#"+this.id).html(htmlElements);
-
-
+
+ $("#"+this.id).html(htmlElements);
+
+
};
SOTE.widget.ImageDownload.setPosition = function(self){
@@ -92,9 +101,9 @@ SOTE.widget.ImageDownload.setPosition = function(self){
*
*/
SOTE.widget.ImageDownload.prototype.setValue = function(value){
-
+
this.value=value;
-
+
};
/**
@@ -109,15 +118,15 @@ SOTE.widget.ImageDownload.prototype.getValue = function(){
};
/**
- * Modify the component based on dependencies. Speficially, update the image dimensions and image size based on the size of rubberband box the user draws. *
+ * Modify the component based on dependencies. Speficially, update the image dimensions and image size based on the size of rubberband box the user draws. *
* @this {Download}
* @param {String} querystring contains all values of dependencies (from registry)
- *
+ *
*/
SOTE.widget.ImageDownload.prototype.updateComponent = function(qs){
-
+
try {
var bbox = SOTE.util.extractFromQuery('map',qs);
var time = SOTE.util.extractFromQuery('time',qs);
@@ -126,13 +135,19 @@ SOTE.widget.ImageDownload.prototype.updateComponent = function(qs){
var products = SOTE.util.extractFromQuery('products',qs);
var epsg = SOTE.util.extractFromQuery('epsg', qs);
//console.log("EPSG: " + epsg);
-
+
var px = pixels.split(",");
- var x1 = px[0]; var y1= px[1]; var x2 = px[2]; var y2=px[3];
+ var x1 = px[0]; var y1= px[1]; var x2 = px[2]; var y2=px[3];
var lonlat1 = this.m.maps.map.getLonLatFromViewPortPx(new OpenLayers.Pixel(Math.floor(x1), Math.floor(y2)));
var lonlat2 = this.m.maps.map.getLonLatFromViewPortPx(new OpenLayers.Pixel(Math.floor(x2), Math.floor(y1)));
- var dlURL = "http://map2.vis.earthdata.nasa.gov/imagegen/index-saveas.php?";
+ var dlURL = null;
+ var imagegen = this.config.parameters.imagegen;
+ if ( imagegen ) {
+ dlURL = this.BASE_URL + "-" + imagegen + ".php?";
+ } else {
+ dlURL= this.BASE_URL + ".php?";
+ }
var conversionFactor = 256;
if (s=="geographic") {
@@ -141,7 +156,7 @@ SOTE.widget.ImageDownload.prototype.updateComponent = function(qs){
}
conversionFactor = 0.002197;
}
- else { //polar
+ else { //polar
if( 0 != $('#selImgFormat option[value=KMZ]').length) {
$('#selImgFormat option[value=KMZ]').remove();
}
@@ -152,16 +167,16 @@ SOTE.widget.ImageDownload.prototype.updateComponent = function(qs){
var jDate = "00" + (1+Math.ceil((dTime.getTime() - jStart) / 86400000));
dlURL += "TIME="+dTime.getUTCFullYear()+(jDate).substr((jDate.length)-3);
-
-
+
+
dlURL += "&extent="+lonlat1.lon+","+lonlat1.lat+","+lonlat2.lon+","+lonlat2.lat;
-
+
//dlURL += "&switch="+s;
dlURL += "&epsg="+epsg;
dlURL +="&layers=";
if (products != ""){
var a = products.split("~");
-
+
//Add the first (top most) visible baselayer.
var base = a[0].split(",");
//base.reverse(); base.pop();
@@ -170,32 +185,32 @@ SOTE.widget.ImageDownload.prototype.updateComponent = function(qs){
dlURL += base[i]+",";
break;
}
- }
-
+ }
+
var overlays = a[1].split(/[\.,]/);
overlays.reverse(); overlays.pop();
-
+
for(var i=0; i<overlays.length; i++){
if(overlays[i].charAt(0)!="!") {
dlURL+= overlays[i]+",";
}
}
-
+
//remove the extra ","
dlURL = dlURL.slice(0,-1);
-
+
}
-
+
var imgWidth=0; var imgHeight=0;
-
+
$("select#selImgResolution").change(function () {
- imgRes = $("#selImgResolution option:selected").val();
+ imgRes = $("#selImgResolution option:selected").val();
imgWidth = Math.round((Math.abs(lonlat2.lon - lonlat1.lon) / conversionFactor) / Number(imgRes));
- imgHeight = Math.round((Math.abs(lonlat2.lat - lonlat1.lat) / conversionFactor) / Number(imgRes));
+ imgHeight = Math.round((Math.abs(lonlat2.lat - lonlat1.lat) / conversionFactor) / Number(imgRes));
imgFilesize = (( imgWidth * imgHeight * 24) / 8388608).toFixed(2);
-
+
$("#imgWidth").text((imgWidth));
$("#imgHeight").text((imgHeight));
$("#imgFileSize").text(imgFilesize);
@@ -203,15 +218,15 @@ SOTE.widget.ImageDownload.prototype.updateComponent = function(qs){
else { $("#imgFileSize").css("color", "white"); $("#btnImgDownload").removeAttr("disabled"); }
})
.change();
-
-
+
+
$("#btnImgDownload").unbind('click').click(function(){
ntptEventTag('lc='+encodeURIComponent(dlURL+"&format="+$("#selImgFormat option:selected").val()+"&width="+$("#imgWidth").text()+"&height="+$("#imgHeight").text() ) );
window.open(dlURL+"&format="+$("#selImgFormat option:selected").val()+"&width="+$("#imgWidth").text()+"&height="+$("#imgHeight").text(),"_blank");
});
-
+
this.setValue(dlURL);
- } catch ( cause ) {
+ } catch ( cause ) {
Worldview.error("Unable to update download box", cause);
}
};
@@ -220,7 +235,7 @@ SOTE.widget.ImageDownload.prototype.updateComponent = function(qs){
/**
* Sets the URL from the querystring
- *
+ *
* @this {Download}
* @param {String} qs contains the querystring (must contain [containerId]=[selectedDate] in the string)
* @returns {boolean} true or false depending on if the extracted date validates
@@ -231,7 +246,7 @@ SOTE.widget.ImageDownload.prototype.loadFromQuery = function(qs){
};
/**
- * Validates that the selected URL is valid
+ * Validates that the selected URL is valid
* @this {Download}
* @returns {boolean} true or false depending on whether the date is not null and within bounds
*/
@@ -243,7 +258,7 @@ SOTE.widget.ImageDownload.prototype.validate = function(){
* Sets the accessor that provides state change instructions given dependencies
*
* @this {Download}
- * @param {String} sourceurl is the relative location of the accessor
+ * @param {String} sourceurl is the relative location of the accessor
*
*/
SOTE.widget.ImageDownload.prototype.setSourceUrl = function(sourceurl){
@@ -252,7 +267,7 @@ SOTE.widget.ImageDownload.prototype.setSourceUrl = function(sourceurl){
/**
* Gets the accessor
- *
+ *
* @this {Download}
* @returns {String} the relative location of the accessor
*
diff --git a/src/js/main.js b/src/js/main.js
index f6c082a9b..ba6a56918 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -1,36 +1,36 @@
$(function() {// Initialize "static" vars
var log = Logging.getLogger();
-
- var entryPoint = function() {
-
+
+ var entryPoint = function() {
+
// Error handlers
Worldview.Events.errorHandler = function(error) {
Worldview.error("Internal error", error);
};
-
- // Place any quirky browser related items in the function called
+
+ // Place any quirky browser related items in the function called
// below.
Worldview.Support.quirks();
-
+
// A message can be displayed to the user (for example, notification
- // of a pending outage) by adding a notice.txt file in the web root
+ // of a pending outage) by adding a notice.txt file in the web root
$.get("var/notice.txt", function(message) {
var html = message.replace(/\n/g, "<br/>");
Worldview.notify(html);
});
-
- // Place any resources that should be completely loaded before
+
+ // Place any resources that should be completely loaded before
// starting up the UI
Worldview.Preloader([
{ id: "config", type:"json",
src: "data/config.json?v=" + Worldview.BUILD_NONCE },
// FIXME: Projection cache HACK
- { id: "geographic", type: "json",
- src: "data/geographic_ap_products.json?v=" + Worldview.BUILD_NONCE },
- { id: "arctic", type: "json",
- src: "data/arctic_ap_products.json?v=" + Worldview.BUILD_NONCE },
- { id: "antarctic", type: "json",
+ { id: "geographic", type: "json",
+ src: "data/geographic_ap_products.json?v=" + Worldview.BUILD_NONCE },
+ { id: "arctic", type: "json",
+ src: "data/arctic_ap_products.json?v=" + Worldview.BUILD_NONCE },
+ { id: "antarctic", type: "json",
src: "data/antarctic_ap_products.json?v=" + Worldview.BUILD_NONCE },
"images/logo.png",
"images/permalink.png",
@@ -49,7 +49,7 @@ $(function() {// Initialize "static" vars
"images/expandUp.png",
"images/activity.gif",
"images/wv-icons.svg",
- "images/wv-logo.svg"
+ "images/wv-logo.svg"
]).execute(onLoad);
};
@@ -67,9 +67,9 @@ $(function() {// Initialize "static" vars
Worldview.error("Unable to start Worldview", error);
}
};
- var storageEngine;
- var init = function(config) {
-
+ var storageEngine;
+ var init = function(config) {
+
// set up storage and decide what to show
try {
storageEngine = YAHOO.util.StorageManager.get(
@@ -85,7 +85,7 @@ $(function() {// Initialize "static" vars
alert("No supported storage mechanism present");
storageEngine = false;
}
-
+
var hideSplash, eventsCollapsed, lastVisit;
if(storageEngine) {
storageEngine.subscribe(storageEngine.CE_READY, function() {
@@ -93,7 +93,7 @@ $(function() {// Initialize "static" vars
eventsCollapsed = storageEngine.getItem('eventsCollapsed');
lastVisit = storageEngine.getItem('lastVisit');
});
-
+
if(!lastVisit) {
lastVisit = Date.now();
}
@@ -102,28 +102,28 @@ $(function() {// Initialize "static" vars
//var lastVisitObj = new Date(lastVisit);
var lastVisitObj = new Date("2013-04-07T00:00:00-04:00"); // FIXME
// get query string
- var queryString =
+ var queryString =
Worldview.Permalink.decode(window.location.search.substring(1));
-
- // Convert all parameters found in the query string to an object,
- // keyed by parameter name
+
+ // Convert all parameters found in the query string to an object,
+ // keyed by parameter name
config.parameters = Worldview.queryStringToObject(location.search);
-
+
// Features that are important for debugging but are not necessary
// for Worldview to opeerate properly
debuggingFeatures(config);
-
+
// Models
var dataDownloadModel = Worldview.DataDownload.Model(config);
- // Create widgets
+ // Create widgets
var projection = new SOTE.widget.Switch("switch", {
dataSourceUrl:"a",
selected:"geographic"
});
var palettes = Worldview.Widget.Palette("palettes", config, {
alignTo: "#products"
- });
+ });
var products = new SOTE.widget.Products("productsHolder", {
paletteWidget: palettes,
config: config
@@ -141,15 +141,16 @@ $(function() {// Initialize "static" vars
});
var imageDownload = new SOTE.widget.ImageDownload("imagedownload", {
baseLayer: "MODIS_Terra_CorrectedReflectance_TrueColor",
- alignTo: rubberBand,
- m: map
- });
+ alignTo: rubberBand,
+ m: map,
+ config: config
+ });
var apcn = new Worldview.Widget.ArcticProjectionChangeNotification(
config, products.b
);
var opacity = new Worldview.Widget.Opacity(config);
var crs = new Worldview.Widget.CRS(config);
-
+
// collapse events if worldview is being loaded via permalink
if(queryString) {
eventsCollapsed = true;
@@ -157,7 +158,7 @@ $(function() {// Initialize "static" vars
if ( config.parameters.events ) {
var events = new SOTE.widget.Events("eventsHolder", {
config: config,
- mapWidget: map,
+ mapWidget: map,
paletteWidget: palettes,
switchWidget: projection,
bankWidget: products,
@@ -169,10 +170,10 @@ $(function() {// Initialize "static" vars
lastVisit: lastVisitObj
});
}
-
+
var dataDownload = Worldview.Widget.DataDownload(config, {
selector: "#DataDownload",
- model: dataDownloadModel,
+ model: dataDownloadModel,
maps: map.maps,
paletteWidget: palettes
});
@@ -197,23 +198,23 @@ $(function() {// Initialize "static" vars
map.maps.events
.on("moveEnd", function(map) {
dataDownload.onViewChange(map);
- })
+ })
.on("zoomEnd", function(map) {
dataDownload.onViewChange(map);
- });
+ });
dataDownloadModel.events
.on("queryResults", function() {
- dataDownload.onViewChange(map.maps.map);
+ dataDownload.onViewChange(map.maps.map);
});
// Register event listeners
- REGISTRY.addEventListener("time",
- "map", "imagedownload", apcn.containerId, crs.containerId,
+ REGISTRY.addEventListener("time",
+ "map", "imagedownload", apcn.containerId, crs.containerId,
dataDownload.containerId);
- REGISTRY.addEventListener("switch",
- "map", "products", "selectorbox", "imagedownload", "camera",
+ REGISTRY.addEventListener("switch",
+ "map", "products", "selectorbox", "imagedownload", "camera",
apcn.containerId, crs.containerId, dataDownload.containerId);
- REGISTRY.addEventListener("products",
- "map", "selectorbox", "imagedownload", "palettes",
+ REGISTRY.addEventListener("products",
+ "map", "selectorbox", "imagedownload", "palettes",
apcn.containerId, dataDownload.containerId);
REGISTRY.addEventListener("selectorbox","products");
REGISTRY.addEventListener("camera","imagedownload");
@@ -224,71 +225,71 @@ $(function() {// Initialize "static" vars
// These are only convienence handles to important objects used
// for console debugging. Code should NOT reference these as they
// are subject to change or removal.
- Worldview.config = config;
+ Worldview.config = config;
Worldview.opacity = opacity;
- Worldview.palettes = palettes;
+ Worldview.palettes = palettes;
Worldview.view = map;
Worldview.ddm = dataDownloadModel;
Worldview.maps = map.maps;
-
+
// Initialize widgets
-
+
var initOrder = [
- projection,
+ projection,
products.b, // bank
- date,
- map,
+ date,
+ map,
palettes,
apcn,
opacity,
crs,
dataDownload
];
-
+
// Init
if (queryString.length > 0) {
REGISTRY.isLoadingQuery = true;
$.each(initOrder, function(index, component) {
- component.loadFromQuery(queryString);
+ component.loadFromQuery(queryString);
});
REGISTRY.isLoadingQuery = false;
}
-
+
// Console notifications
var banner = Worldview.NAME + " - Version " + Worldview.VERSION;
if ( !Worldview.isDevelopment() ) {
banner += " - " + Worldview.BUILD_TIMESTAMP;
- }
+ }
log.info(banner);
if ( Worldview.isDevelopment() ) {
log.warn("Development version");
}
-
- // Do not start the tour if coming in via permalink
- if ( !queryString ) {
- Worldview.Tour.start(storageEngine, hideSplash, false);
- }
-
+
+ // Do not start the tour if coming in via permalink
+ if ( !queryString ) {
+ Worldview.Tour.start(storageEngine, hideSplash, false);
+ }
+
if ( events ) {
window.onbeforeunload = function(){
storageEngine.setItem('eventsCollapsed', events.isCollapsed);
};
}
};
-
+
var debuggingFeatures = function(config) {
// Allow the current day to be overridden
if ( config.parameters.now ) {
try {
var now = Date.parseISOString(config.parameters.now);
Worldview.overrideNow(now);
- log.warn("Overriding now: " + now.toISOString());
+ log.warn("Overriding now: " + now.toISOString());
} catch ( error ) {
log.error("Invalid now: " + query.now, error);
- }
+ }
}
-
- // Install a black palette which can be used to find "holes" in
+
+ // Install a black palette which can be used to find "holes" in
// LUT mappings.
if ( Worldview.isDevelopment() ) {
var debugPalette = Worldview.Palette.Palette({
@@ -298,14 +299,14 @@ $(function() {// Initialize "static" vars
});
config.palettes["__DEBUG"] = debugPalette;
config.paletteOrder.unshift("__DEBUG");
- }
+ }
};
-
+
try {
- entryPoint();
+ entryPoint();
} catch ( cause ) {
Worldview.error("Failed to start Worldview", cause);
- }
-
+ }
+
});