Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

event extent filtering tweaks

Jason Kentcfcfc8d5818f
diff --git a/web/js/containers/sidebar/footer-content.js b/web/js/containers/sidebar/footer-content.js
index e37a5311a..e19ebea4f 100644
--- a/web/js/containers/sidebar/footer-content.js
+++ b/web/js/containers/sidebar/footer-content.js
@@ -12,7 +12,7 @@ import { toggleCompareOnOff, changeMode } from '../../modules/compare/actions';
import SearchUiProvider from '../../components/layer/product-picker/search-ui-provider';
import { openCustomContent } from '../../modules/modal/actions';
import { stop as stopAnimationAction } from '../../modules/animation/actions';
-import { getEventsFilteredCategories } from '../../modules/natural-events/selectors';
+import { getFilteredEvents } from '../../modules/natural-events/selectors';
import { LIMIT_EVENT_REQUEST_COUNT } from '../../modules/natural-events/constants';
const FooterContent = React.forwardRef((props, ref) => {
@@ -140,7 +140,7 @@ const mapStateToProps = (state) => {
animation, config, compare, browser,
} = state;
const { isPlaying } = animation;
- const eventsData = getEventsFilteredCategories(state);
+ const eventsData = getFilteredEvents(state);
return {
isMobile: browser.lessThan.medium,
diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.js
index 08e993062..75ffc7030 100644
--- a/web/js/containers/sidebar/sidebar.js
+++ b/web/js/containers/sidebar/sidebar.js
@@ -28,7 +28,7 @@ import {
requestSources as requestSourcesActionCreator,
} from '../../modules/natural-events/actions';
import { getAllActiveLayers } from '../../modules/layers/selectors';
-import { getEventsFilteredCategories } from '../../modules/natural-events/selectors';
+import { getFilteredEvents } from '../../modules/natural-events/selectors';
import ErrorBoundary from '../error-boundary';
import util from '../../util/util';
import {
@@ -354,7 +354,7 @@ const mapStateToProps = (state) => {
const hasEventRequestError = !!(requestedEvents.error
|| requestedEventSources.error);
- const eventsData = getEventsFilteredCategories(state);
+ const eventsData = getFilteredEvents(state);
const eventsSources = lodashGet(requestedEventSources, 'response');
const { screenHeight } = browser;
const { isDistractionFreeModeActive } = ui;
diff --git a/web/js/map/natural-events/event-markers.js b/web/js/map/natural-events/event-markers.js
index 142011b18..44365d84b 100644
--- a/web/js/map/natural-events/event-markers.js
+++ b/web/js/map/natural-events/event-markers.js
@@ -16,7 +16,7 @@ import googleTagManager from 'googleTagManager';
import EventIcon from '../../components/sidebar/event-icon';
import { selectEvent as selectEventAction } from '../../modules/natural-events/actions';
import { getDefaultEventDate } from '../../modules/natural-events/util';
-import { getEventsFilteredCategories } from '../../modules/natural-events/selectors';
+import { getFilteredEvents } from '../../modules/natural-events/selectors';
const icons = [
'Dust and Haze',
@@ -75,7 +75,7 @@ class EventMarkers extends React.Component {
const markers = eventsData.reduce((collection, event) => {
const marker = {};
const isSelected = event.id === selectedEvent.id;
- const { maxExtent, crs } = proj.selected;
+ const { crs } = proj.selected;
let date = getDefaultEventDate(event);
if (isSelected && selectedEvent.date) {
date = selectedEvent.date;
@@ -118,15 +118,11 @@ class EventMarkers extends React.Component {
? category
: { title: 'Default', slug: 'default' };
- // get maxExtent of current projection and check if marker is within range
- const maxExtentCheck = olExtent.containsCoordinate(maxExtent, coordinates);
- // only create marker if within projection extent range
- if (maxExtentCheck) {
- marker.pin = createPin(event.id, category, isSelected, event.title);
- marker.pin.setPosition(coordinates);
- map.addOverlay(marker.pin);
- this.addInteractions(marker, event, date, isSelected);
- }
+ marker.pin = createPin(event.id, category, isSelected, event.title);
+ marker.pin.setPosition(coordinates);
+ map.addOverlay(marker.pin);
+ this.addInteractions(marker, event, date, isSelected);
+
// empty objects (i.e., markers not within projection range) are not pushed to collection
if (lodashIsEmpty(marker) !== true) {
collection.push(marker);
@@ -272,7 +268,7 @@ const mapStateToProps = (state) => {
selectedEvent: events.selected,
selectedDate: date.selected,
isAnimatingToEvent: events.isAnimatingToEvent,
- eventsData: getEventsFilteredCategories(state),
+ eventsData: getFilteredEvents(state),
eventsDataIsLoading: requestedEvents.isLoading,
};
};
diff --git a/web/js/map/natural-events/event-track.js b/web/js/map/natural-events/event-track.js
index f839a7dc7..b57f0c848 100644
--- a/web/js/map/natural-events/event-track.js
+++ b/web/js/map/natural-events/event-track.js
@@ -11,7 +11,6 @@ import * as olExtent from 'ol/extent';
import OlGeomMultiLineString from 'ol/geom/MultiLineString';
import * as olProj from 'ol/proj';
import {
- find as lodashFind,
each as lodashEach,
debounce as lodashDebounce,
} from 'lodash';
@@ -24,7 +23,7 @@ import {
} from './cluster';
import { mapUtilZoomAction } from '../util';
import { selectEvent as selectEventAction } from '../../modules/natural-events/actions';
-import { getEventsFilteredCategories } from '../../modules/natural-events/selectors';
+import { getFilteredEvents } from '../../modules/natural-events/selectors';
const firstClusterObj = naturalEventsClusterCreateObject(); // Cluster before selected event
const secondClusterObj = naturalEventsClusterCreateObject(); // Cluster after selected event
@@ -350,10 +349,11 @@ const createTrack = function(proj, eventObj, map, selectedDate, callback) {
? [-250, -90, 250, 90]
: [-180, -90, 180, 90];
- const selectedCoords = lodashFind(eventObj.geometry, (geometry) => geometry.date.split('T')[0] === selectedDate).coordinates;
- lodashEach(eventObj.geometry, (geometry, index) => {
- let { coordinates } = geometry;
- const date = geometry.date.split('T')[0];
+ const { geometry } = eventObj;
+ const selectedCoords = geometry.find(({ date }) => date.split('T')[0] === selectedDate).coordinates;
+ geometry.forEach((geom, index) => {
+ let { coordinates } = geom;
+ const date = geom.date.split('T')[0];
const isSelected = selectedDate === date;
const isOverDateline = proj.selected.id === 'geographic'
? crossesDateLine(selectedCoords, coordinates)
@@ -523,7 +523,7 @@ const createArrows = function(lineSegmentCoords, map) {
const addPoints = function(proj, clusters, map, selectedDate, callback) {
const overlays = [];
const trackArray = [];
- lodashEach(clusters, (clusterPoint, index) => {
+ clusters.forEach((clusterPoint, index) => {
let point;
const date = clusterPoint.properties.date || clusterPoint.properties.startDate;
const isSelected = selectedDate === date;
@@ -652,7 +652,7 @@ const mapStateToProps = (state) => {
proj,
selectedDate: date.selected,
selectedEvent: events.selected,
- eventsData: getEventsFilteredCategories(state),
+ eventsData: getFilteredEvents(state),
isAnimatingToEvent,
};
};
diff --git a/web/js/map/natural-events/natural-events.js b/web/js/map/natural-events/natural-events.js
index c1d84ffa2..c8479037a 100644
--- a/web/js/map/natural-events/natural-events.js
+++ b/web/js/map/natural-events/natural-events.js
@@ -11,7 +11,7 @@ import { selected as selectedAction } from '../../modules/natural-events/actions
import {
activateLayersForEventCategory as activateLayersForEventCategoryAction,
} from '../../modules/layers/actions';
-import { getEventsFilteredCategories } from '../../modules/natural-events/selectors';
+import { getFilteredEvents } from '../../modules/natural-events/selectors';
import EventTrack from './event-track';
import EventMarkers from './event-markers';
@@ -171,7 +171,7 @@ const mapStateToProps = (state) => {
mapUi: map.ui,
proj,
eventsDataIsLoading: requestedEvents.isLoading,
- eventsData: getEventsFilteredCategories(state),
+ eventsData: getFilteredEvents(state),
selectedEvent: events.selected,
};
};
diff --git a/web/js/modules/natural-events/selectors.js b/web/js/modules/natural-events/selectors.js
index 26d4b6238..4cd212e8c 100644
--- a/web/js/modules/natural-events/selectors.js
+++ b/web/js/modules/natural-events/selectors.js
@@ -1,23 +1,51 @@
import { createSelector } from 'reselect';
+import { containsCoordinate } from 'ol/extent';
+import { transform } from 'ol/proj';
const getActiveCategories = ({ events }) => events.selectedCategories;
const getEvents = ({ requestedEvents }) => requestedEvents.response;
+const getProjection = ({ proj }) => proj.selected;
/**
- * We need to filter the categories on events so that only categories
+ * Since the EONET API bounding box parameter only accepts a geographic coordinate format
+ * the bounding box extents we send during the API call may return events outside of the
+ * visible extent in polar projections within the app. We filter out any geometries
+ * for an event that are outside the extent (to prevent tracks from extending beyond extent)
+ * and filter out any events that have no visible geometries in the current extent.
+ *
+ * We also need to filter the categories on events so that only categories
* which A) we support and B) are currently selected in the event filter
* so that an inappropriate icon does not show. (E.g. event belongs to
* "Severe Storms" and "Snow" but was returned from a search for "Snow")
*/
// eslint-disable-next-line import/prefer-default-export
-export const getEventsFilteredCategories = createSelector(
- [getActiveCategories, getEvents],
- (activeCategories, events) => {
+export const getFilteredEvents = createSelector(
+ [getActiveCategories, getEvents, getProjection],
+ (activeCategories, events, projection) => {
if (!events) return;
- return events.map((event) => {
- const newEvent = { ...event };
- newEvent.categories = event.categories.filter((c) => activeCategories.some(({ id }) => id === c.id));
- return newEvent;
- });
+ const filterGeoms = ({ coordinates }) => {
+ const { crs, maxExtent } = projection;
+ const coords = transform(coordinates, 'EPSG:4326', crs);
+ return containsCoordinate(maxExtent, coords);
+ };
+ return events
+ .reduce((filteredEvents, event) => {
+ const filteredGeometries = event.geometry.filter(filterGeoms);
+ if (filteredGeometries.length) {
+ const newEvent = {
+ ...event,
+ geometry: filteredGeometries,
+ };
+ filteredEvents.push(newEvent);
+ }
+ return filteredEvents;
+ }, [])
+ .map((event) => {
+ const newEvent = { ...event };
+ newEvent.categories = event.categories.filter(
+ (c) => activeCategories.some(({ id }) => id === c.id),
+ );
+ return newEvent;
+ });
},
);
diff --git a/web/js/modules/natural-events/util.js b/web/js/modules/natural-events/util.js
index ca945ea00..acd9e934c 100644
--- a/web/js/modules/natural-events/util.js
+++ b/web/js/modules/natural-events/util.js
@@ -21,6 +21,7 @@ export function parseEvent(eventString) {
showAll: true,
};
}
+
export function serializeEvent(currentItemState) {
const eventId = lodashGet(currentItemState, 'selected.id');
const eventDate = lodashGet(currentItemState, 'selected.date');
@@ -110,10 +111,8 @@ export function getEventsRequestURL (state) {
selectedDates,
showAll,
} = events;
-
const baseUrl = lodashGet(config, 'features.naturalEvents.host');
const mockEvents = lodashGet(config, 'parameters.mockEvents');
-
if (mockEvents) {
// eslint-disable-next-line no-console
console.warn(`Using mock events data: ${mockEvents}`);
@@ -121,7 +120,14 @@ export function getEventsRequestURL (state) {
? 'mock/events_data.json'
: `mock/events_data.json-${mockEvents}`;
}
-
+ // Rough extents used for EONET projection extent filtering. Polar extents do not
+ // represent exact bounds seen in app since they are expressed in EPSG:4326
+ // format which is the only format the API supports
+ const extentBounds = {
+ 'EPSG:4326': [-180, 90, 180, -90],
+ 'EPSG:3413': [-180, 40, 180, 90],
+ 'EPSG:3031': [-180, -90, 180, -40],
+ };
const { crs } = proj.selected;
const selectedMap = map && map.ui.selected;
const bbox = !showAll && selectedMap && selectedMap.getView().calculateExtent();
@@ -130,6 +136,8 @@ export function getEventsRequestURL (state) {
status: 'all',
limit: LIMIT_EVENT_REQUEST_COUNT,
};
+ const useBbox = bbox && bbox.length && crs === 'EPSG:4326';
+ params.bbox = useBbox ? bbox : extentBounds[crs];
if (start && end) {
params.start = moment.utc(start).format('YYYY-MM-DD');
@@ -138,19 +146,6 @@ export function getEventsRequestURL (state) {
if (selectedCategories.length) {
params.category = selectedCategories.map(({ id }) => id).join(',');
}
-
- let [minLon, maxLat, maxLon, minLat] = [-180, 90, 180, -90];
- if (crs === 'EPSG:3413') {
- [minLon, maxLat, maxLon, minLat] = [-180, 50, 180, 90];
- }
- if (crs === 'EPSG:3031') {
- [minLon, maxLat, maxLon, minLat] = [-180, -90, 180, -50];
- }
- if (bbox && bbox.length && crs === 'EPSG:4326') {
- [minLon, maxLat, maxLon, minLat] = bbox;
- }
- params.bbox = [minLon, maxLat, maxLon, minLat];
-
return `${baseUrl}/events${util.toQueryString(params)}`;
}