Interactive interface for browsing global, full-resolution satellite imagery
Update gif.js to use local gif-creater #816
Benjamin King2bedd01d7bf2
diff --git a/web/js/animation/gif.js b/web/js/animation/gif.jsindex 76e8da2e7..434787bd2 100644--- a/web/js/animation/gif.js+++ b/web/js/animation/gif.js@@ -2,7 +2,7 @@ import $ from 'jquery';import 'jquery-jcrop';import React from 'react';import ReactDOM from 'react-dom';-import gifshot from 'gifshot';+import GifCreater from './gif-creater';import lodashFind from 'lodash/find';import lodashEach from 'lodash/each';import lodashRound from 'lodash/round';@@ -21,6 +21,7 @@ import {import util from '../util/util';import wvui from '../ui/ui';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.6xconst maxGifSize = 40;@@ -33,6 +34,7 @@ const PALETTE_WARNING ='snapshot. Would you like to temporarily revert to the original ' +'layer(s)?';const ROTATE_WARNING = 'Image may not be downloaded when rotated. Would you like to reset rotation?';+const resolutionsGeo = {values: [{ value: '0.125', text: '30m' },@@ -241,19 +243,20 @@ export function animationGif(models, config, ui) {$progress.attr('value', captureProgress); // before value set, it is in indeterminate state};- imageArra = getImageArray(startDate, endDate, $progress);+ imageArra = getImageArray(startDate, endDate, interval);if (!imageArra) { // won't be true if there are too mant framesreturn;}- gifshot.createGIF({+ gifCreater.createGIF({'gifWidth': imgWidth,'gifHeight': imgHeight,'images': imageArra,- 'stamp': stampHeight > 20 ? stamp : null,+ 'waterMarkXCoordinate': stampHeight * 0.01, // Margin based on GIF Height+ 'waterMarkYCoordinate': stampHeight * 0.01, // Margin based on GIF Height+ 'waterMarkHeight': stamp.height,+ 'waterMark': stampHeight > 20 ? stamp : null,+ 'waterMarkWidth': stamp.width,'fontSize': dateStamp.fontSize + 'px',- 'stampHeight': stamp.height,- 'stampWidth': stamp.width,- 'stampCoordinates': { x: stampHeight * 0.01, y: stampHeight * 0.01 }, // Margin based on GIF width'textXCoordinate': dateStamp.x,'textYCoordinate': dateStamp.y, // date location based on Dimensions'textAlign': dateStamp.align, // If textXCoordinate is null this takes precedence@@ -261,9 +264,10 @@ export function animationGif(models, config, ui) {'fontColor': '#fff','fontWeight': '300','fontFamily': 'Open Sans, sans-serif',- 'interval': 1 / interval,'progressCallback': onGifProgress,'showFrameText': stampHeight > 20,+ 'extraLastFrameDelay': 1000,+ 'text': '','stroke': {'color': '#000','pixels': dateStamp.fontSize * 0.05@@ -433,7 +437,7 @@ export function animationGif(models, config, ui) {* @returns {array} array of jpg urls**/- var getImageArray = function(startDate, endDate) {+ var getImageArray = function(startDate, endDate, interval) {var url;var a = [];var fromDate = new Date(startDate);@@ -473,14 +477,11 @@ export function animationGif(models, config, ui) {opacities = imageUtilGetLayerOpacities(products);url = util.format(host + '/' + path + '?{1}&extent={2}&epsg={3}&layers={4}&opacities={5}&worldfile=false&format=image/jpeg&width={6}&height={7}', 'TIME={1}', lonlat[0][0] + ',' + lonlat[0][1] + ',' + lonlat[1][0] + ',' + lonlat[1][1], epsg, layers.join(','), opacities.join(','), imgWidth, imgHeight);src = util.format(url, strDate);- if (showDates) {- a.push({- src: src,- text: strDate- });- } else {- a.push(src);- }+ a.push({+ src: src,+ text: showDates ? strDate : '',+ delay: 1000 / interval+ });if (ui.anim.ui.getInterval() === 'minute') {intervalAmount = 10;} else {@@ -547,31 +548,13 @@ export function animationGif(models, config, ui) {* @returns {void}**/- var onGifComplete = function(obj) { // callback function for when image is finished+ var onGifComplete = function(blob) { // callback function for when image is finished$('#timeline-footer').removeClass('wv-anim-active');models.anim.rangeState.state = 'off';- if (obj.error === false) {- $progress.remove();+ if (blob) {progressing = false;var animatedImage = document.createElement('img');- // Create a blob out of the image's base64 encoding because Chrome can't handle large data URIs, taken from:- // http://stackoverflow.com/questions/16761927/aw-snap-when-data-uri-is-too-large- var byteCharacters = atob(obj.image.substring(22));- var byteArrays = []; // remove "data:image/gif;base64,"- for (var offset = 0; offset < byteCharacters.length; offset += 512) {- var slice = byteCharacters.slice(offset, offset + 512);-- var byteNumbers = new Array(slice.length);- for (var i = 0; i < slice.length; i++) { byteNumbers[i] = slice.charCodeAt(i); }-- var byteArray = new Uint8Array(byteNumbers);- byteArrays.push(byteArray);- }-- var blob = new Blob(byteArrays, {- type: 'image/gif'- });var blobURL = URL.createObjectURL(blob); // supported in Chrome and FFanimatedImage.src = blobURL;animatedImage.width = lastRequestedDimensions.w > window.innerWidth - 198 ? window.innerWidth - 198 : lastRequestedDimensions.w;