Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

built/building gif download

Benjamin1ef03cf3b62c
diff --git a/web/js/animation/wv.anim.gif.js b/web/js/animation/wv.anim.gif.js
index e3f7e9a57..88f6c8c39 100644
--- a/web/js/animation/wv.anim.gif.js
+++ b/web/js/animation/wv.anim.gif.js
@@ -17,19 +17,28 @@ wv.anim = wv.anim || {};
wv.anim.gif = wv.anim.gif || function(models, config, ui) {
var self = {};
+ var animCoords = null;
var $cropee = $("#wv-map");
var jcropAPI = null;
var coords = null;
var animCoords = null;
var previousCoords = null;
+ var animModel = models.anim;
+ var modalWidth = 200;
var GRATICLE_WARNING =
"The graticule layer cannot be used to take a snapshot. Would you " +
"like to hide this layer?";
var ROTATE_WARNING = "Image may not be downloaded when rotated. Would you like to reset rotation?";
+
+
+ self.init = function() {
+ models.anim.events.on('gif-click', setImageCoords);
+ };
+ self.createGIF = function() {
+ var interval = animModel.rangeState.speed / 1000;
- var createGif = function() {
$progress = $("<progress />") //display progress for GIF creation
.attr("id", "wv-gif-progress");
@@ -83,12 +92,11 @@ wv.anim.gif = wv.anim.gif || function(models, config, ui) {
return str;
}
};
- self.getGif = function(startDate, endDate, delta, interval) {
+ self.getGif = function() {
var layers;
//check for rotation, changed palettes, and graticule layers and ask for reset if so
//ui.anim.stop(); Add this
-
layers = models.layers.get({renderable: true});
if (models.palettes.inUse()) {
wv.ui.ask({
@@ -97,7 +105,7 @@ wv.anim.gif = wv.anim.gif || function(models, config, ui) {
onOk: function() {
previousPalettes = models.palettes.active;
models.palettes.clear();
- self.getGif(startDate, endDate, delta, interval);
+ self.getGif();
}
});
return;
@@ -120,12 +128,12 @@ wv.anim.gif = wv.anim.gif || function(models, config, ui) {
onOk: function() {
resetRotation();
//Let rotation finish before image download can occur
- self.getGif(startDate, endDate, delta, interval);
+ self.getGif();
}
});
return;
}
- setImageCoords();
+ self.createGIF();
};
var formImageURL = function() {
//Gather all data to get the image
@@ -160,8 +168,19 @@ wv.anim.gif = wv.anim.gif || function(models, config, ui) {
return wv.util.format("http://map2.vis.earthdata.nasa.gov/image-download?{1}&extent={2}&epsg={3}&layers={4}&opacities={5}&worldfile=false&format=image/jpeg&width={6}&height={7}", "TIME={1}", lonlat1[0]+","+lonlat1[1]+","+lonlat2[0]+","+lonlat2[1], epsg, layers.join(","), opacities.join(","), imgWidth, imgHeight);
};
var getImageArray = function (startDate, endDate) {
+ var to;
var url = formImageURL();
var a = [];
+ var delta = ui.anim.returnNumberInterval();
+ var fromDate = new Date(startDate);
+ var toDate = new Date(endDate);
+ var jStart = wv.util.parseDateUTC(fromDate.getUTCFullYear() + "-01-01");
+ var jDate = "00" + (1 + Math.ceil(toDate.getTime() - jStart) / 86400000);
+ var from = fromDate.getUTCFullYear() + (jDate).substr((jDate.length) - 3);
+
+ jStart = wv.util.parseDateUTC(toDate.getUTCFullYear() + "-01-01");
+ jDate = "00" + (1 + Math.ceil((toDate.getTime() - jStart) / 86400000));
+ to = toDate.getUTCFullYear() + (jDate).substr((jDate.length) - 3);
for(var i = parseInt(from); i <= parseInt(to); ) { //Convert to integer first. change i manually
a.push(wv.util.format(url, i));
//if the interval is in two years, take it to account
@@ -178,6 +197,7 @@ wv.anim.gif = wv.anim.gif || function(models, config, ui) {
else
i += delta;
}
+ console.log(a)
return a;
};
var resetRotation = function() {
@@ -248,13 +268,98 @@ wv.anim.gif = wv.anim.gif || function(models, config, ui) {
});
}
}
+ var calcSize = function(c) {
+ var lonlat1 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x), Math.floor(c.y2)]),
+ lonlat2 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x2), Math.floor(c.y)]);
+
+ var conversionFactor = models.proj.selected.id === "geographic" ? 0.002197 : 256, res = calcRes(0);
+
+ var imgWidth = Math.round((Math.abs(lonlat2[0] - lonlat1[0]) / conversionFactor) / Number(res)),
+ imgHeight = Math.round((Math.abs(lonlat2[1] - lonlat1[1]) / conversionFactor) / Number(res));
+
+ return ((imgWidth * imgHeight * 24) / 8388608).toFixed(2);
+ };
+ var removeCrop = function() {
+ $("#wv-map").insertAfter('#productsHolder'); //retain map element before disabling jcrop
+ animCoords = undefined;
+ jcropAPI.destroy();
+ };
+ self.getSelectorDialog = function() {
+ var $dialogBox;
+ var dialog =
+ "<div class='gifDialog'>" +
+ "<div class='content'>" +
+ "Press the Submit Icon to create an" +
+ "animation from " +
+ "<b>" +
+ animModel.rangeState.startDate +
+ "</b>" +
+ " to " +
+ "<b>" +
+ animModel.rangeState.endDate +
+ "</b>" +
+ " a rate of " +
+ animModel.rangeState.speed +
+ " frames per second" +
+
+
+ "</div>" +
+ "</div>";
+
+
+ $dialogBox = wv.ui.getDialog();
+ $dialogBox.html(dialog);
+ $dialogBox.dialog({
+ dialogClass: "wv-panel wv-image",
+ title: "Generate GIF",
+ height: 160,
+ width: modalWidth,
+ show: { effect: "slide", direction: "down" },
+ position: {
+ my: "left top",
+ at: "left bottom+10",
+ of: $(".jcrop-tracker")
+ },
+
+ close: function(event) {
+ $("#wv-map").insertAfter('#productsHolder'); //retain map element before disabling jcrop
+ jcropAPI.destroy();
+ }
+ });
+ return $dialogBox;
+ };
+ var setDialogMargin = function($dialog, width) {
+ var margin = (width - modalWidth) / 2;
+ if($dialog) {
+ $dialog.parent().position({
+ my: "left top",
+ at: "left+" + margin + " bottom+10",
+ of: $(".jcrop-tracker")
+ });
+ }
+ };
+ var setIconFontSize = function($el, width) {
+ var fs = Math.abs(width / 4);
+ if(!$el)
+ return
+ if(fs <= 30) {
+ fs = 30;
+ };
+ $el.css('font-size', fs);
+ };
var setImageCoords = function() {
+ var starterWidth;
+ var $dlButton;
+ var $dialog;
//Set JCrop selection
if(previousCoords === null || previousCoords === undefined)
previousCoords = [($(window).width()/2)-100,($(window).height()/2)-100,($(window).width()/2)+100,($(window).height()/2)+100];
else
previousCoords = [previousCoords.x, previousCoords.y, previousCoords.x2, previousCoords.y2];
+
+
+ starterWidth = previousCoords[0] - previousCoords[2];
//Start the image cropping. Show the dialog
$("#wv-map").Jcrop({
bgColor: 'black',
@@ -267,26 +372,48 @@ wv.anim.gif = wv.anim.gif || function(models, config, ui) {
$("#wv-gif-height").html((c.h));
},
onChange: function(c) { //Update gif size and image size in MB
+ var modalLeftMargin;
animCoords = c;
+
if(c.h !== 0 && c.w !== 0) //don't save coordinates if empty selection
previousCoords = c;
var dataSize = calcSize(c);
-
//Update the gif selection dialog
- $("#wv-gif-width").html((c.w)); $("#wv-gif-height").html((c.h)); $("#wv-gif-size").html(dataSize + " MB");
+ $("#wv-gif-width").html((c.w));
+ $("#wv-gif-height").html((c.h));
+ $("#wv-gif-size").html(dataSize + " MB");
- if(dataSize > 250) //disable GIF generation if GIF would be too large
+ if(dataSize > 250) {//disable GIF generation if GIF would be too large
$("#wv-gif-button").button("disable");
- else
+ } else {
$("#wv-gif-button").button("enable");
+ }
+ setDialogMargin($dialog, c.w);
+ setIconFontSize($dlButton, c.w);
},
onRelease: function(c) {
removeCrop();
- $dialog.dialog("close");
+ if($dialog) {
+ wv.ui.close();
+ }
}
}, function() {
+ var $tracker;
+ $dlButton = "<div class='wv-dl-gif-bt-case'>" +
+ "<i class='fa fa-check-square'>" +
+ "</div>";
jcropAPI = this;
+ $dialog = self.getSelectorDialog();
+ setDialogMargin($dialog, starterWidth);
+ $tracker = this.ui.selection.find('.jcrop-tracker');
+ $tracker.append($dlButton);
+ $dlButton = $('.wv-dl-gif-bt-case i');
+ setIconFontSize($dlButton, starterWidth);
+ $dlButton.on('click', self.getGif);
+
+
});
};
+ self.init();
return self;
}
diff --git a/web/js/animation/wv.anim.ui.js b/web/js/animation/wv.anim.ui.js
index 0c2f18ad7..5905f60c1 100644
--- a/web/js/animation/wv.anim.ui.js
+++ b/web/js/animation/wv.anim.ui.js
@@ -16,6 +16,7 @@ wv.anim.ui = wv.anim.ui || function(models, ui) {
var queueLength = 5;
var animateArray;
var map = ui.map.selected;
+ var zooms = ['year', 'month', 'day']
self.delay = 500;
self.direction = "forward";
self.interval = "day";
@@ -35,7 +36,6 @@ wv.anim.ui = wv.anim.ui || function(models, ui) {
animModel.events.on('play', self.onPushedPlay);
animModel.events.on('datechange', self.refreshState);
map.getView().on('moveend', self.refreshState);
-
}
self.refreshState = function() {
self.state = {
@@ -71,12 +71,26 @@ wv.anim.ui = wv.anim.ui || function(models, ui) {
self.preload(startDate, endDate, fps);
};
+ self.getInterval = function() {
+ return zooms[ui.timeline.config.currentZoom - 1];
+ };
+ //Determine interval for updating date
+ self.returnNumberInterval = function() {
+ var interval = self.getInterval();
+ if (interval === 'month')
+ return 30;
+ else if (interval === 'year')
+ return 365;
+ else
+ return 1;
+ };
self.preload = function(dateBeingProcessed, endDate, fps) {
var dateArray = [];
var chunkedArray= [];
var i = 1;
var date;
var thisState = self.state;
+ var timeline = ui.timeline;
if(!thisState.fullyLoaded) {
animateArray = [];
@@ -110,7 +124,7 @@ wv.anim.ui = wv.anim.ui || function(models, ui) {
}
}
while(dateBeingProcessed <= endDate) {
- dateBeingProcessed = wv.util.dateAdd(dateBeingProcessed, 'day', 1);
+ dateBeingProcessed = wv.util.dateAdd(dateBeingProcessed, zooms[timeline.config.currentZoom - 1], 1);
date = new Date(dateBeingProcessed);
dateArray.push(date);
}
diff --git a/web/js/util/wv.util.js b/web/js/util/wv.util.js
index c550a7982..88cd20efe 100644
--- a/web/js/util/wv.util.js
+++ b/web/js/util/wv.util.js
@@ -672,7 +672,17 @@ wv.util = (function(self) {
coord[0].toFixed(4) + "&deg;";
}
};
-
+ //allows simple printf functionality with strings
+ //arguments array contains all args passed. String must be formatted so that first replacement starts with "{1}"
+ //usage example: wv.util.format("{1}{2}",'World','view')
+ self.format = function() {
+ var formatted = arguments[0];
+ for (var i = 1; i < arguments.length; i++) {
+ var regexp = new RegExp('\\{'+i+'\\}', 'gi');
+ formatted = formatted.replace(regexp, arguments[i]);
+ }
+ return formatted;
+ };
self.toArray = function(value) {
if ( !value ) {
return [];
diff --git a/web/js/wv.main.js b/web/js/wv.main.js
index 116b495d1..b3ab1f663 100644
--- a/web/js/wv.main.js
+++ b/web/js/wv.main.js
@@ -169,6 +169,7 @@ $(function() {
ui.timeline.input = wv.date.timeline.input(models, config, ui);
ui.anim.rangeselect = wv.anim.rangeselect(models, config, ui); // SETS STATE: NEEDS TO LOAD BEFORE ANIMATION WIDGET
ui.anim.widget = wv.anim.widget(models, config, ui);
+ ui.anim.gif = wv.anim.gif(models, config, ui);
ui.dateLabel = wv.date.label(models);
}