Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Add error logging and remove img listeners #816

Benjamin King14faf7e83245
diff --git a/web/js/animation/gif-creater.js b/web/js/animation/gif-creater.js
index 337864bb8..15b3d0512 100644
--- a/web/js/animation/gif-creater.js
+++ b/web/js/animation/gif-creater.js
@@ -78,26 +78,35 @@ export default class gifCreater {
var chunks = [];
var imagePromiseArray = [];
lodashEach(options.images, (imageObj) => {
- imagePromiseArray.push(this.getImagePromise(imageObj));
+ imagePromiseArray.push(this.getImagePromise(imageObj).catch(returnError));
});
+ function returnError(e) {
+ const callbackObj = {
+ blob: null,
+ error: e
+ };
+ callback(callbackObj);
+ }
Promise.all(imagePromiseArray).then((images) => {
var gifStream = this.getStream(images, ctx);
var reader = gifStream.getReader();
-
- var pull = function() {
+ function pull() {
return reader.read().then(function (result) {
chunks.push(result.value);
return result.done ? chunks : pull();
});
};
-
pull().then(function (chunks) {
- callback(new Blob(chunks, { type: 'image/gif' }));
+ const callbackObj = {
+ blob: new Blob(chunks, { type: 'image/gif' }),
+ error: ''
+ };
+ callback(callbackObj);
});
});
}
getImagePromise(frame) {
- return new Promise((resolve) => {
+ return new Promise((resolve, reject) => {
var img = new Image();
img.width = this.options.gifWidth;
img.height = this.options.gifHeight;
@@ -106,6 +115,13 @@ export default class gifCreater {
img.crossOrigin = 'Anonymous';
img.onload = () => {
resolve(img);
+ delete img.onload;
+ delete img.onerror;
+ };
+ img.onerror = (e) => {
+ reject(e);
+ delete img.onload;
+ delete img.onerror;
};
img.src = frame.src;
});
diff --git a/web/js/animation/gif.js b/web/js/animation/gif.js
index 434787bd2..00338101c 100644
--- a/web/js/animation/gif.js
+++ b/web/js/animation/gif.js
@@ -24,7 +24,7 @@ import uiIndicator from '../ui/indicator';
const gifCreater = new GifCreater();
const conversionConstant = 3.6; // we are saying that the gif compresses each total by about 3.6x
-const maxGifSize = 40;
+const maxGifSize = 250;
const GRATICULE_WARNING =
'The graticule layer cannot be used to take a snapshot. Would you ' +
'like to hide this layer?';
@@ -548,14 +548,14 @@ export function animationGif(models, config, ui) {
* @returns {void}
*
*/
- var onGifComplete = function(blob) { // callback function for when image is finished
+ var onGifComplete = function(obj) { // callback function for when image is finished
$('#timeline-footer').removeClass('wv-anim-active');
models.anim.rangeState.state = 'off';
- if (blob) {
+ if (!obj.error) {
+ const blob = obj.blob;
progressing = false;
var animatedImage = document.createElement('img');
-
- var blobURL = URL.createObjectURL(blob); // supported in Chrome and FF
+ const blobURL = URL.createObjectURL(blob);
animatedImage.src = blobURL;
animatedImage.width = lastRequestedDimensions.w > window.innerWidth - 198 ? window.innerWidth - 198 : lastRequestedDimensions.w;
animatedImage.height = lastRequestedDimensions.h > window.innerHeight - 120 ? window.innerHeight - 120 : lastRequestedDimensions.h;