Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Allow event tract to go over date line #1568

Benjamin King6c04c9d3047f
diff --git a/web/js/natural-events/cluster.js b/web/js/natural-events/cluster.js
index ab4ed8ca3..d1f7f0e35 100644
--- a/web/js/natural-events/cluster.js
+++ b/web/js/natural-events/cluster.js
@@ -32,8 +32,14 @@ export function naturalEventsClusterCreateObject() {
accumulated.startDate = newDate;
accumulated.endDate = newDate;
} else {
- accumulated.startDate = Date.parse(new Date(pastStartDate)) > Date.parse(new Date(newDate)) ? newDate : pastStartDate;
- accumulated.endDate = Date.parse(new Date(pastEndDate)) < Date.parse(new Date(newDate)) ? newDate : pastEndDate;
+ accumulated.startDate =
+ Date.parse(new Date(pastStartDate)) > Date.parse(new Date(newDate))
+ ? newDate
+ : pastStartDate;
+ accumulated.endDate =
+ Date.parse(new Date(pastEndDate)) < Date.parse(new Date(newDate))
+ ? newDate
+ : pastEndDate;
}
},
setPolar: function() {
@@ -45,7 +51,7 @@ export function naturalEventsClusterCreateObject() {
this.maxZoom = 12;
}
});
-};
+}
/**
* Create a geoJSON point out of a point
*
@@ -67,7 +73,7 @@ export function naturalEventsClusterPointToGeoJSON(id, coordinates, date) {
coordinates: coordinates
}
};
-};
+}
/**
* @param {Array}
* @return {void}
@@ -80,7 +86,7 @@ export function naturalEventsClusterSort(clusterArray) {
return new Date(secondDate) - new Date(firstDate);
});
return newArray;
-};
+}
/**
* Load points given superCluster Object
*
@@ -89,7 +95,12 @@ export function naturalEventsClusterSort(clusterArray) {
* @param {number} zoomLevel
* @return {Object}
*/
-export function naturalEventsClusterGetPoints(superClusterObj, pointArray, zoomLevel) {
+export function naturalEventsClusterGetPoints(
+ superClusterObj,
+ pointArray,
+ zoomLevel,
+ extent
+) {
superClusterObj.load(pointArray);
- return superClusterObj.getClusters([-180, -90, 180, 90], lodashRound(zoomLevel));
-};
+ return superClusterObj.getClusters(extent, lodashRound(zoomLevel));
+}
diff --git a/web/js/natural-events/track.js b/web/js/natural-events/track.js
index 7e3efad14..34d7f4188 100644
--- a/web/js/natural-events/track.js
+++ b/web/js/natural-events/track.js
@@ -7,8 +7,12 @@ import OlStyleStyle from 'ol/style/Style';
import * as olExtent from 'ol/extent';
import OlGeomMultiLineString from 'ol/geom/MultiLineString';
import * as olProj from 'ol/proj';
-import lodashEach from 'lodash/each';
-import lodashDebounce from 'lodash/debounce';
+import {
+ find as lodashFind,
+ each as lodashEach,
+ debounce as lodashDebounce
+} from 'lodash';
+
import { naturalEventsUtilGetEventById } from './util';
import {
naturalEventsClusterPointToGeoJSON,
@@ -203,6 +207,33 @@ export default function naturalEventsTrack(models, ui, config) {
init();
return self;
}
+/**
+ * Determine if track point is across the date line from the
+ * selected point
+ * @param {Array} activeCoord Coordinate array of selected track point
+ * @param {Array} nextCoord Coordinate to test against active coord
+ * @return {Boolean}
+ */
+const crossesDateLine = function(activeCoord, nextCoord) {
+ return (
+ Math.abs(Math.abs(activeCoord[0]) - Math.abs(nextCoord[0])) <
+ Math.abs(activeCoord[0] - nextCoord[0])
+ );
+};
+/**
+ * Convert coordinates to be over date line
+ * in geographic projections
+ *
+ * @param {Array} coordinates Coordinate array
+ * @return {Array}
+ */
+const getOverDateLineCoordinates = function(coordinates) {
+ const long = coordinates[0];
+ const lat = coordinates[1];
+ return long < 0
+ ? [Math.abs(180 + 180 - Math.abs(long)), lat]
+ : [-Math.abs(180 + 180 - Math.abs(long)), lat];
+};
/**
* Create vector layer
*
@@ -215,7 +246,10 @@ var naturalEventsTrackLayer = function(models, featuresArray) {
source: new OlSourceVector({
features: featuresArray
}),
- extent: models.proj.selected.maxExtent,
+ extent:
+ models.proj.selected.id === 'geographic'
+ ? [-250, -90, 250, 90]
+ : models.proj.selected.maxExtent,
style: [getLineStyle('black', 2), getLineStyle('white', 1)]
});
};
@@ -313,13 +347,28 @@ var createTrack = function(models, eventObj, map, selectedDate, callback) {
var clustersAfterSelected;
var selectedPoint;
- var zoom = map.getView().getZoom();
var clusters;
var afterSelected = false;
+ const zoom = map.getView().getZoom();
+ const extent =
+ models.proj.selected.id === 'geographic'
+ ? [-250, -90, 250, 90]
+ : models.proj.selected.maxExtent;
+ const selectedCoords = lodashFind(eventObj.geometries, function(geometry) {
+ return geometry.date.split('T')[0] === selectedDate;
+ }).coordinates;
lodashEach(eventObj.geometries, function(geometry, index) {
- var date = geometry.date.split('T')[0];
- var coordinates = geometry.coordinates;
- var isSelected = selectedDate === date;
+ let coordinates = geometry.coordinates;
+ const date = geometry.date.split('T')[0];
+ const isSelected = selectedDate === date;
+ const isOverDateline =
+ models.proj.selected.id === 'geographic'
+ ? crossesDateLine(selectedCoords, coordinates)
+ : false;
+ if (isOverDateline) {
+ // replace coordinates
+ coordinates = getOverDateLineCoordinates(coordinates);
+ }
// Cluster in three groups
if (isSelected) {
selectedPoint = naturalEventsClusterPointToGeoJSON(
@@ -351,12 +400,14 @@ var createTrack = function(models, eventObj, map, selectedDate, callback) {
clustersBeforeSelected = naturalEventsClusterGetPoints(
firstClusterObj,
geoJSONPointsBeforeSelected,
- zoom
+ zoom,
+ extent
);
clustersAfterSelected = naturalEventsClusterGetPoints(
secondClusterObj,
geoJSONPointsAfterSelected,
- zoom
+ zoom,
+ extent
);
clusters = clustersBeforeSelected.concat(
[selectedPoint],
diff --git a/web/mock/events_data.json-20170530 b/web/mock/events_data.json-20170530
index fe5ad3004..301549ca1 100644
--- a/web/mock/events_data.json-20170530
+++ b/web/mock/events_data.json-20170530
@@ -132,6 +132,43 @@
]
},
{
+ "id": "EONET_2777",
+ "title": "Tropical Worldview Storm",
+ "description": "",
+ "link": "http://eonet.sci.gsfc.nasa.gov/api/v2/events/EONET_2804",
+ "categories": [
+ {
+ "id": 10,
+ "title": "Severe Storms"
+ }
+ ],
+ "sources": [
+ {
+ "id": "UNISYS",
+ "url": "http://weather.unisys.com/hurricane/n_indian/2017/MORA/track.dat"
+ }
+
+ ],
+ "geometries": [
+ {
+ "date": "2017-05-27T18:00:00Z",
+ "type": "Point", "coordinates": [178.50, 14.00 ]
+ },
+ {
+ "date": "2017-05-28T00:00:00Z",
+ "type": "Point", "coordinates": [ 179.50, 14.20 ]
+ },
+ {
+ "date": "2017-05-29T06:00:00Z",
+ "type": "Point", "coordinates": [ -179.50, 14.80 ]
+ },
+ {
+ "date": "2017-05-31T12:00:00Z",
+ "type": "Point", "coordinates": [ 179.50, 18.80 ]
+ }
+ ]
+ },
+ {
"id": "EONET_3931",
"title": "Rattlesnake Fire",
"description": "",
@@ -217,7 +254,7 @@
]
},
{
- "id": "EONET_2733",
+ "id": "EONET_2703",
"title": "Iceberg B30",
"description": "",
"link": "http://eonet.sci.gsfc.nasa.gov/api/v2/events/EONET_2733",