Interactive interface for browsing global, full-resolution satellite imagery
Fix progress callback #969
Benjamin Kingb1038c7f9da5
diff --git a/web/js/animation/gif-creater.js b/web/js/animation/gif-creater.jsindex acd3ab9c3..4d8602db9 100644--- a/web/js/animation/gif-creater.js+++ b/web/js/animation/gif-creater.js@@ -81,6 +81,7 @@ export default class gifCreater {this.options = options;this.canvas.width = options.gifWidth;this.canvas.height = options.gifHeight;+var imagePromiseArray = [];lodashEach(options.images, (imageObj) => {imagePromiseArray.push(this.getImagePromise(imageObj).catch(returnError));@@ -96,28 +97,33 @@ export default class gifCreater {var gifStream = this.getStream(images, this.ctx);var reader = gifStream.getReader();var chunks = [];+ var processedImages = 1;+ function finished(chunks) {+ const callbackObj = {+ blob: new Blob(chunks, { type: 'image/gif' }),+ error: ''+ };+ callback(callbackObj);+ };function pull() {+ const imageLength = options.images.length;return reader.read().then(function (result) {const chunk = result.value;- if (chunk) {+ if (result.done) {+ finished(chunks);+ } else {chunks.push(new Uint8Array(chunk));- // for (var offset = 0; offset < chunk.length; offset += 512) {- // let sliceOfChunk = chunk.slice(offset, offset + 512);- // let byteArray = new Uint8Array(sliceOfChunk);- // chunks.push(byteArray);- // }+ options.progressCallback(Math.round((processedImages / imageLength) * 100));+ processedImages++;+ setTimeout(function() { // This was needed in order for callback to be applied+ return pull();+ }, 10);}- return result.done ? chunks : pull();});};- pull().then(function (chunks) {- const callbackObj = {- blob: new Blob(chunks, { type: 'image/gif' }),- error: ''- };- callback(callbackObj);- });+ options.progressCallback(0);+ pull();});}getImagePromise(frame) {@@ -164,7 +170,6 @@ export default class gifCreater {var delay = (frame.delay) ? frame.delay / 10 : 100;processedImages++;delay = (processedImages === totalImages && options.extraLastFrameDelay) ? delay + (options.extraLastFrameDelay / 10) : delay;// Add an extra- options.progressCallback(Math.round((processedImages / totalImages) * 100));ctx = self.addFrameDetails(ctx, frame);imgData = ctx.getImageData(0, 0, width, height);rgbComponents = dataToRGB(imgData.data, imgData.height, imgData.height);diff --git a/web/js/animation/gif.js b/web/js/animation/gif.jsindex 28dfa5ab3..508083322 100644--- a/web/js/animation/gif.js+++ b/web/js/animation/gif.js@@ -232,14 +232,15 @@ export function animationGif(models, config, ui) {var onGifProgress = function(captureProgress) {$('#timeline-footer').removeClass('wv-anim-active');models.anim.rangeState.state = 'off';+if (!progressing) {buildProgressBar();progressing = true;uiIndicator.hide(loader);+ $progress.parent()+ .dialog('option', 'title', 'Creating GIF...'); // set dialog title}- $progress.parent()- .dialog('option', 'title', 'Creating GIF...'); // set dialog title- $progress.attr('value', captureProgress); // before value set, it is in indeterminate state+ $progress.attr('value', captureProgress / 100); // before value set, it is in indeterminate state};imageArra = getImageArray(startDate, endDate, interval);@@ -552,6 +553,7 @@ export function animationGif(models, config, ui) {models.anim.rangeState.state = 'off';if (!obj.error) {const blob = obj.blob;+ $progress.remove();progressing = false;var animatedImage = document.createElement('img');const blobURL = URL.createObjectURL(blob);