Interactive interface for browsing global, full-resolution satellite imagery
Implement event checkbox toggle #1554 #1576 #1622
Benjamin King3e84f57f2cde
diff --git a/web/css/events.css b/web/css/events.cssindex 6f2772c4b..64bd1f5d4 100644--- a/web/css/events.css+++ b/web/css/events.css@@ -410,3 +410,8 @@display: list-item;margin: 2px 0 2px 20px;}+.events-footer-case {+ color: #fff;+ padding-top: 5px;+ border-top: 0.5px solid rgba(250, 250, 250, 0.5);+}diff --git a/web/js/components/sidebar/event.js b/web/js/components/sidebar/event.jsindex f85d9e315..77db7b82e 100644--- a/web/js/components/sidebar/event.js+++ b/web/js/components/sidebar/event.js@@ -5,6 +5,10 @@ import lodashFind from 'lodash/find';import googleTagManager from 'googleTagManager';class Event extends React.Component {+ constructor(props) {+ super(props);+ this.onClick = this.onClick.bind(this);+ }/*** Return date list for selected event*/@@ -21,7 +25,10 @@ class Event extends React.Component {return (<li key={event.id + '-' + date} className="dates"><a- onClick={this.onClick.bind(this, date, null)}+ onClick={e => {+ e.stopPropagation();+ this.onClick(date);+ }}className={selectedDate === date? 'date item-selected active'@@ -43,11 +50,15 @@ class Event extends React.Component {* @param {Boolean} isSelected | Is this event already selected* @param {Object} e | Event Object*/- onClick(date, isSelected, e) {- e.preventDefault();- e.stopPropagation();- const { selectEvent, event, deselectEvent } = this.props;- if (isSelected) {+ onClick(date) {+ const {+ selectEvent,+ event,+ deselectEvent,+ isSelected,+ selectedDate+ } = this.props;+ if (isSelected && (!date || date === selectedDate)) {deselectEvent();} else {selectEvent(event.id, date);@@ -96,7 +107,7 @@ class Event extends React.Component {}}render() {- const { event, selectedDate, isVisible } = this.props;+ const { event, isVisible, isSelected } = this.props;const eventDate = util.parseDateUTC(event.geometries[0].date);var dateString =util.giveWeekDay(eventDate) +@@ -110,13 +121,16 @@ class Event extends React.Component {return (<liclassName={- selectedDate+ isSelected? 'item-selected selectorItem item item-visible': isVisible? 'selectorItem item': 'selectorItem item hidden'}- onClick={this.onClick.bind(this, null, !!selectedDate)}+ onClick={e => {+ e.stopPropagation();+ this.onClick();+ }}id={'sidebar-event-' + util.encodeId(event.id)}><idiff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.jsindex 3b1a11731..8756ef7de 100644--- a/web/js/containers/sidebar/events.js+++ b/web/js/containers/sidebar/events.js@@ -57,7 +57,6 @@ class Events extends React.Component {render() {const {events,- showAll,isLoading,selectEvent,selected,@@ -97,13 +96,15 @@ class Events extends React.Component {event={event}selectEvent={() => selectEvent(event.id, event.date)}deselectEvent={deselectEvent}+ isSelected={+ selected.id === event.id && visibleEvents[event.id]+ }selectedDate={- selected.id === event.id &&- (showAll || visibleEvents[event.id])+ selected.id === event.id && visibleEvents[event.id]? selected.date: null}- isVisible={visibleEvents[event.id] || showAll}+ isVisible={visibleEvents[event.id]}sources={sources}/>))@@ -137,7 +138,8 @@ function mapStateToProps(state) {requestedEvents,requestedEventSources,requestedEventCategories,- config+ config,+ proj} = state;const { selected, showAll } = state.events;@@ -154,11 +156,13 @@ function mapStateToProps(state) {const events = lodashGet(requestedEvents, 'response');const sources = lodashGet(requestedEventSources, 'response');if (events && state.legacy.map.extent) {+ let extent = showAll ? proj.selected.maxExtent : state.legacy.map.extent;visibleEvents = getEventsWithinExtent(events,selected,- state.legacy.map.extent,- state+ extent,+ proj.selected,+ showAll);}diff --git a/web/js/containers/sidebar/footer-content.js b/web/js/containers/sidebar/footer-content.jsindex 80a4232a3..dc725ceab 100644--- a/web/js/containers/sidebar/footer-content.js+++ b/web/js/containers/sidebar/footer-content.js@@ -1,6 +1,7 @@import React from 'react';import PropTypes from 'prop-types';import Button from '../../components/util/button';+import { Checkbox } from '../../components/util/checkbox';import ModeSelection from '../../components/sidebar/mode-selection';import googleTagManager from 'googleTagManager';import { get as lodashGet } from 'lodash';@@ -12,25 +13,25 @@ import {} from '../../modules/data/selectors';import ProductPicker from '../../components/layer/product-picker/product-picker';import { openCustomContent } from '../../modules/modal/actions';+import { toggleListAll } from '../../modules/natural-events/actions';import { DATA_GET_DATA_CLICK } from '../../modules/data/constants';class FooterContent extends React.Component {render() {const {- showListAllButton,isCompareActive,compareMode,isMobile,- events,activeTab,- filterEventList,+ toggleListAll,onGetData,changeCompareMode,addLayers,toggleCompare,counts,dataSelectionSize,- compareFeature+ compareFeature,+ showAll} = this.props;if (activeTab === 'layers') {return (@@ -71,27 +72,14 @@ class FooterContent extends React.Component {);} else if (activeTab === 'events') {return (- <div- className="events-footer-case"- style={- !showListAllButton || !events- ? { display: 'none' }- : { display: 'block' }- }- >- <p>Only selected events and events in current map view are listed</p>- <Button+ <div className="events-footer-case">+ <CheckboxclassName="red"- onClick={e => {- e.stopPropagation();- if (filterEventList) {- filterEventList(true);- googleTagManager.pushEvent({- event: 'natural_events_list_all'- });- }- }}+ id="events-footer-checkbox"+ label="Only show events in current view"+ onCheck={toggleListAll}text="List All"+ checked={!showAll}/></div>);@@ -142,6 +130,9 @@ const mapDispatchToProps = dispatch => ({onGetData: () => {dispatch({ type: DATA_GET_DATA_CLICK });},+ toggleListAll: () => {+ dispatch(toggleListAll());+ },addLayers: () => {dispatch(openCustomContent('LAYER_PICKER_COMPONENT', {@@ -159,7 +150,6 @@ function mapStateToProps(state, ownProps) {const { requestedEvents, config, layers, data, compare } = state;const { showAll } = state.events;const { selectedGranules } = data;- const showListAllButton = !showAll;const events = lodashGet(requestedEvents, 'response');const activeString = compare.isCompareA ? 'active' : 'activeB';const activeLayers = layers[activeString];@@ -167,7 +157,7 @@ function mapStateToProps(state, ownProps) {const dataSelectionSize = getDataSelectionSize(selectedGranules);return {- showListAllButton,+ showAll,activeTab,events,counts,diff --git a/web/js/location.js b/web/js/location.jsindex e5c3795b1..ecb553c4b 100644--- a/web/js/location.js+++ b/web/js/location.js@@ -17,6 +17,7 @@ import { resetLayers, hasSubDaily } from './modules/layers/selectors';import { eventsReducerState } from './modules/natural-events/reducers';import { mapLocationToPaletteState } from './modules/palettes/util';import { mapLocationToAnimationState } from './modules/animation/util';+import { mapLocationToSidebarState } from './modules/sidebar/util';import util from './util/util';import update from 'immutability-helper';@@ -33,6 +34,7 @@ export function mapLocationToState(state, location) {if (location.search) {let parameters = util.fromQueryString(location.search);let stateFromLocation = location.query;+stateFromLocation = mapLocationToProjState(parameters,stateFromLocation,@@ -60,6 +62,12 @@ export function mapLocationToState(state, location) {state,config);+ stateFromLocation = mapLocationToSidebarState(+ parameters,+ stateFromLocation,+ state,+ config+ );// one level deep merge of newState with defaultStatefor (var key in stateFromLocation) {const obj = lodashAssign({}, state[key], stateFromLocation[key]);diff --git a/web/js/map/natural-events/track.js b/web/js/map/natural-events/track.jsindex 54d9814d1..d3b7473dd 100644--- a/web/js/map/natural-events/track.js+++ b/web/js/map/natural-events/track.js@@ -28,7 +28,7 @@ import { selectEvent as selectEventAction } from '../../modules/natural-events/aconst firstClusterObj = naturalEventsClusterCreateObject(); // Cluster before selected eventconst secondClusterObj = naturalEventsClusterCreateObject(); // Cluster after selected event-export default function naturalEventsTrack(ui, store) {+export default function naturalEventsTrack(ui, store, selectedMap) {var self = {};self.trackDetails = {};self.active = false;@@ -105,7 +105,7 @@ export default function naturalEventsTrack(ui, store) {return onSidebarChange(action.activeTab);case CHANGE_PROJECTION:// update/remove track on projection change- if (self.trackDetails.id) return self.update(null, ui.map.selected);+ if (self.trackDetails.id) return self.update(null, selectedMap);}};const onSidebarChange = function(tab) {diff --git a/web/js/map/natural-events/ui.js b/web/js/map/natural-events/ui.jsindex e82ccd979..db4792335 100644--- a/web/js/map/natural-events/ui.js+++ b/web/js/map/natural-events/ui.js@@ -56,6 +56,8 @@ export default function naturalEventsUI(ui, config, store) {return onSidebarChange(action.activeTab);case EVENT_CONSTANTS.SELECT_EVENT:return self.selectEvent(action.id, action.date);+ case EVENT_CONSTANTS.DESELECT_EVENT:+ return self.deselectEvent();case EVENT_CONSTANTS.REQUEST_EVENTS_SUCCESS:case EVENT_CONSTANTS.REQUEST_SOURCES_SUCCESS:case EVENT_CONSTANTS.REQUEST_CATEGORIES_SUCCESS:@@ -130,8 +132,8 @@ export default function naturalEventsUI(ui, config, store) {const state = store.getState();map = ui.map.selected;view = map.getView();- naturalEventMarkers = markers(ui, config);- naturalEventsTrack = track(ui, config);+ naturalEventMarkers = markers(ui, store, map);+ naturalEventsTrack = track(ui, store, map);// filter events within projection view extentself.filterEventList();@@ -347,9 +349,10 @@ export default function naturalEventsUI(ui, config, store) {** @param {Boolean} showAll - show all available points in projection*/- self.filterEventList = function(showAll) {+ self.filterEventList = function() {const state = store.getState();const proj = state.proj;+ const showAll = state.events.showAll;if (isLoading || !state.sidebar.activeTab === 'events') return;var hiddenEventsCounter = self.markers.length;var extent = view.calculateExtent();diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.jsindex e530df4cb..449478487 100644--- a/web/js/modules/date/util.js+++ b/web/js/modules/date/util.js@@ -1,72 +1,6 @@import util from '../../util/util';-import { get, each as lodashEach } from 'lodash';+import { each as lodashEach } from 'lodash';-export function getDateParameterSetup(- parameters,- config,- models,- legacyState,- errors-) {- const initialState = models.date.selected;- const modelLoaded = models.date.load(legacyState, errors);- const bInit = util.dateAdd(initialState, 'day', -7);- return {- t: {- stateKey: 'legacy.date.selected',- initialState: initialState,- type: 'date',- options: {- serializeNeedsGlobalState: true,- setAsEmptyItem: true,- serialize: (currentItemState, state) => {- // intense hacking!- // just a temporary crutch- const isActive = get(state, 'legacy.compare.active');- const isCompareA = get(models, 'compare.isCompareA');- const dateB = get(models, 'date.selectedB');- if (!currentItemState) currentItemState = initialState;- return !isActive && !isCompareA- ? serializeDate(dateB)- : initialState === currentItemState- ? undefined- : serializeDate(currentItemState);- },- parse: str => {- return tryCatchDate(str, initialState);- }- }- },- t1: {- stateKey: 'legacy.date.selectedB',- initialState: bInit,- options: {- serializeNeedsGlobalState: true,- serialize: (currentItemState, state) => {- const isActive = get(state, 'legacy.compare.active');- if (!isActive) return undefined;- if (!currentItemState) currentItemState = bInit;- return serializeDate(currentItemState || bInit);- },- parse: str => {- return tryCatchDate(str, bInit);- }- }- },- z: {- stateKey: 'legacy.date.selectedZoom',- initialState: 3,- options: {- parse: str => {- return str ? Number(str) : 3;- },- serialize: () => {- return models.date.selectedZoom.toString();- }- }- }- };-}export function serializeDate(date) {return (date.toISOString().split('T')[0] +@@ -80,9 +14,9 @@ export function serializeDate(date) {);}export function getActiveTime(state) {- const { compare, legacy } = state;+ const { compare, date } = state;const activeStr = compare.isCompareA ? 'selected' : 'selectedB';- return legacy.date[activeStr];+ return date[activeStr];}export function tryCatchDate(str, initialState) {try {diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.jsindex 94b6f3f22..724b5cb1c 100644--- a/web/js/modules/natural-events/actions.js+++ b/web/js/modules/natural-events/actions.js@@ -5,7 +5,8 @@ import {SELECT_EVENT,DESELECT_EVENT,SHOW_ALL_EVENTS,- ONLY_SHOW_VISIBLE+ ONLY_SHOW_VISIBLE,+ TOGGLE_SHOW_ALL} from './constants';import { requestAction } from '../core/actions';@@ -41,7 +42,6 @@ export function requestSources(location) {}export function selectEvent(id, date) {- console.log(id, date);return {type: SELECT_EVENT,id: id,@@ -62,6 +62,11 @@ export function showAll() {type: SHOW_ALL_EVENTS};}+export function toggleListAll() {+ return {+ type: TOGGLE_SHOW_ALL+ };+}export function onlyShowVisible() {return {diff --git a/web/js/modules/natural-events/constants.js b/web/js/modules/natural-events/constants.jsindex cb54ba5ba..1609578c9 100644--- a/web/js/modules/natural-events/constants.js+++ b/web/js/modules/natural-events/constants.js@@ -17,3 +17,4 @@ export const DESELECT_EVENT = 'EVENTS/DESELECT_EVENT';export const SELECT_EVENT = 'EVENTS/SELECT_EVENT';export const SHOW_ALL_EVENTS = 'EVENTS/SHOW_ALL_EVENTS';export const ONLY_SHOW_VISIBLE = 'EVENTS/ONLY_SHOW_VISIBLE';+export const TOGGLE_SHOW_ALL = 'EVENTS/TOGGLE_SHOW_ALL';diff --git a/web/js/modules/natural-events/reducers.js b/web/js/modules/natural-events/reducers.jsindex f45d9e427..77b89bb6b 100644--- a/web/js/modules/natural-events/reducers.js+++ b/web/js/modules/natural-events/reducers.js@@ -5,7 +5,8 @@ import {SELECT_EVENT,DESELECT_EVENT,SHOW_ALL_EVENTS,- ONLY_SHOW_VISIBLE+ ONLY_SHOW_VISIBLE,+ TOGGLE_SHOW_ALL} from './constants';import { CHANGE_TAB as CHANGE_SIDEBAR_TAB } from '../sidebar/constants';import {@@ -46,7 +47,7 @@ export const eventsReducerState = {date: null},active: false,- showAll: false+ showAll: true};export function eventsReducer(state = eventsReducerState, action) {@@ -58,14 +59,22 @@ export function eventsReducer(state = eventsReducerState, action) {date: action.date}});+case DESELECT_EVENT:return lodashAssign({}, state, {- selected: {}+ selected: {+ id: '',+ date: null+ }});case SHOW_ALL_EVENTS:return lodashAssign({}, state, {showAll: true});+ case TOGGLE_SHOW_ALL:+ return lodashAssign({}, state, {+ showAll: !state.showAll+ });case ONLY_SHOW_VISIBLE:return lodashAssign({}, state, {showAll: falsediff --git a/web/js/modules/natural-events/selectors.js b/web/js/modules/natural-events/selectors.jsindex a041321cb..508fc7ccd 100644--- a/web/js/modules/natural-events/selectors.js+++ b/web/js/modules/natural-events/selectors.js@@ -2,8 +2,13 @@ import { find as lodashFind, get as lodashGet } from 'lodash';import * as olProj from 'ol/proj';import * as olExtent from 'ol/extent';-export function getEventsWithinExtent(loadedEvents, selected, extent, state) {- const selectedProj = lodashGet(state, 'proj.selected');+export function getEventsWithinExtent(+ loadedEvents,+ selected,+ extent,+ selectedProj,+ showAll+) {var maxExtent = selectedProj.maxExtent;var visibleListEvents = {};@@ -48,7 +53,14 @@ export function getEventsWithinExtent(loadedEvents, selected, extent, state) {olExtent.containsCoordinate(extent, coordinates) &&olExtent.containsCoordinate(maxExtent, coordinates);- if (isVisible || isSelectedEvent) {+ if (isVisible) {+ visibleListEvents[naturalEvent.id] = true;+ } else if (+ // Keep selected in event list if within proj limits+ isSelectedEvent &&+ olExtent.containsCoordinate(maxExtent, coordinates)+ ) {+ console.log(maxExtent, coordinates);visibleListEvents[naturalEvent.id] = true;}});diff --git a/web/js/modules/natural-events/util.js b/web/js/modules/natural-events/util.jsindex 2e30d0dca..97c6d0d6e 100644--- a/web/js/modules/natural-events/util.js+++ b/web/js/modules/natural-events/util.js@@ -4,7 +4,7 @@ export function eventParse(state) {var values = state.split(',');var id = values[0] || '';var date = values[1] || '';- id = id.match(/^EONET_[0-9]+/i) ? values[0] : null;+ id = id.match(/^EONET_[0-9]+/i) ? values[0] : '';date = date.match(/\d{4}-\d{2}-\d{2}/) ? values[1] : null;return {selected: {@@ -12,7 +12,7 @@ export function eventParse(state) {date},active: true,- showAll: false+ showAll: true};}export function serializeEvent(currentItemState) {diff --git a/web/js/modules/sidebar/util.js b/web/js/modules/sidebar/util.jsnew file mode 100644index 000000000..fa88c9c71--- /dev/null+++ b/web/js/modules/sidebar/util.js@@ -0,0 +1,25 @@+import update from 'immutability-helper';+import { assign as lodashAssign } from 'lodash';+export function mapLocationToSidebarState(+ parameters,+ stateFromLocation,+ state,+ config+) {+ if (parameters.e) {+ let sidebarState = lodashAssign({}, state.sidebar, {+ activeTab: 'events'+ });+ stateFromLocation = update(stateFromLocation, {+ sidebar: { $set: sidebarState }+ });+ } else if (parameters.download) {+ let sidebarState = lodashAssign({}, state.sidebar, {+ activeTab: 'download'+ });+ stateFromLocation = update(stateFromLocation, {+ sidebar: { $set: sidebarState }+ });+ }+ return stateFromLocation;+}