Interactive interface for browsing global, full-resolution satellite imagery
various cleanup
Jason Kentd52c0fa2930b
diff --git a/web/js/components/sidebar/event.js b/web/js/components/sidebar/event.jsindex f42c61ebd..7a262d754 100644--- a/web/js/components/sidebar/event.js+++ b/web/js/components/sidebar/event.js@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';import lodashFind from 'lodash/find';import googleTagManager from 'googleTagManager';import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';-import { getDefaultEventDate } from '../../map/natural-events/util';+import { getDefaultEventDate } from '../../modules/natural-events/util';import util from '../../util/util';import EventIcon from './event-icon';@@ -15,15 +15,16 @@ function Event (props) {selectedDate,selectEvent,sources,- isVisible,} = props;const eventDate = util.parseDateUTC(event.geometry[0].date);- const dateString = `${util.giveWeekDay(eventDate)}, ${util.giveMonth(eventDate)} ${eventDate.getUTCDate()}, ${eventDate.getUTCFullYear()}`;+ const weekday = util.giveWeekDay(eventDate);+ const day = eventDate.getUTCDate();+ const month = util.giveMonth(eventDate);+ const year = eventDate.getUTCFullYear();+ const dateString = `${weekday}, ${month} ${day}, ${year}`;const itemClass = isSelected- ? 'item-selected selectorItem item item-visible'- : isVisible- ? 'selectorItem item'- : 'selectorItem item hidden';+ ? 'item-selected selectorItem item'+ : 'selectorItem item';const elRef = useRef();useLayoutEffect(() => {@@ -151,7 +152,6 @@ Event.propTypes = {deselectEvent: PropTypes.func,event: PropTypes.object,isSelected: PropTypes.bool,- isVisible: PropTypes.bool,selectedDate: PropTypes.string,selectEvent: PropTypes.func,sources: PropTypes.array,diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.jsindex 717746287..fb3bfb219 100644--- a/web/js/containers/sidebar/events.js+++ b/web/js/containers/sidebar/events.js@@ -16,12 +16,10 @@ import {selectEvent as selectEventActionCreator,deselectEvent as deselectEventActionCreator,} from '../../modules/natural-events/actions';-import { getEventsWithinExtent } from '../../map/natural-events/util';import { collapseSidebar } from '../../modules/sidebar/actions';import { selectDate } from '../../modules/date/actions';import { getSelectedDate } from '../../modules/date/selectors';import { toggleCustomContent } from '../../modules/modal/actions';-import AlertUtil from '../../components/util/alert';import util from '../../util/util';import { LIMIT_EVENT_REQUEST_COUNT } from '../../modules/natural-events/constants';@@ -33,7 +31,6 @@ function Events(props) {selectEvent,selected,openFilterModal,- visibleEventsInProjection,height,deselectEvent,hasRequestError,@@ -51,10 +48,6 @@ function Events(props) {const maxHeight = Math.max(height - dropdownHeight, 166);const scrollbarMaxHeight = isEmbedModeActive ? '50vh' : `${maxHeight}px`;- const missingEventDate = selected.id && !selected.date;- const selectedEventNotInData = !isLoading && selected.id && (eventsData || []).filter((event) => event.id === selected.id).length === 0;- let showInactiveEventAlert = missingEventDate || selectedEventNotInData;-const startDate = moment(selectedStartDate).format('YYYY MMM DD');const endDate = moment(selectedEndDate).format('YYYY MMM DD');@@ -65,116 +58,111 @@ function Events(props) {: '';const eventLimitReach = eventsData && eventsData.length === LIMIT_EVENT_REQUEST_COUNT;+ const numEvents = eventsData ? eventsData.length : 0;- return (- <div className="event-container">- <div className="filter-controls">-- <div className="filter-dates-icons">- <div className="filter-dates">- {showDates && `${startDate} - ${endDate}`}- </div>-- <div className="filter-icons">- {selectedCategories.map(({ title }) => (- <EventIcon- id="filter-"- key={title}- category={title}- title={title}- />- ))}- </div>+ const renderFilterControls = () => (+ <div className="filter-controls">+ <div className="filter-dates-icons">+ <div className="filter-dates">+ {showDates && `${startDate} - ${endDate}`}+ </div>+ <div className="filter-icons">+ {selectedCategories.map(({ title }) => (+ <EventIcon+ id="filter-"+ key={title}+ category={title}+ title={title}+ />+ ))}</div>- <Button- id="event-filter-button"- className="filter-button"- aria-label="Filtered layer search"- onClick={openFilterModal}- color="primary"- size="sm"- block- disabled={isLoading}- >- <FontAwesomeIcon icon="filter" />- </Button></div>-- <Scrollbars- className="event-scroll-list"- style={{ maxHeight: `${scrollbarMaxHeight}` }}+ <Button+ id="event-filter-button"+ className="filter-button"+ aria-label="Filtered layer search"+ onClick={openFilterModal}+ color="primary"+ size="sm"+ block+ disabled={isLoading}>- <div id="wv-events">- {(isLoading || hasRequestError || (isEmbedModeActive && showInactiveEventAlert)) && (- <div className="events-loading-text">- {hasRequestError && (<FontAwesomeIcon icon="exclamation-triangle" fixedWidth />)}- {errorOrLoadingText}- {(isEmbedModeActive && showInactiveEventAlert) && (- <>- <br />- {`The event with an id of ${selected.id} is no longer active.`}- </>- )}- </div>- )}+ <FontAwesomeIcon icon="filter" />+ </Button>+ </div>+ );- {eventsData && eventsData.length ? (- <div className="wv-eventslist sidebar-panel">- <ul id="wv-eventscontent" className="content map-item-list">- {sources && eventsData.map((event) => (- <Event- showAlert={showAlert}- key={event.id}- event={event}- selectEvent={(id, date) => selectEvent(id, date, isMobile && !isEmbedModeActive)}- deselectEvent={isEmbedModeActive ? () => null : deselectEvent}- isSelected={selected.id === event.id && visibleEventsInProjection[event.id]}- selectedDate={selectedDate}- isVisible={visibleEventsInProjection[event.id]}- sources={sources}- />- ))}- </ul>- </div>- ) : !isLoading && (- <h3 className="no-events"> No events meet current criteria</h3>- )}- </div>- </Scrollbars>+ const renderEventList = () => (+ <Scrollbars+ className="event-scroll-list"+ style={{ maxHeight: `${scrollbarMaxHeight}` }}+ >+ <div id="wv-events">+ {(isLoading || hasRequestError) && (+ <div className="events-loading-text">+ {hasRequestError && (<FontAwesomeIcon icon="exclamation-triangle" fixedWidth />)}+ {errorOrLoadingText}+ </div>+ )}- <div className="event-count">- {eventLimitReach && (- <>- <span>- Showing the first- {` ${eventsData ? eventsData.length : ''} `}- events- </span>- <FontAwesomeIcon id="filter-info-icon" icon="info-circle" />- <UncontrolledTooltip- placement="right"- target="filter-info-icon"- >- <div>- More than- {` ${LIMIT_EVENT_REQUEST_COUNT} `}- events matched the current filter criteria.- </div>- </UncontrolledTooltip>- </>+ {eventsData && eventsData.length ? (+ <div className="wv-eventslist sidebar-panel">+ <ul id="wv-eventscontent" className="content map-item-list">+ {sources && eventsData.map((event) => (+ <Event+ showAlert={showAlert}+ key={event.id}+ event={event}+ selectEvent={(id, date) => selectEvent(id, date, isMobile)}+ deselectEvent={deselectEvent}+ isSelected={selected.id === event.id}+ selectedDate={selectedDate}+ sources={sources}+ />+ ))}+ </ul>+ </div>+ ) : !isLoading && (+ <h3 className="no-events"> No events meet current criteria</h3>)}</div>+ </Scrollbars>+ );- {showInactiveEventAlert && (- <AlertUtil- id="event-unavailable-alert"- isOpen- onDismiss={() => { showInactiveEventAlert = false; }}- message={`The event with an id of ${selected.id} is no longer active.`}- />+ const renderEventCount = () => (+ <div className="event-count">+ {eventsData && eventLimitReach ? (+ <>+ <span>+ {`Showing the first ${numEvents} events`}+ </span>+ <FontAwesomeIcon id="filter-info-icon" icon="info-circle" />+ <UncontrolledTooltip+ placement="right"+ target="filter-info-icon"+ >+ <div>+ More than+ {` ${LIMIT_EVENT_REQUEST_COUNT} `}+ events matched the current filter criteria.+ </div>+ </UncontrolledTooltip>+ </>+ ) : (+ <span>+ {`Showing ${numEvents} events`}+ </span>)}</div>);++ return (+ <div className="event-container">+ {renderFilterControls()}+ {renderEventList()}+ {renderEventCount()}+ </div>+ );}const mapDispatchToProps = (dispatch) => ({@@ -202,31 +190,19 @@ const mapDispatchToProps = (dispatch) => ({},});-const mapStateToProps = (state, ownProps) => {+const mapStateToProps = (state) => {const {animation,embed,- proj,browser,events,} = state;- const { eventsData } = ownProps;+const {selected, showAll, selectedDates, selectedCategories,} = events;- let visibleEventsInProjection = {};const { isEmbedModeActive } = embed;- if (eventsData) {- // TODO don't check this in mapStateToProps or memoize it- visibleEventsInProjection = getEventsWithinExtent(- eventsData,- selected,- proj.selected,- proj.selected.maxExtent,- );- }-return {isPlaying: animation.isPlaying,isMobile: browser.lessThan.medium,@@ -239,7 +215,6 @@ const mapStateToProps = (state, ownProps) => {selectedStartDate: selectedDates.start,selectedEndDate: selectedDates.end,selectedDate: util.toISOStringDate(getSelectedDate(state)),- visibleEventsInProjection,};};export default connect(@@ -265,5 +240,4 @@ Events.propTypes = {selectEvent: PropTypes.func,showAlert: PropTypes.bool,sources: PropTypes.array,- visibleEventsInProjection: PropTypes.object,};diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.jsindex 4fc2729ef..7bbb88cb0 100644--- a/web/js/containers/sidebar/sidebar.js+++ b/web/js/containers/sidebar/sidebar.js@@ -17,9 +17,12 @@ import NavCase from '../../components/sidebar/nav/nav-case';import {loadCustom as loadCustomPalette,} from '../../modules/palettes/util';-import { loadedCustomPalettes } from '../../modules/palettes/actions';+import {+ loadedCustomPalettes as loadedCustomPalettesAction,+} from '../../modules/palettes/actions';import { getSelectedDate } from '../../modules/date/selectors';import { getPermalink } from '../../modules/link/util';+import {requestEvents as requestEventsActionCreator,requestSources as requestSourcesActionCreator,@@ -35,7 +38,7 @@ import {} from '../../modules/sidebar/actions';import history from '../../main';import safeLocalStorage from '../../util/local-storage';-import { getEventsRequestURL } from '../../map/natural-events/util';+import { getEventsRequestURL } from '../../modules/natural-events/util';const { SIDEBAR_COLLAPSED } = safeLocalStorage.keys;@@ -123,12 +126,14 @@ class Sidebar extends React.Component {let sourcesURL = `${baseUrl}/sources`;if (mockEvents) {+ // eslint-disable-next-line no-consoleconsole.warn(`Using mock events data: ${mockEvents}`);eventsURL = mockEvents === 'true'? 'mock/events_data.json': `mock/events_data.json-${mockEvents}`;}if (mockSources) {+ // eslint-disable-next-line no-consoleconsole.warn(`Using mock categories data: ${mockSources}`);sourcesURL = `mock/categories_data.json-${mockSources}`;}@@ -453,7 +458,7 @@ const mapDispatchToProps = (dispatch) => ({dispatch(expandSidebarAction());},loadedCustomPalettes: (customs) => {- dispatch(loadedCustomPalettes(customs));+ dispatch(loadedCustomPalettesAction(customs));},requestEvents: (url) => {dispatch(requestEventsActionCreator(url));diff --git a/web/js/map/natural-events/event-markers.js b/web/js/map/natural-events/event-markers.jsindex 8d4fcc53e..02a854549 100644--- a/web/js/map/natural-events/event-markers.js+++ b/web/js/map/natural-events/event-markers.js@@ -15,7 +15,7 @@ import * as olProj from 'ol/proj';import googleTagManager from 'googleTagManager';import EventIcon from '../../components/sidebar/event-icon';import { selectEvent as selectEventAction } from '../../modules/natural-events/actions';-import { getDefaultEventDate } from './util';+import { getDefaultEventDate } from '../../modules/natural-events/util';import { getEventsFilteredCategories } from '../../modules/natural-events/selectors';const icons = [diff --git a/web/js/map/natural-events/natural-events.js b/web/js/map/natural-events/natural-events.jsindex f4031fdb2..8421993d1 100644--- a/web/js/map/natural-events/natural-events.js+++ b/web/js/map/natural-events/natural-events.js@@ -3,7 +3,7 @@ import { connect } from 'react-redux';import PropTypes from 'prop-types';import * as olExtent from 'ol/extent';import * as olProj from 'ol/proj';-import { getDefaultEventDate, getEventsWithinExtent } from './util';+import { getDefaultEventDate } from '../../modules/natural-events/util';import util from '../../util/util';import { selectDate as selectDateAction } from '../../modules/date/actions';import { selected as selectedAction } from '../../modules/natural-events/actions';@@ -37,6 +37,7 @@ class NaturalEvents extends React.Component {proj,eventsDataIsLoading,selectedEvent,+ eventsData,} = this.props;const loadingChange = eventsDataIsLoading !== prevProps.eventsDataIsLoading;const projChange = proj !== prevProps.proj;@@ -47,7 +48,7 @@ class NaturalEvents extends React.Component {// When changing projection, zoom to the selected event if it is visibleif (projChange && selectedEvent) {const { id, date } = selectedEvent;- const event = this.filterEventList().find((e) => e.id === id);+ const event = eventsData.find((e) => e.id === id);if (event) {this.zoomToEvent(event, date);}@@ -63,20 +64,6 @@ class NaturalEvents extends React.Component {}}- filterEventList() {- const {- proj, eventsData, selectedEvent,- } = this.props;-- const eventsInExtentMap = getEventsWithinExtent(- eventsData,- selectedEvent,- proj.selected,- proj.selected.maxExtent,- );- return eventsData.filter((e) => eventsInExtentMap[e.id]);- }-getZoomPromise = function(event,date,diff --git a/web/js/map/natural-events/util.js b/web/js/map/natural-events/util.jsdeleted file mode 100644index 7e63fa6a4..000000000--- a/web/js/map/natural-events/util.js+++ /dev/null@@ -1,118 +0,0 @@-import {- find as lodashFind,-} from 'lodash';-import { transform } from 'ol/proj';-import { getCenter, boundingExtent, containsCoordinate } from 'ol/extent';-import moment from 'moment';-import * as olProj from 'ol/proj';-import util from '../../util/util';-import {- LIMIT_EVENT_REQUEST_COUNT,-} from '../../modules/natural-events/constants';--const geographicProj = 'EPSG:4326';--export function getEventsRequestURL (baseUrl, selectedDates, categories = [], proj, bbox) {- const { crs } = proj.selected;- const params = {- status: 'all',- limit: LIMIT_EVENT_REQUEST_COUNT,- };- const { start, end } = selectedDates;- const transformCoords = (coords) => olProj.transform(coords, crs, geographicProj);-- if (start && end) {- params.start = moment.utc(start).format('YYYY-MM-DD');- params.end = moment.utc(end).format('YYYY-MM-DD');- }- if (categories.length) {- params.category = categories.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') {- const [minLonA, minLatA, maxLonA, maxLatA] = bbox;- [minLon, maxLat] = transformCoords([minLonA, maxLatA]);- [maxLon, minLat] = transformCoords([maxLonA, minLatA]);- }- params.bbox = [minLon, maxLat, maxLon, minLat];-- return `${baseUrl}/events${util.toQueryString(params)}`;-}--/**- *- * @param {*} event- */-export function getDefaultEventDate(event) {- const preDate = event.geometry[0] && event.geometry[0].date;- let date = new Date(preDate).toISOString().split('T')[0];- if (event.geometry.length < 2) return date;- const category = event.categories.title || event.categories[0].title;- const today = new Date().toISOString().split('T')[0];- // For storms that happened today, get previous date- if (date === today && category === 'Severe Storms') {- [date] = new Date(event.geometry[1].date).toISOString().split('T');- }- return date;-}--/**- *- * @param {*} events- * @param {*} selected- * @param {*} extent- * @param {*} selectedProj- * @param {*} showAll- */-export function getEventsWithinExtent(- events,- selected,- selectedProj,- maxExtent,-) {- const { crs } = selectedProj;- const visibleListEvents = {};-- events.forEach((naturalEvent) => {- let date = getDefaultEventDate(naturalEvent);- if (selected && selected.date) {- date = selected.date;- }- const geometry = lodashFind(- naturalEvent.geometry,- (geom) => geom.date.split('T')[0] === date,- ) || naturalEvent.geometry[0];-- let { coordinates } = geometry;-- if (selectedProj.id !== 'geographic') {- if (geometry.type === 'Polygon') {- const coordinatesTransform = coordinates[0].map(- (coordinate) => transform(coordinate, 'EPSG:4326', crs),- );- const geomExtent = boundingExtent(coordinatesTransform);- coordinates = getCenter(geomExtent);- } else {- coordinates = transform(coordinates, 'EPSG:4326', crs);- }- } else if (geometry.type === 'Polygon') {- const geomExtent = boundingExtent(geometry.coordinates[0]);- coordinates = getCenter(geomExtent);- }-- const visibleInExtent = containsCoordinate(maxExtent, coordinates);-- if (visibleInExtent) {- visibleListEvents[naturalEvent.id] = true;- }- });-- return visibleListEvents;-}diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.jsindex 5ace850c7..52256376b 100644--- a/web/js/modules/natural-events/actions.js+++ b/web/js/modules/natural-events/actions.js@@ -4,7 +4,7 @@ import {} from 'lodash';import {getEventsRequestURL,-} from '../../map/natural-events/util';+} from './util';import {REQUEST_EVENTS,diff --git a/web/js/modules/natural-events/util.js b/web/js/modules/natural-events/util.jsindex 37f38ebde..cd5b21a51 100644--- a/web/js/modules/natural-events/util.js+++ b/web/js/modules/natural-events/util.js@@ -1,5 +1,10 @@import { get } from 'lodash';import update from 'immutability-helper';+import moment from 'moment';+import util from '../../util/util';+import {+ LIMIT_EVENT_REQUEST_COUNT,+} from './constants';export function parseEvent(eventString) {const values = eventString.split(',');@@ -95,3 +100,51 @@ export function mapLocationToEventFilterState(parameters, stateFromLocation, sta},});}++export function getEventsRequestURL (baseUrl, selectedDates, categories = [], proj, bbox) {+ const { crs } = proj.selected;+ const params = {+ status: 'all',+ limit: LIMIT_EVENT_REQUEST_COUNT,+ };+ const { start, end } = selectedDates;++ if (start && end) {+ params.start = moment.utc(start).format('YYYY-MM-DD');+ params.end = moment.utc(end).format('YYYY-MM-DD');+ }+ if (categories.length) {+ params.category = categories.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)}`;+}++/**+ *+ * @param {*} event+ */+export function getDefaultEventDate(event) {+ const preDate = event.geometry[0] && event.geometry[0].date;+ let date = new Date(preDate).toISOString().split('T')[0];+ if (event.geometry.length < 2) return date;+ const category = event.categories.title || event.categories[0].title;+ const today = new Date().toISOString().split('T')[0];+ // For storms that happened today, get previous date+ if (date === today && category === 'Severe Storms') {+ [date] = new Date(event.geometry[1].date).toISOString().split('T');+ }+ return date;+}