Interactive interface for browsing global, full-resolution satellite imagery
projection based filtering on query
Jason Kent6e1979759e7c
diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.jsindex a5bddb883..719050f06 100644--- a/web/js/containers/sidebar/events.js+++ b/web/js/containers/sidebar/events.js@@ -33,7 +33,7 @@ function Events(props) {selectEvent,selected,openFilterModal,- visibleEvents,+ visibleEventsInProjection,height,deselectEvent,hasRequestError,@@ -60,6 +60,7 @@ function Events(props) {: hasRequestError? 'There has been an ERROR retrieving events from the EONET events API. Please try again later.': '';+const eventLimitReach = eventsData && eventsData.length === LIMIT_EVENT_REQUEST_COUNT;return (@@ -101,14 +102,14 @@ function Events(props) {events<FontAwesomeIcon id="filter-info-icon" icon="info-circle" /><UncontrolledTooltip- placement="top"+ placement="right"target="filter-info-icon">- More than- {' '}- {LIMIT_EVENT_REQUEST_COUNT}- {' '}- events matched the current filter criteria.+ <div>+ More than+ {` ${LIMIT_EVENT_REQUEST_COUNT} `}+ events matched the current filter criteria.+ </div></UncontrolledTooltip></div>)}@@ -141,9 +142,9 @@ function Events(props) {event={event}selectEvent={(id, date) => selectEvent(id, date, isMobile && !isEmbedModeActive)}deselectEvent={isEmbedModeActive ? () => null : deselectEvent}- isSelected={selected.id === event.id && visibleEvents[event.id]}+ isSelected={selected.id === event.id && visibleEventsInProjection[event.id]}selectedDate={selectedDate}- isVisible={visibleEvents[event.id]}+ isVisible={visibleEventsInProjection[event.id]}sources={sources}/>))}@@ -206,21 +207,13 @@ const mapStateToProps = (state, ownProps) => {const {selected, showAll, selectedDates, selectedCategories,} = events;- let visibleEvents = {};+ let visibleEventsInProjection = {};const mapExtent = lodashGet(state, 'map.extent');- let visibleWithinMapExtent = {};const { isEmbedModeActive } = embed;if (eventsData && mapExtent) {- visibleWithinMapExtent = getEventsWithinExtent(- eventsData,- selected,- proj.selected.maxExtent,- proj.selected,- true,- );const extent = showAll ? proj.selected.maxExtent : mapExtent;- visibleEvents = getEventsWithinExtent(+ visibleEventsInProjection = getEventsWithinExtent(eventsData,selected,extent,@@ -232,8 +225,7 @@ const mapStateToProps = (state, ownProps) => {return {showAll,selected,- visibleWithinMapExtent,- visibleEvents,+ visibleEventsInProjection,isPlaying: animation.isPlaying,isMobile: browser.lessThan.medium,isEmbedModeActive,@@ -268,5 +260,5 @@ Events.propTypes = {selectEvent: PropTypes.func,showAlert: PropTypes.bool,sources: PropTypes.array,- visibleEvents: PropTypes.object,+ visibleEventsInProjection: PropTypes.object,};diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.jsindex dbfaafde7..ca83c7e6a 100644--- a/web/js/containers/sidebar/sidebar.js+++ b/web/js/containers/sidebar/sidebar.js@@ -32,7 +32,7 @@ import {} from '../../modules/sidebar/actions';import history from '../../main';import safeLocalStorage from '../../util/local-storage';-import { initialEventsLoad } from '../../map/natural-events/util';+import { getEventsRequestURL } from '../../map/natural-events/util';const { SIDEBAR_COLLAPSED } = safeLocalStorage.keys;@@ -85,20 +85,22 @@ class Sidebar extends React.Component {}}- componentDidUpdate() {- const { activeTab } = this.props;+ componentDidUpdate(prevProps) {+ const { activeTab, proj } = this.props;if (activeTab === 'events') {- this.loadEvents();+ const projChange = proj !== prevProps.proj;+ this.loadEvents(projChange);}this.updateDimensions();}- loadEvents() {+ loadEvents(projChanged) {const {isLoadingEvents,hasEventRequestError,eventsData,config,+ proj,requestEvents,requestSources,selectedStartDate,@@ -106,12 +108,29 @@ class Sidebar extends React.Component {selectedCategories,} = this.props;- if (!isLoadingEvents && !hasEventRequestError && !eventsData) {- const {- sourcesURL, eventsURL,- } = initialEventsLoad(config, selectedStartDate, selectedEndDate, selectedCategories);+ const baseUrl = lodashGet(config, 'features.naturalEvents.host');+ const mockEvents = lodashGet(config, 'parameters.mockEvents');+ const mockSources = lodashGet(config, 'parameters.mockSources');+ let eventsURL = getEventsRequestURL(baseUrl, selectedStartDate, selectedEndDate, selectedCategories, proj);+ let sourcesURL = `${baseUrl}/sources`;++ if (mockEvents) {+ console.warn(`Using mock events data: ${mockEvents}`);+ eventsURL = mockEvents === 'true'+ ? 'mock/events_data.json'+ : `mock/events_data.json-${mockEvents}`;+ }+ if (mockSources) {+ console.warn(`Using mock categories data: ${mockSources}`);+ sourcesURL = `mock/categories_data.json-${mockSources}`;+ }++ const initialLoad = !isLoadingEvents && !hasEventRequestError && !eventsData;+ if (initialLoad) {requestEvents(eventsURL);requestSources(sourcesURL);+ } else if (projChanged) {+ requestEvents(eventsURL);}}@@ -352,6 +371,7 @@ const mapStateToProps = (state) => {requestedEventSources,sidebar,ui,+ proj,} = state;const isLoadingEvents = requestedEvents.isLoading@@ -392,6 +412,7 @@ const mapStateToProps = (state) => {isEmbedModeActive,isLoadingEvents,isMobile,+ proj,selectedStartDate: events.selectedDates.start,selectedEndDate: events.selectedDates.end,selectedCategories: events.selectedCategories,@@ -454,6 +475,7 @@ Sidebar.propTypes = {loadedCustomPalettes: PropTypes.func,numberOfLayers: PropTypes.number,onTabClick: PropTypes.func,+ proj: PropTypes.object,screenHeight: PropTypes.number,selectedStartDate: PropTypes.string,selectedEndDate: PropTypes.string,diff --git a/web/js/map/natural-events/util.js b/web/js/map/natural-events/util.jsindex 6ad53f174..5b9aa29de 100644--- a/web/js/map/natural-events/util.js+++ b/web/js/map/natural-events/util.js@@ -1,6 +1,5 @@import {find as lodashFind,- get as lodashGet,} from 'lodash';import * as olProj from 'ol/proj';import { getCenter, boundingExtent, containsCoordinate } from 'ol/extent';@@ -8,7 +7,7 @@ import moment from 'moment';import util from '../../util/util';import { LIMIT_EVENT_REQUEST_COUNT } from '../../modules/natural-events/constants';-export function getEventsRequestURL (baseUrl, startDate, endDate, categories = []) {+export function getEventsRequestURL (baseUrl, startDate, endDate, categories = [], proj) {const params = {status: 'all',limit: LIMIT_EVENT_REQUEST_COUNT,@@ -20,31 +19,18 @@ export function getEventsRequestURL (baseUrl, startDate, endDate, categories = [if (categories.length) {params.category = categories.map(({ id }) => id).join(',');}- return `${baseUrl}/events${util.toQueryString(params)}`;-}--export function initialEventsLoad (config, startDate, endDate, categories) {- const baseUrl = lodashGet(config, 'features.naturalEvents.host');- let eventsURL = getEventsRequestURL(baseUrl, startDate, endDate, categories);- let sourcesURL = `${baseUrl}/sources`;-- const mockEvents = lodashGet(config, 'parameters.mockEvents');- const mockSources = lodashGet(config, 'parameters.mockSources');- if (mockEvents) {- console.warn(`Using mock events data: ${mockEvents}`);- eventsURL = mockEvents === 'true'- ? 'mock/events_data.json'- : `mock/events_data.json-${mockEvents}`;+ let [minLon, maxLat, maxLon, minLat] = [-180, 90, 180, -90];+ const { crs } = proj.selected;+ if (crs === 'EPSG:3413') {+ [minLon, maxLat, maxLon, minLat] = [-180, 45, 180, 90];}- if (mockSources) {- console.warn(`Using mock categories data: ${mockSources}`);- sourcesURL = `mock/categories_data.json-${mockSources}`;+ if (crs === 'EPSG:3031') {+ [minLon, maxLat, maxLon, minLat] = [-180, -90, 180, -45];}- return {- sourcesURL,- eventsURL,- };+ params.bbox = [minLon, maxLat, maxLon, minLat];++ return `${baseUrl}/events${util.toQueryString(params)}`;}/**diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.jsindex 705c8cb40..57fb17dc8 100644--- a/web/js/modules/natural-events/actions.js+++ b/web/js/modules/natural-events/actions.js@@ -55,9 +55,9 @@ export function showAll() {export function setEventsFilter(categories, startDate, endDate) {return (dispatch, getState) => {- const { config } = getState();+ const { config, proj } = getState();const baseUrl = lodashGet(config, 'features.naturalEvents.host');- const requestUrl = getEventsRequestURL(baseUrl, startDate, endDate, categories);+ const requestUrl = getEventsRequestURL(baseUrl, startDate, endDate, categories, proj);dispatch(requestEvents(requestUrl));dispatch({type: SET_EVENTS_FILTER,diff --git a/web/js/modules/natural-events/reducers.js b/web/js/modules/natural-events/reducers.jsindex 0a28840dd..847ab1f9e 100644--- a/web/js/modules/natural-events/reducers.js+++ b/web/js/modules/natural-events/reducers.js@@ -40,7 +40,7 @@ const sortEvents = function(events) {};const endDate = util.toISOStringDate(new Date());-const startDate = util.toISOStringDate(new Date(new Date().setDate(new Date().getDate() - 60)));+const startDate = util.toISOStringDate(new Date(new Date().setDate(new Date().getDate() - 120)));export function getInitialEventsState(config) {const { categories } = config.naturalEvents;