Interactive interface for browsing global, full-resolution satellite imagery
AIRS Dust Score now working properly with swath connectors
Mike McGanne1262baf5027
diff --git a/src/js/Date.js b/src/js/Date.jsindex fa9dd9058..ecf46696f 100644--- a/src/js/Date.js+++ b/src/js/Date.js@@ -32,8 +32,8 @@* @static** @param dateAsString {string} The string must be in the form of- * yyyy-MM-ddThh:mm:ssZ. Only the year, month, and day are required and the- * remaining string can be shortened. The Z to denote UTC is optional.+ * yyyy-MM-ddThh:mm:ss.sssZ. Only the year, month, and day are required and+ * the remaining string can be shortened. The Z to denote UTC is optional.** @return {Date} converted string as a date object, throws an exception if* the string is invalid@@ -51,15 +51,18 @@var hour = 0;var minute = 0;var second = 0;+ var millisecond = 0;// Use default of midnight if time is not specifiedif ( dateTimeArr.length > 1 ) {- var hhmmss = dateTimeArr[1].split(/[:Z]/);+ var hhmmss = dateTimeArr[1].split(/[:\.Z]/);var hour = hhmmss[0] || 0;var minute = hhmmss[1] || 0;var second = hhmmss[2] || 0;+ var millisecond = hhmmss[3] || 0;}- var date = new Date(Date.UTC(year, month, day, hour, minute, second));+ var date = new Date(Date.UTC(year, month, day, hour, minute, second,+ millisecond));if ( isNaN(date.getTime()) ) {throw new Error("Invalid date: " + dateAsString);}diff --git a/src/js/Worldview/DataDownload/Layers/Swath.js b/src/js/Worldview/DataDownload/Layers/Swath.jsindex 5ceab84ea..3801182ce 100644--- a/src/js/Worldview/DataDownload/Layers/Swath.js+++ b/src/js/Worldview/DataDownload/Layers/Swath.js@@ -20,56 +20,10 @@ Worldview.DataDownload.Layers.Swath = function(model, maps, config) {strokeOpacity: 0.75,strokeWidth: 2};+ var MAX_DISTANCE_GEO = 270;var self = {};-- var combineSwath = function(startTimes, endTimes, swath) {- var combined = false;-- // Can this swath be added to the end of other swath?- var otherSwath = endTimes[swath[0].time_start];- if ( otherSwath ) {- // Remove entries for this swath- delete startTimes[swath[0].time_start];- delete endTimes[swath[swath.length - 1].time_end];-- // Remove entries for other swath- delete startTimes[otherSwath[0].time_start];- delete endTimes[otherSwath[otherSwath.length - 1].time_end];-- // Combine swaths- var newSwath = otherSwath.concat(swath);-- startTimes[newSwath[0].time_start] = newSwath;- endTimes[newSwath[newSwath.length - 1].time_end] = newSwath;- combined = true;- swath = newSwath;- }-- var otherSwath = startTimes[swath[0].time_end];- if ( otherSwath ) {- // Remove entries for this swath- delete startTimes[swath[0].time_start];- delete endTimes[swath[swath.length - 1].time_end];-- // Remove entries for other swath- delete startTimes[otherSwath[0].time_start];- delete endTimes[otherSwath[otherSwath.length - 1].time_end];-- // Combine swaths- var newSwath = swath.concat(otherSwath);-- startTimes[newSwath[0].time_start] = newSwath;- endTimes[newSwath[newSwath.length - 1].time_end] = newSwath;- combined = true;- swath = newSwath;- }-- if ( combined ) {- combineSwath(startTimes, endTimes, swath);- }- };-+self.update = function(results) {self.clear();var swaths = results.meta.swaths;@@ -77,17 +31,36 @@ Worldview.DataDownload.Layers.Swath = function(model, maps, config) {return;}var layer = getLayer();-++ var maxDistance = ( model.crs === Worldview.Map.CRS_WGS_84 )+ ? MAX_DISTANCE_GEO : Number.POSITIVE_INFINITY;+var features = [];$.each(swaths, function(index, swath) {- var points = [];+ var lastGranule = null;+ // Main granules or west side granuels$.each(swath, function(index, granule) {- points.push(granule.centroid[model.crs].clone());+ if ( !lastGranule ) {+ lastGranule = granule;+ return;+ }+ var polys1 = Worldview.Map.toPolys(lastGranule.geometry[model.crs]);+ var polys2 = Worldview.Map.toPolys(granule.geometry[model.crs]);+ $.each(polys1, function(index1, poly1) {+ $.each(polys2, function(index2, poly2) {+ var c1 = poly1.getCentroid();+ var c2 = poly2.getCentroid();+ var distanceX = Worldview.Map.distanceX(c1, c2);+ if ( distanceX < maxDistance ) {+ features.push(new OpenLayers.Feature.Vector(+ new OpenLayers.Geometry.LineString([c1, c2])+ ));+ }+ });+ });+ lastGranule = granule;});- var line = new OpenLayers.Feature.Vector(- new OpenLayers.Geometry.LineString(points)- );- features.push(line);+});layer.addFeatures(features);};diff --git a/src/js/Worldview/DataDownload/Results/ConnectSwaths.js b/src/js/Worldview/DataDownload/Results/ConnectSwaths.jsindex c1587fe85..dae7782d6 100644--- a/src/js/Worldview/DataDownload/Results/ConnectSwaths.js+++ b/src/js/Worldview/DataDownload/Results/ConnectSwaths.js@@ -28,19 +28,22 @@ Worldview.DataDownload.Results.ConnectSwaths = function(projection) {if ( !granule.centroid[projection] ) {return;}- if ( startTimes[granule.time_start] ) {- log.warn("Discarding duplicate start time", granule.time_start,- granule, startTimes[granule.time_start]);+ var timeStart = roundTime(granule.time_start);+ var timeEnd = roundTime(granule.time_end);++ if ( startTimes[timeStart] ) {+ log.warn("Discarding duplicate start time", timeStart,+ granule, startTimes[timeStart]);return;}- if ( endTimes[granule.time_end] ) {- log.warn("Discarding duplicate end time", granule.time_end,- granule, endTimes[granule.time_end]);+ if ( endTimes[timeEnd] ) {+ log.warn("Discarding duplicate end time", timeEnd,+ granule, endTimes[timeEnd]);return;}var swath = [granule];- startTimes[granule.time_start] = swath;- endTimes[granule.time_end] = swath;+ startTimes[timeStart] = swath;+ endTimes[timeEnd] = swath;combineSwath(swath);return granule;@@ -60,59 +63,73 @@ Worldview.DataDownload.Results.ConnectSwaths = function(projection) {var maxDistance = ( projection === Worldview.Map.CRS_WGS_84 )? MAX_DISTANCE_GEO : Number.POSITIVE_INFINITY;+ var thisTimeStart = roundTime(swath[0].time_start);+ var thisTimeEnd = roundTime(swath[swath.length - 1].time_end);+ var otherSwath = endTimes[thisTimeStart];+// Can this swath be added to the end of other swath?- var otherSwath = endTimes[swath[0].time_start];if ( otherSwath ) {var otherGranule = otherSwath[otherSwath.length - 1];- if ( distance(swath[0], otherGranule) < maxDistance ) {+ var otherTimeStart = roundTime(otherSwath[0].time_start);+ var otherTimeEnd =+ roundTime(otherSwath[otherSwath.length - 1].time_end);++ if ( connectionAllowed(swath[0], otherGranule, maxDistance) ) {// Remove entries for this swath- delete startTimes[swath[0].time_start];- delete endTimes[swath[swath.length - 1].time_end];+ delete startTimes[thisTimeStart];+ delete endTimes[thisTimeEnd];// Remove entries for other swath- delete startTimes[otherSwath[0].time_start];- delete endTimes[otherSwath[otherSwath.length - 1].time_end];+ delete startTimes[otherTimeStart];+ delete endTimes[otherTimeEnd];// Combine swathsvar newSwath = otherSwath.concat(swath);- startTimes[newSwath[0].time_start] = newSwath;- endTimes[newSwath[newSwath.length - 1].time_end] = newSwath;+ var newTimeStart = roundTime(newSwath[0].time_start);+ var newTimeEnd =+ roundTime(newSwath[newSwath.length - 1].time_end);++ startTimes[newTimeStart] = newSwath;+ endTimes[newTimeEnd] = newSwath;combined = true;swath = newSwath;}}-- /*- var otherSwath = startTimes[swath[0].time_end];- if ( otherSwath && distance(swath[0], otherSwath) < MAX_DISTANCE ) {- // Remove entries for this swath- delete startTimes[swath[0].time_start];- delete endTimes[swath[swath.length - 1].time_end];-- // Remove entries for other swath- delete startTimes[otherSwath[0].time_start];- delete endTimes[otherSwath[otherSwath.length - 1].time_end];-- // Combine swaths- var newSwath = swath.concat(otherSwath);-- startTimes[newSwath[0].time_start] = newSwath;- endTimes[newSwath[newSwath.length - 1].time_end] = newSwath;- combined = true;- swath = newSwath;- }- */-+if ( combined ) {combineSwath(swath);}};- var distance = function(g1, g2) {- var x1 = g1.centroid[projection].x;- var x2 = g2.centroid[projection].x;- return Math.abs(x2 - x1);+ // Connection is allowed as long as there is at least one path between+ // centroids that is less than the max distance+ var connectionAllowed = function(g1, g2, maxDistance) {+ var polys1 = Worldview.Map.toPolys(g1.geometry[projection]);+ var polys2 = Worldview.Map.toPolys(g2.geometry[projection]);+ var allowed = false;++ $.each(polys1, function(index, poly1) {+ $.each(polys2, function(index, poly2) {+ var x1 = poly1.getCentroid().x;+ var x2 = poly2.getCentroid().x;+ if ( Math.abs(x2 - x1) < maxDistance ) {+ allowed = true;+ return false;+ }+ });+ });+ return allowed;+ };+++ var roundTime = function(timeString) {+ var time = Date.parseISOString(timeString);+ if ( time.getUTCMilliseconds() >= 500 ) {+ time.setUTCSeconds(time.getUTCSeconds() + 1);+ }+ time.setUTCMilliseconds(0);+ return time.toISOString();};return self;diff --git a/src/js/Worldview/Map.js b/src/js/Worldview/Map.jsindex 510c532d1..759ae65f4 100644--- a/src/js/Worldview/Map.js+++ b/src/js/Worldview/Map.js@@ -216,6 +216,10 @@ $(function(ns) {(Math.pow(p1.y - p2.y, 2)));};+ ns.distanceX = function(p1, p2) {+ return Math.abs(p2.x - p1.x);+ };+ns.interpolate2D = function(p1, p2, amount) {var distX = p2.x - p1.x;var distY = p2.y - p1.y;@@ -225,5 +229,18 @@ $(function(ns) {return new OpenLayers.Geometry.Point(interpX, interpY);};++ // If multipolygon, return a list of the polygons. If polygon, return+ // the single item in a list+ ns.toPolys = function(geom) {+ var polys = [];+ if ( geom.CLASS_NAME === "OpenLayers.Geometry.MultiPolygon" ) {+ polys = geom.components;+ } else {+ polys = [geom];+ }+ return polys;+ };+}(Worldview.Map));diff --git a/src/js/main.js b/src/js/main.jsindex c85917f5a..e5a36c25a 100644--- a/src/js/main.js+++ b/src/js/main.js@@ -266,9 +266,11 @@ $(function() {// Initialize "static" varsWorldview.Tour.start(storageEngine, hideSplash, false);}- window.onbeforeunload = function(){- storageEngine.setItem('eventsCollapsed', events.isCollapsed);- };+ if ( events ) {+ window.onbeforeunload = function(){+ storageEngine.setItem('eventsCollapsed', events.isCollapsed);+ };+ }};var debuggingFeatures = function(config) {