Interactive interface for browsing global, full-resolution satellite imagery
move remove edsc and move gifstream into modules #3647
Ben04b58a3436fd
diff --git a/.eslintignore b/.eslintignoreindex 64e7a1501..f52ad534d 100644--- a/.eslintignore+++ b/.eslintignore@@ -10,6 +10,5 @@ web/ext/*web/dist/*web/build/*test/*-web/js/edsc/*web/js/lib/*diff --git a/web/js/containers/gif.js b/web/js/containers/gif.jsindex 35e037748..068d95064 100644--- a/web/js/containers/gif.js+++ b/web/js/containers/gif.js@@ -7,7 +7,7 @@ import { debounce as lodashDebounce, round as lodashRound } from 'lodash';import {Progress, Modal, ModalBody, ModalHeader,} from 'reactstrap';-import GifStream from '../lib/gifstream';+import GifStream from '../modules/animation/gifstream';import GifPanel from '../components/animation-widget/gif-panel';import util from '../util/util';diff --git a/web/js/edsc.js b/web/js/edsc.jsdeleted file mode 100644index a93ebad7a..000000000--- a/web/js/edsc.js+++ /dev/null@@ -1,81 +0,0 @@-import edscArc from './edsc/arc';-import edscCoordinate from './edsc/coordinate';-import edscGeoUtil from './edsc/geoutil';-import edscInterpolation from './edsc/interpolation';-import edscSphericalPolygon from './edsc/spherical-polygon';--const edsc = {};-edsc.map = {};-edsc.config = null;--const L = {};-edsc.L = L;-L.Polyline = {- prototype: {},-};--L.Polygon = {- extend() {},- prototype: {},-};--L.Rectangle = {- prototype: {},-};--L.LayerGroup = {- prototype: {},-};--L.FeatureGroup = {- prototype: {},-};--L.EditToolbar = {- Delete: {- prototype: {- _removeLayer: {},- },- },-};--L.Draw = {- Polygon: {- extend() {},- },-};--L.Edit = {- Poly: {- extend() {},- },-};--L.Util = {- isArray(value) {- return value.constructor === Array;- },-};-function LatLng(lat, lng) {- if (lat.lat) {- const latlng = lat;- this.lat = latlng.lat;- this.lng = latlng.lng;- } else {- this.lat = lat;- this.lng = lng;- }-}--L.LatLng = LatLng;-L.latLng = function(lat, lng) {- return new L.LatLng(lat, lng);-};-edsc.Coordinate = edscCoordinate(L);-edsc.Arc = edscArc(L, edsc.Coordinate);-edsc.geoutil = edscGeoUtil(L, edsc.Coordinate, edsc.Arc, edsc.config);-edsc.interpolation = edscInterpolation(L, edsc.geoutil.gcInterpolate);-edsc.L.sphericalPolygon = edscSphericalPolygon(L, edsc.geoutil, edsc.Arc, edsc.Coordinate);--// eslint-disable-next-line import/prefer-default-export-export { L as dataHelper };diff --git a/web/js/edsc/arc.js b/web/js/edsc/arc.jsdeleted file mode 100644index 293ae977b..000000000--- a/web/js/edsc/arc.js+++ /dev/null@@ -1,90 +0,0 @@-export default function (L, Coordinate) {- var Arc, EPSILON;- // A small number for dealing with near-0- EPSILON = 0.00000001;-- // Method for dealing with operations on great circle arcs- Arc = (function () {- function Arc (coordA, coordB) {- var ref;- if (coordB.theta < coordA.theta) {- ref = [coordA, coordB], coordB = ref[0], coordA = ref[1];- }- if (coordB.theta - coordA.theta > Math.PI) {- this.coordB = coordA;- this.coordA = coordB;- } else {- this.coordA = coordA;- this.coordB = coordB;- }- this.normal = this.coordA.cross(this.coordB);- }-- Arc.prototype.antimeridianCrossing = function () {- var abs, x, xN, y, yA, yN, z, zN;- abs = Math.abs;-- // Doesn't cross the meridian- if (this.coordA.theta < this.coordB.theta) {- return null;- }- // On the meridian- if (abs(Math.PI - abs(this.coordA.theta)) < EPSILON || abs(Math.PI - abs(this.coordB.theta)) < EPSILON) {- return null;- }- // On a longitude line- if (abs(this.coordA.theta - this.coordB.theta) % Math.PI < EPSILON) {- return null;- }- xN = this.normal.x;- yN = this.normal.y;- zN = this.normal.z;-- /**- * We have two vectors and a normal vector. We need to find a third- * vector which passes through the (anti-)meridian (y = 0) and whose- * normal vector with either @coordA or @coordB is @normal (or at least- * points in the same direction).- *- * xN = yA * z - zA * y- * yN = zA * x - xA * z- * zN = xA * y - yA * x- *- * x = - zN / yA- * y = 0- * z = xN / yA- *- * We need to be careful of two things here. First, yA cannot be 0,- * in other words our chosen arc endpoint cannot itself be on the meridian- */- yA = this.coordA.y;- if (abs(yA) < EPSILON) {- yA = this.coordB.y;- }-- // If they're both on the meridian, bail- if (abs(yA) < EPSILON) {- return null;- }-- // Second, the normal directions zN and xN cannot both be 0. This happens- // when the arc follows the meridian, so in theory this case should never occur.- if (abs(zN) < EPSILON && abs(xN) < EPSILON) {- return null;- }- x = -zN / yA;- y = 0;- z = xN / yA;-- // Finally, we need <x, y, z> to point in the direction of the anti-meridian- if (x > 0) {- x = -x;- z = -z;- }- return Coordinate.fromXYZ(x, y, z);- };-- return Arc;- })();- return Arc;-}diff --git a/web/js/edsc/coordinate.js b/web/js/edsc/coordinate.jsdeleted file mode 100644index 3ebe705c4..000000000--- a/web/js/edsc/coordinate.js+++ /dev/null@@ -1,124 +0,0 @@-export default function(L) {- var slice, Coordinate, DEG_TO_RAD, RAD_TO_DEG;-- slice = [].slice;- DEG_TO_RAD = Math.PI / 180;- RAD_TO_DEG = 180 / Math.PI;-- /**- * Method for dealing with conversions between lat/lng, phi/theta, and x/y/z as well- * as operations on the various forms.- * Consider properties on this class to be immutable. Changing, say, 'x' will not- * update `phi` or `theta` and will throw normalization out of whack.- */- Coordinate = (function () {- Coordinate.fromLatLng = function () {- var args, lat, lng, ref;- args = arguments.length >= 1 ? slice.call(arguments, 0) : [];- if (args.length === 1) {- ref = args[0], lat = ref.lat, lng = ref.lng;- } else {- lat = args[0], lng = args[1];- }- return Coordinate.fromPhiTheta(lat * DEG_TO_RAD, lng * DEG_TO_RAD);- };-- Coordinate.fromPhiTheta = function (phi, theta) {- var PI, cos, sin, x, y, z;- PI = Math.PI;- cos = Math.cos;- sin = Math.sin;-- // Normalize phi to the interval [-PI / 2, PI / 2]- while (phi >= PI) {- phi -= 2 * PI;- }- while (phi < PI) {- phi += 2 * PI;- }- if (phi > PI / 2) {- phi = PI - phi;- theta += PI;- }- if (phi < -PI / 2) {- phi = -PI - phi;- theta += PI;- }- while (theta >= PI) {- theta -= 2 * PI;- }- while (theta < -PI) {- theta += 2 * PI;- }- x = cos(phi) * cos(theta);- y = cos(phi) * sin(theta);- z = sin(phi);- return new Coordinate(phi, theta, x, y, z);- };-- /**- * +X axis passes through the (anti-)meridian at the equator- * +Y axis passes through 90 degrees longitude at the equator- * +Z axis passes through the north pole- */- Coordinate.fromXYZ = function (x, y, z) {- var d, phi, scale, theta;- d = x * x + y * y + z * z;- if (d === 0) { // Should never happen, but stay safe- d = x = 1;- }- // We normalize so that x, y, and z fall on a unit sphere- scale = 1 / Math.sqrt(d);- x *= scale;- y *= scale;- z *= scale;- theta = Math.atan2(y, x);- phi = Math.asin(z);- return new Coordinate(phi, theta, x, y, z);- };-- function Coordinate (phi1, theta1, x1, y1, z1) {- this.phi = phi1;- this.theta = theta1;- this.x = x1;- this.y = y1;- this.z = z1;- }-- // Dot product- Coordinate.prototype.dot = function (other) {- return this.x * other.x + this.y * other.y + this.z * other.z;- };-- // Normalized cross product- Coordinate.prototype.cross = function (other) {- var x, y, z;- x = this.y * other.z - this.z * other.y;- y = this.z * other.x - this.x * other.z;- z = this.x * other.y - this.y * other.x;- return Coordinate.fromXYZ(x, y, z);- };-- // Distance to other coordinate on a unit sphere. Same as the angle between the two points at the origin.- Coordinate.prototype.distanceTo = function (other) {- return Math.acos(this.dot(other));- };-- Coordinate.prototype.toLatLng = function () {- return new L.LatLng(RAD_TO_DEG * this.phi, RAD_TO_DEG * this.theta);- };-- Coordinate.prototype.toString = function () {- var latlng;- latlng = this.toLatLng();- return '(' + (latlng.lat.toFixed(3)) + ', ' + (latlng.lng.toFixed(3)) + ')';- };-- Coordinate.prototype.toXYZString = function () {- return '<' + (this.x.toFixed(3)) + ', ' + (this.y.toFixed(3)) + ', ' + (this.z.toFixed(3)) + '>';- };-- return Coordinate;- })();- return Coordinate;-};diff --git a/web/js/edsc/geoutil.js b/web/js/edsc/geoutil.jsdeleted file mode 100644index f55d14409..000000000--- a/web/js/edsc/geoutil.js+++ /dev/null@@ -1,274 +0,0 @@-export default function (L, Coordinate, Arc, config) {- var DEG_TO_RAD, EPSILON, NORTH_POLE, RAD_TO_DEG, SOUTH_POLE, _angleDelta, _course, _rotationDirection, area, containsPole, gcInterpolate;-- // A small number for dealing with near-0- EPSILON = 0.00000001;- NORTH_POLE = 1;- SOUTH_POLE = 2;- DEG_TO_RAD = Math.PI / 180;- RAD_TO_DEG = 180 / Math.PI;-- // Given two points, returns their midpoint along the shortest great circle between them. The- // two points may not be antipodal, since such a midpoint would be undefined- gcInterpolate = function (p1, p2) {- return (function (abs, asin, sqrt, pow, sin, cos, atan2) {- var AB, d, lat, lat1, lat2, lon, lon1, lon2, ref, ref1, x, y, z;- if ((abs(p1.lat) === (ref = abs(p2.lat)) && ref === 90)) {- return p1;- }- if (p2.lng < p1.lng) {- ref1 = [p2, p1], p1 = ref1[0], p2 = ref1[1];- }- lat1 = p1.lat * DEG_TO_RAD;- lon1 = p1.lng * DEG_TO_RAD;- lat2 = p2.lat * DEG_TO_RAD;- lon2 = p2.lng * DEG_TO_RAD;-- // https://williams.best.vwh.net/avform.htm#Dist- d = 2 * asin(sqrt(pow(sin((lat1 - lat2) / 2), 2) + cos(lat1) * cos(lat2) * pow(sin((lon1 - lon2) / 2), 2)));-- /**- * https://williams.best.vwh.net/avform.htm#Intermediate- * This is a special case where f = 1/2 and therefore A = B, allowing us- * to simplify a few expressions- */- AB = sin(d / 2) / sin(d);- x = AB * (cos(lat1) * cos(lon1) + cos(lat2) * cos(lon2));- y = AB * (cos(lat1) * sin(lon1) + cos(lat2) * sin(lon2));- z = AB * (sin(lat1) + sin(lat2));- lat = RAD_TO_DEG * atan2(z, sqrt(x * x + y * y));- lon = RAD_TO_DEG * atan2(y, x);- // Guard against the points being the same or antipodal- if (isNaN(lat) || isNaN(lon)) {- return p1;- }- while (lon < p1.lng - EPSILON) {- lon += 360;- }- while (lon > p2.lng + EPSILON) {- lon -= 360;- }- return new L.LatLng(lat, lon);- })(Math.abs, Math.asin, Math.sqrt, Math.pow, Math.sin, Math.cos, Math.atan2);- };-- // Determines the initial course direction from latlng1 setting off toward latlng2- _course = function (latlng1, latlng2) {- var PI, atan2, c1, c2, cos, denom, lat1, lat2, lng1, lng2, numer, result, sin;- // https://williams.best.vwh.net/avform.htm#Crs- sin = Math.sin, cos = Math.cos, atan2 = Math.atan2, PI = Math.PI;- c1 = Coordinate.fromLatLng(latlng1);- c2 = Coordinate.fromLatLng(latlng1);- lat1 = latlng1.lat * DEG_TO_RAD;- lng1 = latlng1.lng * DEG_TO_RAD;- lat2 = latlng2.lat * DEG_TO_RAD;- lng2 = latlng2.lng * DEG_TO_RAD;- if (lat1 > PI / 2 - EPSILON) {- return PI;- }- if (lat1 < -PI / 2 + EPSILON) {- return 2 * PI;- }- numer = sin(lng1 - lng2) * cos(lat2);- denom = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lng1 - lng2);- result = atan2(numer, denom) % (2 * PI);- if (result < 0) {- result += 2 * PI;- }- return result;- };-- // Determines the difference between the given angles in the interval (-180, 180)- // See: https://www.element84.com/determining-if-a-spherical-polygon-contains-a-pole.html- _angleDelta = function (a1, a2) {- var left_turn_amount;- if (a2 < a1) {- a2 += 360;- }- left_turn_amount = a2 - a1;- if (left_turn_amount === 180) {- return 0;- } else if (left_turn_amount > 180) {- return left_turn_amount - 360;- } else {- return left_turn_amount;- }- };-- // Returns a positive number if the angles rotate counterclockwise, a negative number- // if the angles rotate clockwise, or 0 if they do not rotate- _rotationDirection = function (angles) {- var a1, a2, delta, i, j, len, ref;- // Sum all adjacent angle deltas. The sum gives us the number we need to return- delta = 0;- len = angles.length;- for (i = j = 0, ref = len; ref >= 0 ? j < ref : j > ref; i = ref >= 0 ? ++j : --j) {- a1 = angles[i];- a2 = angles[(i + 1) % len];- delta += _angleDelta(a1, a2);- }- if (Math.abs(delta) < EPSILON) {- delta = 0;- }- return delta;- };-- /**- * Returns a number indicating which pole(s) the given latlngs cross- * North Pole: (containsPole(...) & NORTH_POLE) != 0- * South Pole: (containsPole(...) & SOUTH_POLE) != 0- * Any Pole: containsPole(...) != 0- * Neither Pole: containsPole(...) == 0- */- containsPole = function (latlngs) {- var angles, delta, delta0, delta1, dir, final, i, initial, j, latlng, latlng0, latlng1, latlng2, len, prev, ref;- if (latlngs.length < 3) {- return false;- }- latlngs = (function () {- var j, len1, results;- results = [];- for (j = 0, len1 = latlngs.length; j < len1; j+= 1) {- latlng = latlngs[j];- results.push(L.latLng(latlng));- }- return results;- })();- // https://www.element84.com/determining-if-a-spherical-polygon-contains-a-pole.html- delta = 0;- len = latlngs.length;- for (i = j = 0, ref = len; ref >= 0 ? j < ref : j > ref; i = ref >= 0 ? ++j : --j) {- latlng0 = latlngs[(i - 1 + len) % len];- latlng1 = latlngs[i];- latlng2 = latlngs[(i + 1) % len];- prev = (_course(latlng1, latlng0) + Math.PI) % (2 * Math.PI);- initial = _course(latlng1, latlng2);- final = (_course(latlng2, latlng1) + Math.PI) % (2 * Math.PI);- delta0 = initial - prev;- if (delta0 > Math.PI) {- delta0 -= 2 * Math.PI;- }- if (delta0 < -Math.PI) {- delta0 += 2 * Math.PI;- }- if (Math.abs(Math.PI - Math.abs(delta0)) < EPSILON) {- delta0 = 0;- }- delta1 = final - initial;- if (delta1 > Math.PI) {- delta1 -= 2 * Math.PI;- }- if (delta1 < -Math.PI) {- delta1 += 2 * Math.PI;- }- if (Math.abs(Math.PI - Math.abs(delta1)) < EPSILON) {- delta1 = 0;- }- delta += delta0 + delta1;- }- delta = delta * RAD_TO_DEG;- if (delta < -360 + EPSILON) {- return NORTH_POLE | SOUTH_POLE;- } else if (delta < EPSILON) {- angles = (function () {- var k, len1, results;- results = [];- for (k = 0, len1 = latlngs.length; k < len1; k+= 1) {- latlng = latlngs[k];- results.push(latlng.lng);- }- return results;- })();- dir = _rotationDirection(angles);- if (dir > 0) {- return NORTH_POLE;- } else if (dir < 0) {- return SOUTH_POLE;- } else {- return 0;- }- } else {- return 0;- }- };-- // Calculates the area within the given latlngs- area = function (origLatlngs) {- var PI, crossesMeridian, i, j, k, latlngA, latlngB, latlngC, latlngs, len, phiB, ref, ref1, sum, thetaA, thetaB, thetaC;- if (origLatlngs.length < 3) {- return 0;- }- /**- * This algorithm is an approximation to area. For some polygons, particularly large and narrow- * ones, it will produce incorrect results causing us to think they have clockwise points when- * their points are counterclockwise.- * The algorithm to deal with this exactly is complex and slow (see PDF below). For our purposes,- * we want to eliminate cases that may cause real problems. Below, we add the midpoint for long- * arcs to our list of latlngs. Doing so means we'll see fewer problems but we'll be doing- * more calculations.- * If polygons still cause problems, interpolate more :)- * Example of a problematic polygon before interpolation:- * https://edsc.dev/search/datasets?polygon=-38.53125%2C37.125%2C-60.75%2C56.109375%2C1.6875%2C0.28125%2C-38.53125%2C37.125&m=15.5390625!10.8984375!2!1!0!- * Example of a problematic polygon after interpolation:- * https://edsc.dev/search/datasets?polygon=-38.53125%2C37.125%2C-60.75%2C56.109375%2C-11.390625%2C-4.5%2C-38.53125%2C37.125&m=15.5390625!10.8984375!2!1!0!- */- latlngs = [];- len = origLatlngs.length;- for (i = j = 0, ref = len; ref >= 0 ? j < ref : j > ref; i = ref >= 0 ? ++j : --j) {- latlngA = origLatlngs[i];- latlngB = origLatlngs[(i + 1) % len];- latlngs.push(latlngA);- if (Math.abs(latlngA.lat - latlngB.lat) > 20 || Math.abs(latlngA.lng - latlngB.lng) > 20) {- latlngs.push(gcInterpolate(latlngA, latlngB));- }- }- // https://trs-new.jpl.nasa.gov/dspace/bitstream/2014/40409/3/JPL%20Pub%2007-3%20%20w%20Errata.pdf- // Page 7- PI = Math.PI;- crossesMeridian = false;- sum = 0;- len = latlngs.length;- for (i = k = 0, ref1 = len; ref1 >= 0 ? k < ref1 : k > ref1; i = ref1 >= 0 ? ++k : --k) {- latlngA = latlngs[i];- latlngB = latlngs[(i + 1) % len];- latlngC = latlngs[(i + 2) % len];- thetaA = latlngA.lng * DEG_TO_RAD;- thetaB = latlngB.lng * DEG_TO_RAD;- thetaC = latlngC.lng * DEG_TO_RAD;- phiB = latlngB.lat * DEG_TO_RAD;- if (Math.abs(thetaB - thetaA) > PI) {- crossesMeridian = !crossesMeridian;- if (thetaB > thetaA) {- thetaB -= 2 * Math.PI;- } else {- thetaB += 2 * Math.PI;- }- }- if (Math.abs(thetaC - thetaB) > PI) {- crossesMeridian = !crossesMeridian;- if (thetaC > thetaB) {- thetaC -= 2 * Math.PI;- } else {- thetaC += 2 * Math.PI;- }- }- sum += (thetaC - thetaA) * Math.sin(phiB);- }- if (crossesMeridian) {- sum = 4 * Math.PI + sum;- }- area = -sum / 2;- if (area < 0) {- area = 4 * Math.PI + area;- }- return area;- };-- return {- gcInterpolate: gcInterpolate,- area: area,- containsPole: containsPole,- NORTH_POLE: NORTH_POLE,- SOUTH_POLE: SOUTH_POLE- };-};diff --git a/web/js/edsc/interpolation.js b/web/js/edsc/interpolation.jsdeleted file mode 100644index d259d2f64..000000000--- a/web/js/edsc/interpolation.js+++ /dev/null@@ -1,162 +0,0 @@-/**- * This module extends L.Polyline and subclasses (Rectangle, Polygon) to- * interpolate their vertices before drawing them. The result is that,- * for instance, a bounding rectangle drawn in a polar projection will- * have a curved shape despite only having 4 vertices.- */--export default function (L, gcInterpolate) {- var interpolateCartesian, interpolateGeodetic, projectLatLngPath, projectLatlngs, projectPath;-- interpolateCartesian = function (ll0, ll1) {- return L.latLng((ll0.lat + ll1.lat) / 2, (ll0.lng + ll1.lng) / 2);- };-- // Geodetic interpolation. Finds great circle path between the given points.- // See geoutil.gcInterpolate- interpolateGeodetic = function (ll0, ll1) {- return gcInterpolate(ll0, ll1);- };-- // Given a path defined by latLngs, a projection defined by proj, and an interpolation- // function that takes two pionts and returns their midpoint, finds a set of projected- // (x, y) points defining the path between the points in the given projection- projectLatLngPath = function (latLngs, proj, interpolateFn, tolerance, maxDepth) {- var d, depth, depth0, depth1, interpolatedLatLngs, interpolatedPoints, ll, ll0, ll1, maxDepthReached, p, p0, p1, points, ref;- if (tolerance == null) {- tolerance = 1;- }- if (maxDepth == null) {- maxDepth = 10;- }- if (latLngs.length === 0) {- return [];- }- // Clone path and set its last element to its first so we can interpolate the last segment- if ((Math.abs(latLngs[0].lng) === (ref = Math.abs(latLngs[latLngs.length - 1].lng)) && ref === 180)) {- // In this case the last element is an artificial longitude crossing. Avoid interpolating- // with the first to prevent drawing strokes along the dateline- latLngs = latLngs.concat(latLngs[latLngs.length - 1]);- } else {- latLngs = latLngs.concat(latLngs[0]);- }- points = (function () {- var i, len, results;- results = [];- for (i = 0, len = latLngs.length; i < len; i+= 1) {- ll = latLngs[i];- results.push(proj(ll));- }- return results;- })();- // for ll in latLngs- // if Math.abs(ll.lat) == 90- // console.log ll.toString(), '->', proj(ll).toString()- interpolatedLatLngs = [latLngs.shift()];- interpolatedPoints = [points.shift()];- depth0 = 0;- depth1 = 0;- maxDepthReached = false;- while (latLngs.length > 0) {- ll0 = interpolatedLatLngs[interpolatedLatLngs.length - 1];- p0 = interpolatedPoints[interpolatedPoints.length - 1];- ll1 = latLngs[0];- p1 = points[0];- ll = interpolateFn(ll0, ll1);- p = proj(ll);- depth = Math.max(depth0, depth1) + 1;-- // if depth == 1- // console.log '0:', ll0.toString(), '->', p0.toString()- // console.log 'M:', ll.toString(), '->', p.toString()- // console.log '1:', ll1.toString(), '->', p1.toString()-- d = L.LineUtil.pointToSegmentDistance(p, p0, p1);- if (d < tolerance || depth >= maxDepth) {- if (depth >= maxDepth) {- maxDepthReached = true;- }- interpolatedLatLngs.push(ll, latLngs.shift());- interpolatedPoints.push(p, points.shift());- depth0 = depth1;- depth1 = Math.max(0, depth1 - 2);- } else {- latLngs.unshift(ll);- points.unshift(p);- depth1 += 1;- }- }- if (maxDepthReached && config.debug) {- console.log('Max interpolation depth reached.');- }- return interpolatedPoints;- };-- projectPath = function (map, latlngs, holes, fn, tolerance, maxDepth) {- var hole, proj, result;- if (holes == null) {- holes = [];- }- if (fn == null) {- fn = 'geodetic';- }- if (tolerance == null) {- tolerance = 1;- }- if (maxDepth == null) {- maxDepth = 10;- }- if (fn === 'geodetic') {- fn = interpolateGeodetic;- }- if (fn === 'cartesian') {- fn = interpolateCartesian;- }- proj = function (ll) {- // Avoid weird precision problems near infinity by clamping to a high min/max pixel value- var MAX_RES, result;- MAX_RES = 10000000;- // Fix problems where 90 degrees projects to NaN in our south polar projection- if (ll.lat === 90) {- ll = L.latLng(89.999, ll.lng);- }- result = map.latLngToLayerPoint.call(map, ll);- result.x = Math.max(Math.min(result.x, MAX_RES), -MAX_RES);- result.y = Math.max(Math.min(result.y, MAX_RES), -MAX_RES);- return result;- };- return result = {- boundary: projectLatLngPath(latlngs, proj, fn, tolerance, maxDepth),- holes: (function () {- var i, len, ref, results;- ref = holes != null ? holes : [];- results = [];- for (i = 0, len = ref.length; i < len; i+= 1) {- hole = ref[i];- results.push(projectLatLngPath(hole, proj, fn, tolerance, maxDepth));- }- return results;- })()- };- };-- // Overrides the default projectLatLngs in Polyline and Polygon to project and interpolate the- // path instead of just projecting it- projectLatlngs = function () {- var interpolated;- interpolated = projectPath(this._map, this._latlngs, this._holes, this._interpolationFn);- this._originalPoints = interpolated.boundary;- return this._holePoints = interpolated.holes;- };-- // Override methods- L.Polyline.prototype.projectLatlngs = projectLatlngs;- L.Polygon.prototype.projectLatlngs = projectLatlngs;-- // Give shapes an appropriate interpolation function. Polygons use geodetic, rectangles cartesian- L.Polyline.prototype._interpolationFn = interpolateGeodetic;- L.Rectangle.prototype._interpolationFn = interpolateCartesian;- return {- projectPath: projectPath- };-};diff --git a/web/js/edsc/spherical-polygon.js b/web/js/edsc/spherical-polygon.jsdeleted file mode 100644index f5ed8b77c..000000000--- a/web/js/edsc/spherical-polygon.js+++ /dev/null@@ -1,369 +0,0 @@-export default function (L, geoutil, Arc, Coordinate) {- var antimeridianCrossing, convertLatLngs, dividePolygon, ll2j, ll2s, makeCounterclockwise, originalRemove;-- // Converts the given latlngs to L.latLng objects and ensures they're- // normalized on the expected interval, [-180, 180]- convertLatLngs = function (latlngs) {- var j, latlng, len1, original, result;- result = [];- for (j = 0, len1 = latlngs.length; j < len1; j+= 1) {- original = latlngs[j];- latlng = L.latLng(original);- while (latlng.lng > 180) {- latlng.lng -= 360;- }- while (latlng.lng < -180) {- latlng.lng += 360;- }- result.push(latlng);- }- return result;- };-- /**- * Helper which delegates out to Arc to figure out where the great circle- * arc between latlng0 and latlng1 crosses the antimeridian. Will either- * return the point of the crossing or null if the arc does not cross.- */- antimeridianCrossing = function (latlng0, latlng1) {- var arc, ref;- arc = new Arc(Coordinate.fromLatLng(L.latLng(latlng0)), Coordinate.fromLatLng(L.latLng(latlng1)));- return (ref = arc.antimeridianCrossing()) != null ? ref.toLatLng() : void 0;- };-- // Ensures that latlngs is counterclockwise around its smallest area- // This is an in-place operation modifying the original list.- makeCounterclockwise = function (latlngs) {- var area;- area = geoutil.area(latlngs);- if (area > 2 * Math.PI) {- latlngs.reverse();- }- return latlngs;- };-- // For debugging- // Prints a string of latLng objects- ll2s = function (latlngs) {- var ll;- return ((function () {- var j, len1, results;- results = [];- for (j = 0, len1 = latlngs.length; j < len1; j+= 1) {- ll = latlngs[j];- results.push('(' + ll.lat + ', ' + ll.lng + ')');- }- return results;- })()).join(', ');- };-- // Prints a string of latLng objects to a format useful in Jason's visualization- // tools: https://testbed.echo.nasa.gov/spatial-viz/interactive_spherical_polygon_coverage- ll2j = function (latlngs) {- var ll;- return ((function () {- var j, len1, ref, results;- ref = latlngs.concat(latlngs[0]);- results = [];- for (j = 0, len1 = ref.length; j < len1; j+= 1) {- ll = ref[j];- results.push(ll.lng + ',' + ll.lat);- }- return results;- })()).join(', ');- };-- /**- * Given a list of latlngs constituting a polygon, returns an object:- * {interiors: [...], boundaries: [...]}- *- * When the interiors are drawn as filled un-stroked leaflet polygons and the- * boundaries are drawn as leaflet strokes (polylines), the displayed area- * is equivalent to how ECHO interprets the original latlngs.- *- * This is where all the magic happens.- *- * Problem:- * There are two ways to interpret the "interior" of a polygon on a globe, because a- * polygon divides the globe into two parts. In ECHO, a list of points in a polygon- * proceeds counterclockwise around its interior. Leaflet, on the other hand, ignores- * the problem entirely; the interior is whatever svg happens to draw for a set of- * projected points, which may or may not be completely different if you switch map- * projections.- *- * This method takes an ECHO polygon, normalizes its points, slices it along the meridian,- * and adds points for the poles to ensure that Leaflet renders the ECHO interpretation- * of the polygon in all projections.- *- * It is, necessarily, a hack.- */- dividePolygon = function (latlngs) {- var boundaries, boundary, containedPoles, containsNorthPole, containsSouthPole, crossing, extra, extras, hasInsertions, hasPole, hole, holes, i, inc, interior, interiors, j, k, l, lat, latlng, latlng1, latlng2, len, len1, len2, len3, lng, m, maxCrossingLat, minCrossingLat, n, next, o, p, q, ref, ref1, split;- interiors = [];- boundaries = [];- holes = [];- // Handle a list containing holes- if (latlngs && L.Util.isArray(latlngs[0]) && typeof latlngs[0][0] !== 'number') {- ref = latlngs.slice(1);- for (j = 0, len1 = ref.length; j < len1; j+= 1) {- hole = ref[j];- hole = convertLatLngs(hole);- denormalizePath(hole);- holes.push(hole);- }- latlngs = latlngs[0];- }- // Ensure we're dealing with normalized L.LatLng objects- latlngs = convertLatLngs(latlngs);- // Ensure the exterior points are counterclockwise around their smallest area- latlngs = makeCounterclockwise(latlngs);- // We will have to add points to accommodate the poles later- containedPoles = geoutil.containsPole(latlngs);- containsNorthPole = (containedPoles & geoutil.NORTH_POLE) !== 0;- containsSouthPole = (containedPoles & geoutil.SOUTH_POLE) !== 0;- // The maximum and minimum latitudes we cross the antimeridian- maxCrossingLat = -95;- minCrossingLat = 95;- /**- * Eventually we're going to want to split the polygon into multiple- * sub-polygons across the antimerdian. So, a square crossing the- * antimeridian would have a tall rectangle in the eastern hemisphere- * and a tall rectangle in the western hemisphere, which individually- * can be drawn correctly by Leaflet.- *- * The following loop iterates across the original polygon. Anywhere- * the polygon crosses the antimeridian, we ensure there two points,- * one at [crossing_lat, -180] and the other at [crossing_lon, 180]- */- split = [];- len = latlngs.length;- for (i = k = 0, ref1 = len; ref1 >= 0 ? k < ref1 : k > ref1; i = ref1 >= 0 ? ++k : --k) {- latlng1 = latlngs[i];- latlng2 = latlngs[(i + 1) % len];- crossing = antimeridianCrossing(latlng1, latlng2);- split.push(latlng1);- extras = [];- if (crossing != null) {- lat = crossing.lat;- if (latlng1.lng < latlng2.lng) {- extras = [[lat, -180], [lat, 180]];- } else {- extras = [[lat, 180], [lat, -180]];- }- } else if (latlng1.lng === 180 && latlng2.lng < 0) {- extras = [[latlng1.lat, -180]];- } else if (latlng1.lng === -180 && latlng2.lng > 0) {- extras = [[latlng1.lat, 180]];- } else if (latlng2.lng === 180 && latlng1.lng < 0) {- extras = [[latlng2.lat, -180]];- } else if (latlng2.lng === -180 && latlng1.lng > 0) {- extras = [[latlng2.lat, 180]];- }- for (l = 0, len2 = extras.length; l < len2; l+= 1) {- extra = extras[l];- lat = extra[0], lng = extra[1];- split.push(L.latLng(lat, lng));- maxCrossingLat = Math.max(lat, maxCrossingLat);- minCrossingLat = Math.min(lat, minCrossingLat);- }- }- // Did we insert anything?- hasInsertions = latlngs.length < split.length;- interior = [];- boundary = [];- if (hasInsertions) {- // Rearrange the split array so that its beginning and end contain separate polygons- if (Math.abs(split[0].lng) !== 180 || Math.abs(split[split.length - 1].lng) !== 180) {- while (Math.abs(split[0].lng) !== 180) {- split.push(split.shift());- }- split.push(split.shift());- }- }- // We now take the expanded array created by inserting points at the antimeridian and- // use it to create boundary and interior polygons- for (i = m = 0, len3 = split.length; m < len3; i = ++m) {- latlng = split[i];- interior.push(latlng);- boundary.push(latlng);- next = split[(i + 1) % split.length];- // If we're at the antimeridian- if (interior.length > 2 && Math.abs(latlng.lng) === 180 && Math.abs(next.lng) === 180) {- // We've reached the end of our current boundary- boundaries.push(boundary);- boundary = [];- /**- * If we contain the North pole, then we insert points at the northernmost- * antimeridian crossing which run along the top of the map in the default- * projection. and join it to its corresponding point on the other side- * of the map, ensuring that the pole will be filled-in.- */- hasPole = false;- if (containsNorthPole && latlng.lat === maxCrossingLat) {- hasPole = true;- lng = latlng.lng;- // We need a few points along the top of the map or polar projections screw up- inc = lng < 0 ? 90 : -90;- for (i = n = 0; n <= 4; i = ++n) {- interior.push(L.latLng(90, lng + i * inc));- }- }- // Similarly for the South Pole- if (containsSouthPole && latlng.lat === minCrossingLat) {- hasPole = true;- lng = latlng.lng;- inc = lng < 0 ? 90 : -90;- for (i = o = 0; o <= 4; i = ++o) {- interior.push(L.latLng(-90, lng + i * inc));- }- }- /**- * If we joined the east and west side of the polygon by going across the pole- * above, we want to keep adding to our current interior shape. Otherwise,- * we're stopping the interior at the antimeridian and adding it to our list.- */- if (!hasPole) {- interiors.push(interior);- interior = [];- }- }- }- // Close any remaining boundaries or interiors- if (boundary.length > 0) {- boundaries.push(boundary);- }- if (interior.length > 0) {- interiors.push(interior);- }- // Special case: If we contain both poles but do not have an edge crossing the meridian- // as dealt with above, reverse our drawing.- if (containsNorthPole && containsSouthPole && !hasInsertions) {- interior = [];- for (i = p = 0; p <= 4; i = ++p) {- interior.push(L.latLng(90, -180 + i * 90));- }- for (i = q = 0; q <= 4; i = ++q) {- interior.push(L.latLng(-90, 180 - i * 90));- }- interiors.unshift(interior);- }- return {- interiors: interiors,- boundaries: boundaries- };- };-- // This is a bit tricky. We need to be an instanceof L.Polygon for L.Draw methods- // to work, but in reality we're an L.FeatureGroup, hence the "includes"- L.SphericalPolygon = L.Polygon.extend({- includes: [L.LayerGroup.prototype, L.FeatureGroup.prototype],- options: {- fill: true- },- initialize: function (latlngs, options) {- this._layers = {};- this._options = L.extend({}, this.options, options);- return this.setLatLngs(latlngs);- },- setLatLngs: function (latlngs) {- var divided, latlng;- if (latlngs[0] && Array.isArray(latlngs[0]) && latlngs[0].length > 2) {- // Don't deal with holes- if (console.warn) {- console.warn('Polygon with hole detected. Ignoring.');- }- latlngs = latlngs[0];- }- latlngs = (function () {- var j, len1, results;- results = [];- for (j = 0, len1 = latlngs.length; j < len1; j+= 1) {- latlng = latlngs[j];- results.push(L.latLng(latlng));- }- return results;- })();- this._latlngs = latlngs;- divided = dividePolygon(latlngs);- if (this._boundaries) {- this._interiors.setLatLngs(divided.interiors);- return this._boundaries.setLatLngs(divided.boundaries);- } else {- this._interiors = L.polygon(divided.interiors, L.extend({}, this._options, {- stroke: false- }));- this._boundaries = L.multiPolyline(divided.boundaries, L.extend({}, this._options, {- fill: false- }));- this.addLayer(this._interiors);- return this.addLayer(this._boundaries);- }- },- getLatLngs: function () {- return makeCounterclockwise(this._latlngs.concat());- },- newLatLngIntersects: function (latlng, skipFirst) {- return false;- },- setOptions: function (options) {- this._options = this.options = L.extend({}, this._options, options);- L.setOptions(this._interiors, L.extend({}, this._options, {- stroke: false- }));- L.setOptions(this._boundaries, L.extend({}, this._options, {- fill: false- }));- return this.redraw();- },- setStyle: function (style) {- if (this.options.previousOptions) {- this.options.previousOptions = this._options;- }- this._interiors.setStyle(L.extend({}, style, {- stroke: false- }));- return this._boundaries.setStyle(L.extend({}, style, {- fill: false- }));- },- redraw: function () {- return this.setLatLngs(this._latlngs);- }- });-- L.sphericalPolygon = function (latlngs, options) {- return new L.SphericalPolygon(latlngs, options);- };-- // Monkey-patch _removeLayer. The original doesn't handle event propagation- // from FeatureGroups, and SphericalPolygons are FeatureGroups- originalRemove = L.EditToolbar.Delete.prototype._removeLayer;- L.EditToolbar.Delete.prototype._removeLayer = function (e) {- var ref;- if ((ref = e.target) != null ? ref._boundaries : void 0) {- e.layer = e.target;- }- return originalRemove.call(this, e);- };-- L.Draw.Polygon = L.Draw.Polygon.extend({- Poly: L.SphericalPolygon,- addHooks: function () {- L.Draw.Polyline.prototype.addHooks.call(this);- if (this._map) {- return this._poly = new L.SphericalPolygon([], this.options.shapeOptions);- }- }- });-- L.Edit.Poly = L.Edit.Poly.extend({- _getMiddleLatLng: function (marker1, marker2) {- var latlng;- return latlng = geoutil.gcInterpolate(marker1.getLatLng(), marker2.getLatLng());- }- });-- return {- dividePolygon: dividePolygon- };-};diff --git a/web/js/lib/gifstream.js b/web/js/modules/animation/gifstream.jssimilarity index 90%rename from web/js/lib/gifstream.jsrename to web/js/modules/animation/gifstream.jsindex 74066423f..9b01b478c 100644--- a/web/js/lib/gifstream.js+++ b/web/js/modules/animation/gifstream.js@@ -1,6 +1,7 @@+/* eslint no-plusplus: 0 */import Promise from 'bluebird';-import GifWriter from './gifwriter';-import NeuQuant from './neuquant';+import GifWriter from '../../lib/gifwriter';+import NeuQuant from '../../lib/neuquant';Promise.config({ cancellation: true });export default class GifStream {@@ -160,9 +161,10 @@ export default class GifStream {Math.round((processedImages / imageLength) * 100),);processedImages++;- setTimeout(() =>+ setTimeout(() => {// This was needed in order for callback to be applied- pull(),+ pull();+ },10);}});@@ -215,13 +217,6 @@ export default class GifStream {pull: function pull(controller) {const frame = frames.shift();if (!frame) controller.close();- let imgData;- let rgbComponents;- let paletteRGB;- let nq;- let paletteArray;- let numberPixels;- let pixels;let r;let g;let b;@@ -232,13 +227,13 @@ export default class GifStream {? delay + options.extraLastFrameDelay / 10: delay; // Add an extractx = self.addFrameDetails(ctx, frame);- imgData = ctx.getImageData(0, 0, width, height);- rgbComponents = dataToRGB(imgData.data, imgData.width, imgData.height);- nq = new NeuQuant(rgbComponents, rgbComponents.length, 15);- paletteRGB = nq.process();- paletteArray = new Uint32Array(componentizedPaletteToArray(paletteRGB));- numberPixels = imgData.height * imgData.width;- pixels = new Uint8Array(imgData.height * imgData.width);+ const imgData = ctx.getImageData(0, 0, width, height);+ const rgbComponents = dataToRGB(imgData.data, imgData.width, imgData.height);+ const nq = new NeuQuant(rgbComponents, rgbComponents.length, 15);+ const paletteRGB = nq.process();+ const paletteArray = new Uint32Array(componentizedPaletteToArray(paletteRGB));+ const numberPixels = imgData.height * imgData.width;+ const pixels = new Uint8Array(imgData.height * imgData.width);for (let i = 0; i < numberPixels; i++) {r = rgbComponents[k++];g = rgbComponents[k++];@@ -274,7 +269,7 @@ function componentizedPaletteToArray(paletteRGB) {r = paletteRGB[i];g = paletteRGB[i + 1];b = paletteRGB[i + 2];- paletteArray.push((r << 16) | (g << 8) | b);+ paletteArray.push((r << 16) | (g << 8) | b); // eslint-disable-line no-bitwise}return paletteArray;}