Interactive interface for browsing global, full-resolution satellite imagery
WV-2006: Toggle setting to always show datelines (#3811)
Jason Kentc71e29d84add
diff --git a/web/css/toolbar.css b/web/css/toolbar.cssindex be8637375..8d7db9214 100644--- a/web/css/toolbar.css+++ b/web/css/toolbar.css@@ -156,6 +156,9 @@.global-setting-container {margin-bottom: 16px;}+ .settings-component {+ margin-bottom: 15px;+ }.wv-header {margin-bottom: 12px;diff --git a/web/js/components/dateline/dateline.js b/web/js/components/dateline/dateline.jsdeleted file mode 100644index 9630249db..000000000--- a/web/js/components/dateline/dateline.js+++ /dev/null@@ -1,174 +0,0 @@-import React from 'react';-import PropTypes from 'prop-types';-import util from '../../util/util';-/*- * A react component, Builds a SVG line who's dimensions and styles- * are customizable- *- * @class Line- * @extends React.Component- */-class Line extends React.Component {- /*- * Sets state and extents props- */- constructor(props) {- super(props);- this.state = {- hovered: false,- height: 0,- active: true,- };- }-- shouldComponentUpdate(nextProps, nextState) {- const { active, height, hovered } = this.state;- const checkForStateUpdates = nextState.active === active- && nextState.height === height- && nextState.hovered === hovered;-- if (checkForStateUpdates) {- return false;- }- return true;- }-- /*- * Updates state on svg hover- *- * return {Void}- */- mouseOver = () => {- this.setState({- hovered: true,- });- }-- /*- * Updates state on svg mouseout- *- * return {Void}- */- mouseOut = () => {- this.setState({- hovered: false,- });- }-- /*- * Runs lineOver props method when- * the invisible line is hovered, passing- * event properties- *- * @param {Object} e - React event object- * return {Void}- */- mouseOverHidden = (e) => {- const {- lineOver, overlay, lineX, tooltip,- } = this.props;- lineOver(- [e.clientX, e.clientY],- overlay,- lineX,- tooltip,- );- }-- /*- * Runs lineOut props method when- * the invisible line is not longer hovered, passing- * the react component to deactivate- *- * return {Void}- */- mouseOutHidden = () => {- const { lineOut, tooltip } = this.props;- lineOut(tooltip);- }-- render() {- const {- id,- svgStyle,- width,- style,- classes,- color,- strokeWidth,- opacity,- dashArray,- } = this.props;- const { height, active, hovered } = this.state;- return (- <svg- onMouseOver={this.mouseOver}- onMouseOut={this.mouseOut}- style={svgStyle}- width={width}- id={id}- height={height}- className={classes}- >- <line- strokeWidth={strokeWidth}- stroke={color}- opacity={- (hovered && active)- || (active && util.browser.mobileAndTabletDevice)- ? opacity- : '0'- }- x1={strokeWidth / 2}- x2={strokeWidth / 2}- strokeDasharray={dashArray}- y2={height}- y1="0"- />- <line- className="dateline-hidden"- onMouseOver={this.mouseOverHidden}- onMouseMove={this.mouseOverHidden}- onMouseOut={this.mouseOutHidden}- style={style}- opacity="0"- x1={strokeWidth / 2}- x2={strokeWidth / 2}- strokeWidth={strokeWidth}- stroke={color}- y1="0"- y2={height}- />- </svg>- );- }-}-Line.defaultProps = {- dashArray: '5, 10',- opacity: '0.5',- width: '10',- strokeWidth: '6',- color: 'white',- svgStyle: {- transform: 'translateX(-3px)',- },-};--Line.propTypes = {- classes: PropTypes.string,- color: PropTypes.string,- dashArray: PropTypes.string,- id: PropTypes.string,- lineOut: PropTypes.func,- lineOver: PropTypes.func,- lineX: PropTypes.number,- opacity: PropTypes.string,- overlay: PropTypes.object,- strokeWidth: PropTypes.string,- style: PropTypes.object,- svgStyle: PropTypes.object,- tooltip: PropTypes.object,- width: PropTypes.string,-};--export default Line;diff --git a/web/js/components/dateline/datelines.js b/web/js/components/dateline/datelines.jsnew file mode 100644index 000000000..434be2294--- /dev/null+++ b/web/js/components/dateline/datelines.js@@ -0,0 +1,120 @@+/* eslint-disable react/no-render-return-value */+import React, { useEffect, useState } from 'react';+import { connect } from 'react-redux';+import PropTypes from 'prop-types';+import Line from './line';+import util from '../../util/util';+import { getSelectedDate } from '../../modules/date/selectors';++function DateLines(props) {+ const {+ map, proj, date, isCompareActive, mapIsRendered, alwaysShow,+ } = props;++ if (!mapIsRendered) return null;++ const [height, setHeight] = useState(0);+ const [startY, setStartY] = useState(0);+ const [hideLines, setHideLines] = useState(false);++ const updatePosition = () => {+ let topY;+ let bottomY;+ let newStartY;++ if (map.getSize()[0] === 0) {+ return [0, 0];+ }+ const extent = map.getView().calculateExtent(map.getSize());+ const top = [extent[2] - 1, extent[3] + 5];+ const bottom = [extent[2] - 1, extent[1] - 5];+ const topExtent = map.getPixelFromCoordinate([extent[2] - 1, extent[3] - 1]);+ const bottomExtent = map.getPixelFromCoordinate([extent[0] + 1, extent[1] + 1]);+ topY = Math.round(topExtent[1] + 5);+ bottomY = Math.round(bottomExtent[1] - 5);+ newStartY = Math.round(extent[3] + 5);++ if (newStartY > 90) {+ newStartY = 90;+ [, topY] = map.getPixelFromCoordinate([extent[2], 90]);+ } else {+ [, topY] = map.getPixelFromCoordinate(top);+ }+ if (extent[1] > -90) {+ [, bottomY] = map.getPixelFromCoordinate(bottom);+ } else {+ [, bottomY] = map.getPixelFromCoordinate([extent[2], -90]);+ }+ const newHeight = Math.round(Math.abs(bottomY - topY));+ setHeight(newHeight);+ setStartY(newStartY);+ setHideLines(false);+ };++ useEffect(() => {+ if (proj.id !== 'geographic' || !mapIsRendered) {+ return;+ }+ map.on('movestart', () => { setHideLines(true); });+ map.on('moveend', updatePosition);+ return () => {+ map.off('movestart', updatePosition);+ map.off('moveend', updatePosition);+ };+ }, [mapIsRendered]);++ useEffect(updatePosition, [mapIsRendered]);++ return (+ <>+ <Line+ id="dateline-left"+ map={map}+ alwaysShow={alwaysShow}+ isCompareActive={isCompareActive}+ height={hideLines ? 0 : height}+ lineX={-180}+ lineY={startY}+ date={date}+ />+ <Line+ id="dateline-right"+ map={map}+ alwaysShow={alwaysShow}+ isCompareActive={isCompareActive}+ height={hideLines ? 0 : height}+ lineX={180}+ lineY={startY}+ date={util.dateAdd(date, 'day', -1)}+ />+ </>+ );+}++const mapStateToProps = (state) => {+ const {+ proj, map, compare, settings,+ } = state;+ return {+ proj,+ map: map.ui.selected,+ date: getSelectedDate(state),+ isCompareActive: compare.active,+ mapIsRendered: map.rendered,+ alwaysShow: settings.alwaysShowDatelines,+ };+};++DateLines.propTypes = {+ map: PropTypes.object,+ proj: PropTypes.object,+ date: PropTypes.object,+ isCompareActive: PropTypes.bool,+ mapIsRendered: PropTypes.bool,+ alwaysShow: PropTypes.bool,+};++export default connect(+ mapStateToProps,+ () => ({}),+)(DateLines);diff --git a/web/js/components/dateline/line.js b/web/js/components/dateline/line.jsnew file mode 100644index 000000000..887c65f2d--- /dev/null+++ b/web/js/components/dateline/line.js@@ -0,0 +1,155 @@+import React from 'react';+import PropTypes from 'prop-types';+import OlOverlay from 'ol/Overlay';+import util from '../../util/util';+import LineText from './text';++const lineStyles = {+ dashArray: '5, 10',+ opacity: '0.5',+ width: '10',+ strokeWidth: '6',+ color: 'white',+ svgStyle: {+ transform: 'translateX(-3px)',+ },+};++class Line extends React.Component {+ constructor(props) {+ super(props);+ this.state = {+ overlay: '',+ hovered: false,+ textActive: props.alwaysShow,+ textCoords: [0, 0],+ };+ this.nodeRef = React.createRef();+ }++ componentDidMount() {+ const { lineX, map } = this.props;+ const overlay = new OlOverlay({+ element: this.nodeRef.current,+ stopEvent: false,+ });+ overlay.setPosition([lineX, 90]);+ map.addOverlay(overlay);+ this.setState({ overlay });+ }++ componentDidUpdate() {+ const { lineX, lineY } = this.props;+ const { overlay } = this.state;+ overlay.setPosition([lineX, lineY]);+ }++ mouseOver = () => {+ this.setState({+ hovered: true,+ });+ }++ mouseOut = () => {+ this.setState({+ hovered: false,+ });+ }++ mouseOverHidden = (e) => {+ const { map } = this.props;+ this.setState({+ textActive: true,+ textCoords: map.getCoordinateFromPixel([e.clientX, e.clientY]),+ });+ }++ mouseOutHidden = () => {+ this.setState({ textActive: false });+ }++ render() {+ const {+ id,+ alwaysShow,+ date,+ lineX,+ isCompareActive,+ style,+ map,+ height,+ } = this.props;+ const { hovered, textCoords, textActive } = this.state;++ const {+ strokeWidth, dashArray, color, svgStyle, width,+ } = lineStyles;+ const useOpacity = alwaysShow || util.browser.mobileAndTabletDevice || hovered+ ? lineStyles.opacity+ : '0';++ return (+ <>+ <svg+ id={id}+ ref={this.nodeRef}+ className="dateline-case"+ style={svgStyle}+ height={height}+ width={width}+ onMouseOver={this.mouseOver}+ onMouseOut={this.mouseOut}+ >+ <line+ strokeWidth={strokeWidth}+ stroke={color}+ opacity={useOpacity}+ x1={strokeWidth / 2}+ x2={strokeWidth / 2}+ strokeDasharray={dashArray}+ y1="0"+ y2={height}+ />+ <line+ className="dateline-hidden"+ onMouseOver={this.mouseOverHidden}+ onMouseMove={this.mouseOverHidden}+ onMouseOut={this.mouseOutHidden}+ style={style}+ opacity="0"+ x1={strokeWidth / 2}+ x2={strokeWidth / 2}+ strokeWidth={strokeWidth}+ stroke={color}+ y1="0"+ y2={height}+ />+ </svg>+ <LineText+ active={alwaysShow || textActive}+ map={map}+ date={date}+ x={lineX}+ y={90}+ isCompareActive={isCompareActive}+ isLeft={lineX < 0}+ textCoords={textCoords}+ />+ </>+ );+ }+}++Line.propTypes = {+ alwaysShow: PropTypes.bool,+ date: PropTypes.object,+ height: PropTypes.number,+ id: PropTypes.string,+ isCompareActive: PropTypes.bool,+ lineX: PropTypes.number,+ lineY: PropTypes.number,+ map: PropTypes.object,+ style: PropTypes.object,+};++export default Line;diff --git a/web/js/components/dateline/text.js b/web/js/components/dateline/text.jsindex 9b9fa8f24..fb6beaa40 100644--- a/web/js/components/dateline/text.js+++ b/web/js/components/dateline/text.js@@ -1,37 +1,78 @@import React from 'react';import PropTypes from 'prop-types';+import OlOverlay from 'ol/Overlay';import util from '../../util/util';+import { memoizedDateMonthAbbrev } from '../../modules/compare/selectors';++const textStyles = {+ textOpacity: 0.7,+ rectOpacity: 1,+ width: '300',+ color: 'white',+ textY: 14,+ fill: 'rgba(40,40,40,0.75)',+ textWidth: 80,+ textHeight: 20,+ recRadius: 3,+};-/*- * Builds an SVG text box- *- * @class LineText- * @extends React.Component- */class LineText extends React.Component {- /*- * Sets state and extents props- */constructor(props) {super(props);this.state = {- active: false,- dateRight: props.dateRight,- dateLeft: props.dateLeft,+ overlay: '',+ };+ this.nodeRef = React.createRef();+ }++ componentDidMount() {+ const { x, map } = this.props;+ const overlay = new OlOverlay({+ element: this.nodeRef.current,+ stopEvent: false,+ });+ overlay.setPosition([x, 90]);+ map.addOverlay(overlay);+ this.setState({ overlay });+ }++ componentDidUpdate() {+ const { overlay } = this.state;+ const { x, textCoords } = this.props;+ overlay.setPosition([x, textCoords[1]]);+ }++ getDateText() {+ const { date, isCompareActive, isLeft } = this.props;+ if (isCompareActive) {+ return {+ dateLeft: isLeft+ ? '+ 1 day'+ : '',+ dateRight: isLeft+ ? ''+ : '- 1 day',+ };+ }+ const dateState = {+ selected: util.dateAdd(date, 'day', 1),+ selectedB: date,+ };+ const { dateA, dateB } = memoizedDateMonthAbbrev({ date: dateState })();+ return {+ dateLeft: dateA,+ dateRight: dateB,};}render() {- const { dateLeft, dateRight, active } = this.state;+ const { active } = this.props;const {textWidth, recRadius, fill, textY, color, width, textOpacity, textHeight, rectOpacity,- } = this.props;- const leftTextWidth = Math.round(- util.getTextWidth(dateLeft, '13px Open Sans') * 100,- ) / 100 || textWidth;- const rightTextWidth = Math.round(- util.getTextWidth(dateRight, '13px Open Sans') * 100,- ) / 100 || textWidth;+ } = textStyles;+ const { dateLeft, dateRight } = this.getDateText();+ const leftTextWidth = Math.round(util.getTextWidth(dateLeft, '13px Open Sans') * 100) / 100 || textWidth;+ const rightTextWidth = Math.round(util.getTextWidth(dateRight, '13px Open Sans') * 100) / 100 || textWidth;const svgStyle = {position: 'absolute',transform: `translateX(${-(leftTextWidth + 25)}px)`,@@ -41,69 +82,63 @@ class LineText extends React.Component {pointerEvents: 'none',left: '0',};+return (- <svg className="dateline-text" style={svgStyle}>- <rect- fill={fill}- width={leftTextWidth + 10}- height={textHeight}- x={0}- rx={recRadius}- opacity={active && dateLeft ? rectOpacity : '0'}- />- <text- y={textY}- x={6}- fill={color}- width={width}- opacity={active && dateLeft ? textOpacity : '0'}- >- {dateLeft}- </text>- <rect- fill={fill}- width={rightTextWidth + 10}- height={textHeight}- x={leftTextWidth + 40}- rx={recRadius}- opacity={active && dateRight ? rectOpacity : '0'}- />- <text- y={textY}- x={leftTextWidth + 46}- fill={color}- opacity={active && dateRight ? textOpacity : '0'}- >- {dateRight}- </text>+ <svg+ ref={this.nodeRef}+ className="dateline-text"+ style={svgStyle}+ >+ {active && (+ <>+ <rect+ fill={fill}+ width={leftTextWidth + 10}+ height={textHeight}+ x={0}+ rx={recRadius}+ opacity={dateLeft ? rectOpacity : '0'}+ />+ <text+ y={textY}+ x={6}+ fill={color}+ width={width}+ opacity={dateLeft ? textOpacity : '0'}+ >+ {dateLeft}+ </text>+ <rect+ fill={fill}+ width={rightTextWidth + 10}+ height={textHeight}+ x={leftTextWidth + 40}+ rx={recRadius}+ opacity={dateRight ? rectOpacity : '0'}+ />+ <text+ y={textY}+ x={leftTextWidth + 46}+ fill={color}+ opacity={dateRight ? textOpacity : '0'}+ >+ {dateRight}+ </text>+ </>+ )}</svg>);}}-LineText.defaultProps = {- textOpacity: 0.7,- rectOpacity: 1,- width: '300',- color: 'white',- textY: 14,- fill: 'rgba(40,40,40,0.75)',- textWidth: 80,- textHeight: 20,- recRadius: 3,-};LineText.propTypes = {- color: PropTypes.string,- dateLeft: PropTypes.string,- dateRight: PropTypes.string,- fill: PropTypes.string,- recRadius: PropTypes.number,- rectOpacity: PropTypes.number,- textHeight: PropTypes.number,- textOpacity: PropTypes.number,- textWidth: PropTypes.number,- textY: PropTypes.number,- width: PropTypes.string,+ active: PropTypes.bool,+ date: PropTypes.object,+ x: PropTypes.number,+ isCompareActive: PropTypes.bool,+ isLeft: PropTypes.bool,+ map: PropTypes.object,+ textCoords: PropTypes.array,};export default LineText;diff --git a/web/js/components/global-settings/global-settings.js b/web/js/components/global-settings/global-settings.jsindex d4e470288..bbff3d34a 100644--- a/web/js/components/global-settings/global-settings.js+++ b/web/js/components/global-settings/global-settings.js@@ -1,13 +1,19 @@import React from 'react';import PropTypes from 'prop-types';import { connect } from 'react-redux';+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';+import HoverTooltip from '../util/hover-tooltip';import TemperatureUnitButtons from './temperature-unit-buttons';import {changeTemperatureUnit,-} from '../../modules/global-unit/actions';+ changeDatelineVisibility,+} from '../../modules/settings/actions';+import Switch from '../util/switch';function GlobalSettings(props) {const {+ alwaysShowDatelines,+ toggleAlwaysShowDatelines,changeTemperatureUnitAction,globalTemperatureUnit,} = props;@@ -15,20 +21,43 @@ function GlobalSettings(props) {return (<><div className="global-setting-container">+<TemperatureUnitButtonschangeTemperatureUnit={changeTemperatureUnitAction}globalTemperatureUnit={globalTemperatureUnit}/>++ <div className="settings-component">+ <h3 className="wv-header">+ Show Datelines+ {' '}+ <span><FontAwesomeIcon id="datelines-toggle" icon="info-circle" /></span>+ <HoverTooltip+ isMobile={false}+ labelText="Either always show or only on mouse hover"+ target="datelines-toggle"+ placement="right"+ />+ </h3>+ <Switch+ id="dateline-visibility-toggle"+ label={alwaysShowDatelines ? 'Always' : 'On Hover'}+ containerClassAddition="header"+ active={alwaysShowDatelines}+ toggle={() => toggleAlwaysShowDatelines(!alwaysShowDatelines)}+ />+ </div></div></>);}function mapStateToProps(state) {- const { globalUnit } = state;- const { globalTemperatureUnit } = globalUnit;+ const { settings } = state;+ const { globalTemperatureUnit, alwaysShowDatelines } = settings;return {globalTemperatureUnit,+ alwaysShowDatelines,};}@@ -36,6 +65,9 @@ const mapDispatchToProps = (dispatch) => ({changeTemperatureUnitAction: (value) => {dispatch(changeTemperatureUnit(value));},+ toggleAlwaysShowDatelines: (value) => {+ dispatch(changeDatelineVisibility(value));+ },});export default connect(@@ -44,6 +76,8 @@ export default connect()(GlobalSettings);GlobalSettings.propTypes = {+ alwaysShowDatelines: PropTypes.bool,+ toggleAlwaysShowDatelines: PropTypes.func,changeTemperatureUnitAction: PropTypes.func,globalTemperatureUnit: PropTypes.string,};diff --git a/web/js/components/global-settings/temperature-unit-buttons.js b/web/js/components/global-settings/temperature-unit-buttons.jsindex 7400a34e8..2dda64f6c 100644--- a/web/js/components/global-settings/temperature-unit-buttons.js+++ b/web/js/components/global-settings/temperature-unit-buttons.js@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';import { Button, ButtonGroup } from 'reactstrap';import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';import HoverTooltip from '../util/hover-tooltip';-import { TEMPERATURE_UNITS } from '../../modules/global-unit/constants';+import { TEMPERATURE_UNITS } from '../../modules/settings/constants';const TemperatureUnitButtons = ({ changeTemperatureUnit, globalTemperatureUnit }) => (<div className="temperature-unit-buttons settings-component">diff --git a/web/js/components/layer/settings/layer-settings.js b/web/js/components/layer/settings/layer-settings.jsindex 6edc812a1..e85bec832 100644--- a/web/js/components/layer/settings/layer-settings.js+++ b/web/js/components/layer/settings/layer-settings.js@@ -309,11 +309,11 @@ class LayerSettings extends React.Component {function mapStateToProps(state, ownProps) {const {- config, palettes, compare, browser, globalUnit,+ config, palettes, compare, browser, settings,} = state;const { custom } = palettes;const groupName = compare.activeString;- const globalTemperatureUnit = lodashGet(ownProps, 'layer.disableUnitConversion') ? '' : globalUnit.globalTemperatureUnit;+ const globalTemperatureUnit = lodashGet(ownProps, 'layer.disableUnitConversion') ? '' : settings.globalTemperatureUnit;return {paletteOrder: config.paletteOrder,groupName,diff --git a/web/js/components/layer/settings/palette-threshold.js b/web/js/components/layer/settings/palette-threshold.jsindex baa6e38a4..11d6c1121 100644--- a/web/js/components/layer/settings/palette-threshold.js+++ b/web/js/components/layer/settings/palette-threshold.js@@ -5,7 +5,7 @@ import { Range as RangeInput } from 'rc-slider';import Checkbox from '../../util/checkbox';import {checkTemperatureUnitConversion, convertPaletteValue,-} from '../../../modules/global-unit/util';+} from '../../../modules/settings/util';class ThresholdSelect extends React.Component {constructor(props) {diff --git a/web/js/components/map/coordinates.js b/web/js/components/map/coordinates.jsindex e7cdad374..c7df83b0d 100644--- a/web/js/components/map/coordinates.js+++ b/web/js/components/map/coordinates.js@@ -1,6 +1,6 @@import React from 'react';import PropTypes from 'prop-types';-import { UncontrolledTooltip } from 'reactstrap';+import util from '../../util/util';// previous : next@@ -44,9 +44,6 @@ export default class Coordinates extends React.Component {className="wv-coords-map wv-coords-map-btn"onClick={this.changeFormat}>- <UncontrolledTooltip placement="bottom" target="coords-panel">- Change coordinates format- </UncontrolledTooltip><span className="map-coord">{`${coords}`}</span>diff --git a/web/js/components/map/ol-coordinates.js b/web/js/components/map/ol-coordinates.jsindex 1b42561b7..31b212d38 100644--- a/web/js/components/map/ol-coordinates.js+++ b/web/js/components/map/ol-coordinates.js@@ -1,5 +1,7 @@import React from 'react';+import PropTypes from 'prop-types';import { transform } from 'ol/proj';+import { UncontrolledTooltip } from 'reactstrap';import Coordinates from './coordinates';import util from '../../util/util';@@ -110,21 +112,30 @@ export default class OlCoordinates extends React.Component {const {hasMouse, format, latitude, longitude, crs, width,} = this.state;- // Don't render until a mouse is being used- if (!hasMouse) {- return null;- }-+ const { show } = this.props;return (<div id="ol-coords-case" className="wv-coords-container" style={{ width }}>- <Coordinates- format={format}- latitude={latitude}- longitude={longitude}- crs={crs}- onFormatChange={this.changeFormat}- />+ {hasMouse && show && (+ <>+ <Coordinates+ format={format}+ latitude={latitude}+ longitude={longitude}+ crs={crs}+ onFormatChange={this.changeFormat}+ />+ {latitude && latitude && (+ <UncontrolledTooltip placement="bottom" target="ol-coords-case">+ Change coordinates format+ </UncontrolledTooltip>+ )}+ </>+ )}</div>);}}++OlCoordinates.propTypes = {+ show: PropTypes.bool,+};diff --git a/web/js/components/map/ol-coordinates.test.js b/web/js/components/map/ol-coordinates.test.jsindex c9a84633a..2df6702a2 100644--- a/web/js/components/map/ol-coordinates.test.js+++ b/web/js/components/map/ol-coordinates.test.js@@ -19,7 +19,7 @@ beforeEach(() => {getCoordinateFromPixel: () => [0, 0],};act(() => {- render(<OlCoordinates />, container);+ render(<OlCoordinates show />, container);});});diff --git a/web/js/components/sidebar/paletteLegend.js b/web/js/components/sidebar/paletteLegend.jsindex 85424b0c2..00af8dc4b 100644--- a/web/js/components/sidebar/paletteLegend.js+++ b/web/js/components/sidebar/paletteLegend.js@@ -12,7 +12,7 @@ import {import {checkTemperatureUnitConversion,convertPaletteValue,-} from '../../modules/global-unit/util';+} from '../../modules/settings/util';import util from '../../util/util';/**diff --git a/web/js/containers/map-interactions/map-interactions.js b/web/js/containers/map-interactions/map-interactions.jsindex a36ddc1a3..fa50097d6 100644--- a/web/js/containers/map-interactions/map-interactions.js+++ b/web/js/containers/map-interactions/map-interactions.js@@ -10,6 +10,7 @@ import OlRotationButtons from '../../components/map/rotation';import OlZoomButtons from '../../components/map/zoom';import RightClickMenu from '../../components/context-menu/context-menu';import NaturalEvents from '../../map/natural-events/natural-events';+import DateLines from '../../components/dateline/datelines';class MapInteractions extends PureComponent {getMapClasses = () => {@@ -29,21 +30,20 @@ class MapInteractions extends PureComponent {const mapClasses = this.getMapClasses();return (<>- <RightClickMenu />- <OlZoomButtons />- <OlRotationButtons /><ContextMenuTrigger id="context-menu-trigger"><div id="wv-map" className={mapClasses} /></ContextMenuTrigger>- {!isDistractionFreeModeActive && (- <OlCoordinates />- )}+ <RightClickMenu />+ <OlZoomButtons />+ <OlRotationButtons />+ <OlCoordinates show={!isDistractionFreeModeActive} /><OlVectorInteractions /><OlMeasureTool /><OlCoordinatesMarker />{isNaturalEventsActive && (<NaturalEvents />)}+ <DateLines /></>);}diff --git a/web/js/containers/sidebar/layer-row.js b/web/js/containers/sidebar/layer-row.jsindex 884618009..b4fdff42d 100644--- a/web/js/containers/sidebar/layer-row.js+++ b/web/js/containers/sidebar/layer-row.js@@ -406,11 +406,11 @@ const makeMapStateToProps = () => {compareState,} = ownProps;const {- browser, palettes, config, embed, map, compare, proj, ui, globalUnit, animation,+ browser, palettes, config, embed, map, compare, proj, ui, settings, animation,} = state;const isMobile = browser.lessThan.medium;const { isDistractionFreeModeActive } = ui;- const globalTemperatureUnit = lodashGet(ownProps, 'layer.disableUnitConversion') ? '' : globalUnit.globalTemperatureUnit;+ const globalTemperatureUnit = lodashGet(ownProps, 'layer.disableUnitConversion') ? '' : settings.globalTemperatureUnit;const hasPalette = !lodashIsEmpty(layer.palette);const renderedPalettes = palettes.rendered;const paletteName = lodashGet(config, `layers['${layer.id}'].palette.id`);diff --git a/web/js/map/datelinebuilder.js b/web/js/map/datelinebuilder.jsdeleted file mode 100644index e77b27552..000000000--- a/web/js/map/datelinebuilder.js+++ /dev/null@@ -1,398 +0,0 @@-/* eslint-disable react/no-render-return-value */-import React from 'react';-import ReactDOM from 'react-dom';-import OlOverlay from 'ol/Overlay';-import util from '../util/util';-import DateLine from '../components/dateline/dateline';-import LineText from '../components/dateline/text';-import {- CHANGE_STATE as COMPARE_CHANGE_STATE,- TOGGLE_ON_OFF as COMPARE_TOGGLE_ON_OFF,-} from '../modules/compare/constants';-import { SELECT_DATE } from '../modules/date/constants';-import { CHANGE_PROJECTION } from '../modules/projection/constants';-import { LOCATION_POP_ACTION } from '../redux-location-state-customs';-import { getSelectedDate } from '../modules/date/selectors';-import { memoizedDateMonthAbbrev } from '../modules/compare/selectors';--const { events } = util;--let map;-let overlay1;-let overlay2;-let textOverlay1;-let textOverlay2;-let lineLeft;-let lineRight;-let textLeft;-let textRight;-let proj;--export default function mapDateLineBuilder(store) {- const self = {};- /*- * Subscribe to redux store and listen for- * specific action types- */- const subscribeToStore = function(action) {- switch (action.type) {- case SELECT_DATE:- case LOCATION_POP_ACTION:- case COMPARE_CHANGE_STATE:- case COMPARE_TOGGLE_ON_OFF: {- const state = store.getState();- const date = getSelectedDate(state);- return updateDate(date);- }- case CHANGE_PROJECTION:- proj = action.id;- break;- default:- break;- }- };-- /*- * Sets globals and event listeners- *- * @method init- * @static- *- * @param {Object} olMap - OL map object- * @param {Object} date - JS date Object- *- * @returns {object} React Component- */- self.init = function(olMap, date) {- let dimensions;- map = olMap;- drawDatelines(map, date);- proj = store.getState().proj.id;-- events.on('map:moveend', () => {- if (!isGeoProjection()) {- return;- }- updateLineVisibility(true);- dimensions = position(map);- update(dimensions);- });- events.on('map:drag', () => {- if (!isGeoProjection()) {- return;- }- updateLineVisibility(false);- });- events.on('map:movestart', () => {- if (!isGeoProjection()) {- return;- }- updateLineVisibility(false);- });- events.on('redux:action-dispatched', subscribeToStore);- };-- const isGeoProjection = function() {- if (proj === 'geographic') {- return true;- }- return false;- };-- /*- * Add Props to React Components that creates- * a hoverable line SVG- *- * @method setLineDefaults- * @private- *- * @param {object} Factory - React component Factory- * @param {number} height - Length of line- * @param {number} lineX - x coordinate value- * @param {object} overlay - OL overlay- * @param {object} reactCase - Dom El in which to render component- * @param {object} tooltip - OL overlay that is associated with this widget- *- * @returns {object} React Component- */- const setLineDefaults = function(- ReactComponent,- height,- lineX,- overlay,- reactCase,- tooltip,- ) {- const props = {- height,- lineOver: onHover,- lineOut: onMouseOut,- lineX,- overlay,- tooltip,- };- const component = ReactDOM.render(- React.createElement(ReactComponent, props),- reactCase,- );- return component;- };-- /*- * Add Props to React Components that creates an- * SVG text component- *- * @method setTextDefaults- * @private- *- * @param {object} Factory - React component Factory- * @param {object} reactCase - Dom El in which to render component- * @param {object} date - JS date object- *- * @returns {object} React Component- */- const setTextDefaults = function(ReactComponent, reactCase, date, isLeft) {- const props = getTextState(date, isLeft);- return ReactDOM.render(- React.createElement(ReactComponent, props),- reactCase,- );- };-- /*- * @method updateTextState- * @private- *- * @param {object} date - JS date object- * @param {boolean} isLeft - is this on left or right side of map- *- * @returns {object} Object with tooltip state- */- const getTextState = function(date, isLeft) {- const state = store.getState();- if (state.compare.active) {- return {- dateLeft: isLeft- ? '+ 1 day'- : '',- dateRight: isLeft- ? ''- : '- 1 day',- };- }- const dateState = { selected: util.dateAdd(date, 'day', 1), selectedB: date };- const { dateA, dateB } = memoizedDateMonthAbbrev({ date: dateState })();- return { dateLeft: dateA, dateRight: dateB };- };-- /*- * Updates active state of line Components- *- * @method updateLineVisibility- * @private- *- * @param {boolean} boo - component deactivation boolean- *- * @returns {void}- */- const updateLineVisibility = function(boo) {- const state = {- active: boo,- };- lineRight.setState(state);- lineLeft.setState(state);- };-- /*- * constructs dateline components- *- * @method drawDatelines- * @private- *- * @param {boolean} boo - component deactivation boolean- *- * @returns {void}- */- const drawDatelines = function(map, date) {- const leftLineCase = document.createElement('div');- const rightLineCase = document.createElement('div');- leftLineCase.className = 'dateline-case';- rightLineCase.className = 'dateline-case';- const leftTextCase = document.createElement('div');- const rightTextCase = document.createElement('div');- const height = 0;-- overlay1 = drawOverlay([-180, 90], leftLineCase);- overlay2 = drawOverlay([180, 90], rightLineCase);- textOverlay1 = drawOverlay([-180, 90], leftTextCase);- textOverlay2 = drawOverlay([180, 90], rightTextCase);-- map.addOverlay(overlay1);- map.addOverlay(overlay2);- map.addOverlay(textOverlay1);- map.addOverlay(textOverlay2);-- textLeft = setTextDefaults(LineText, leftTextCase, date, true);- textRight = setTextDefaults(- LineText,- rightTextCase,- util.dateAdd(date, 'day', -1),- false,- );- lineLeft = setLineDefaults(- DateLine,- height,- -180,- textOverlay1,- leftLineCase,- textLeft,- );- lineRight = setLineDefaults(- DateLine,- height,- 180,- textOverlay2,- rightLineCase,- textRight,- );- };-- /*- * relocates and shows tooltip on line hover- *- * @method onHover- * @private- *- * @param {Array} pixels - pixel array- * @param {Object} overlay - OL overlay that contains react tooltip- * @param {Number} lineX - X coordinate of line- * @param {Object} tooltip - React tooltip that displays line date-info- *- * @returns {void}- */- const onHover = function(pixels, overlay, lineX, tooltip) {- const coords = map.getCoordinateFromPixel(pixels);- overlay.setPosition([lineX, coords[1]]);- tooltip.setState({- active: true,- });- };-- /*- * Hides tooltip when mouse is no longer hovering over- * line- *- * @method onMouseOut- * @private- *- * @param {Object} tooltip - React tooltip that displays line date-info- *- * @returns {void}- */- const onMouseOut = function(tooltip) {- tooltip.setState({- active: false,- });- };-- /*- * Updates react tooltip components with correct date- *- * @method updateDate- * @private- *- * @param {Object} date - JS date object- *- * @returns {void}- */- const updateDate = function(date) {- const leftState = getTextState(date, true);- const rightState = getTextState(util.dateAdd(date, 'day', -1), false);- textLeft.setState(leftState);- textRight.setState(rightState);- };-- /*- * Calculates the height and y-position of the line- *- * @method position- * @private- *- * @param {Object} map - OL map object- *- * @returns {void}- */- const position = function(map) {- let topY;- let bottomY;- let startY;-- if (map.getSize()[0] === 0) {- return;- }- const extent = map.getView().calculateExtent(map.getSize());- const top = [extent[2] - 1, extent[3] + 5];- const bottom = [extent[2] - 1, extent[1] - 5];- const topExtent = map.getPixelFromCoordinate([extent[2] - 1, extent[3] - 1]);- const bottomExtent = map.getPixelFromCoordinate([extent[0] + 1, extent[1] + 1]);- topY = Math.round(topExtent[1] + 5);- bottomY = Math.round(bottomExtent[1] - 5);- startY = Math.round(extent[3] + 5);-- if (startY > 90) {- startY = 90;- [, topY] = map.getPixelFromCoordinate([extent[2], 90]);- } else {- [, topY] = map.getPixelFromCoordinate(top);- }- if (extent[1] > -90) {- [, bottomY] = map.getPixelFromCoordinate(bottom);- } else {- [, bottomY] = map.getPixelFromCoordinate([extent[2], -90]);- }- const height = Math.round(Math.abs(bottomY - topY));- return [height, startY];- };-- /*- * Calculates the height and y-position of the line- *- * @method update- * @private- *- * @param {Array} dimensions - Array containing height and y-axis values- *- * @returns {void}- */- const update = function(dimensions) {- const state = {- height: dimensions[0],- };- lineRight.setState(state);- lineLeft.setState(state);- overlay1.setPosition([-180, dimensions[1]]);- overlay2.setPosition([180, dimensions[1]]);- };-- /*- * Calculates the height and y-position of the line- *- * @method drawOverlay- * @private- *- * @param {Array} coordinate- * @param {Object} el - DOM object to be append to overlay- *- * @returns {void}- */- const drawOverlay = function(coordinate, el) {- const overlay = new OlOverlay({- element: el,- stopEvent: false,- });- overlay.setPosition(coordinate);- return overlay;- };-- return self;-}diff --git a/web/js/map/ui.js b/web/js/map/ui.jsindex bec174184..6e07a4fe6 100644--- a/web/js/map/ui.js+++ b/web/js/map/ui.js@@ -26,7 +26,6 @@ import * as olProj from 'ol/proj';import { CALCULATE_RESPONSIVE_STATE } from 'redux-responsive';import Cache from 'cachai';import PQueue from 'p-queue/dist';-import mapDateLineBuilder from './datelinebuilder';import mapLayerBuilder from './layerbuilder';import MapRunningData from './runningdata';import { getActiveLayerGroup, fly, saveRotation } from './util';@@ -70,7 +69,6 @@ const { events } = util;export default function mapui(models, config, store, ui) {const animationDuration = 250;- const dateline = mapDateLineBuilder(store);const compareMapUi = mapCompare(store);const runningdata = new MapRunningData(compareMapUi, store);const doubleClickZoom = new OlInteractionDoubleClickZoom({@@ -988,8 +986,6 @@ export default function mapui(models, config, store, ui) {if (proj.id !== 'geographic' && proj.id !== 'webmerc') {map.addInteraction(rotateInteraction);map.addInteraction(mobileRotation);- } else if (proj.id === 'geographic') {- dateline.init(map, dateSelected);}const onRotate = () => {diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.jsindex 005b61673..5953674bc 100644--- a/web/js/modules/combine-reducers.js+++ b/web/js/modules/combine-reducers.js@@ -48,7 +48,7 @@ import embedReducers from './embed/reducers';import uiReducers from './ui/reducers';import { alertReducer } from './alerts/reducer';import { smartHandoffReducer } from './smart-handoff/reducer';-import { getInitialState as globalUnitGetInitialState, globalUnitReducer } from './global-unit/reducer';+import { getInitialState as getInitialSettingsState, settingsReducer } from './settings/reducer';function lastAction(state = null, action) {return action;@@ -84,7 +84,7 @@ export function getInitialState(models, config, parameters) {proj: getProjInitialState(config),layers: getLayersInitialState(config),events: getInitialEventsState(config),- globalUnit: globalUnitGetInitialState(),+ settings: getInitialSettingsState(),requestedEvents: eventRequestResponse(),requestedEventSources: eventRequestResponse(),palettes: getInitialPaletteState(config),@@ -133,7 +133,7 @@ const reducers = {embed: embedReducers,ui: uiReducers,productPicker: productPickerReducer,- globalUnit: globalUnitReducer,+ settings: settingsReducer,};const appReducer = combineReducers(reducers);/**diff --git a/web/js/modules/global-unit/constants.js b/web/js/modules/global-unit/constants.jsdeleted file mode 100644index 8ef4845ce..000000000--- a/web/js/modules/global-unit/constants.js+++ /dev/null@@ -1,3 +0,0 @@-// eslint-disable-next-line import/prefer-default-export-export const CHANGE_TEMPERATURE_UNIT = 'GLOBAL_UNIT/CHANGE_TEMPERATURE_UNIT';-export const TEMPERATURE_UNITS = ['Kelvin', 'Celsius', 'Fahrenheit'];diff --git a/web/js/modules/global-unit/reducer.js b/web/js/modules/global-unit/reducer.jsdeleted file mode 100644index 57c23dce5..000000000--- a/web/js/modules/global-unit/reducer.js+++ /dev/null@@ -1,27 +0,0 @@-import safeLocalStorage from '../../util/local-storage';-import { CHANGE_TEMPERATURE_UNIT } from './constants';--const { GLOBAL_TEMPERATURE_UNIT } = safeLocalStorage.keys;--export const initialState = {- globalTemperatureUnit: '',-};--export function getInitialState() {- const globalTemperatureUnit = safeLocalStorage.getItem(GLOBAL_TEMPERATURE_UNIT);- return {- globalTemperatureUnit,- };-}--export const globalUnitReducer = (state = initialState, action) => {- switch (action.type) {- case CHANGE_TEMPERATURE_UNIT:- return {- ...state,- globalTemperatureUnit: action.value,- };- default:- return state;- }-};diff --git a/web/js/modules/global-unit/actions.js b/web/js/modules/settings/actions.jssimilarity index 50%rename from web/js/modules/global-unit/actions.jsrename to web/js/modules/settings/actions.jsindex 65fc1a2db..f735f93db 100644--- a/web/js/modules/global-unit/actions.js+++ b/web/js/modules/settings/actions.js@@ -1,10 +1,11 @@import {CHANGE_TEMPERATURE_UNIT,+ CHANGE_DATELINE_VISIBILITY,} from './constants';import safeLocalStorage from '../../util/local-storage';-const { GLOBAL_TEMPERATURE_UNIT } = safeLocalStorage.keys;-// eslint-disable-next-line import/prefer-default-export+const { GLOBAL_TEMPERATURE_UNIT, ALWAYS_SHOW_DATELINES } = safeLocalStorage.keys;+export function changeTemperatureUnit(value) {if (!value) {safeLocalStorage.removeItem(GLOBAL_TEMPERATURE_UNIT);@@ -16,3 +17,15 @@ export function changeTemperatureUnit(value) {value,};}++export function changeDatelineVisibility(value) {+ if (!value) {+ safeLocalStorage.removeItem(ALWAYS_SHOW_DATELINES);+ } else {+ safeLocalStorage.setItem(ALWAYS_SHOW_DATELINES, value);+ }+ return {+ type: CHANGE_DATELINE_VISIBILITY,+ value,+ };+}diff --git a/web/js/modules/settings/constants.js b/web/js/modules/settings/constants.jsnew file mode 100644index 000000000..77f2d57f6--- /dev/null+++ b/web/js/modules/settings/constants.js@@ -0,0 +1,4 @@+// eslint-disable-next-line import/prefer-default-export+export const CHANGE_TEMPERATURE_UNIT = 'SETTINGS/CHANGE_TEMPERATURE_UNIT';+export const CHANGE_DATELINE_VISIBILITY = 'SETTINGS/CHANGE_DATELINE_VISIBILITY';+export const TEMPERATURE_UNITS = ['Kelvin', 'Celsius', 'Fahrenheit'];diff --git a/web/js/modules/settings/reducer.js b/web/js/modules/settings/reducer.jsnew file mode 100644index 000000000..056e315d1--- /dev/null+++ b/web/js/modules/settings/reducer.js@@ -0,0 +1,36 @@+import safeLocalStorage from '../../util/local-storage';+import { CHANGE_TEMPERATURE_UNIT, CHANGE_DATELINE_VISIBILITY } from './constants';++const { GLOBAL_TEMPERATURE_UNIT, ALWAYS_SHOW_DATELINES } = safeLocalStorage.keys;++export const initialState = {+ globalTemperatureUnit: '',+ alwaysShowDatelines: false,++};++export function getInitialState() {+ const alwaysShowDatelines = Boolean(safeLocalStorage.getItem(ALWAYS_SHOW_DATELINES));+ return {+ globalTemperatureUnit: safeLocalStorage.getItem(GLOBAL_TEMPERATURE_UNIT),+ alwaysShowDatelines,+ };+}++export const settingsReducer = (state = initialState, action) => {+ switch (action.type) {+ case CHANGE_TEMPERATURE_UNIT:+ return {+ ...state,+ globalTemperatureUnit: action.value,+ };+ case CHANGE_DATELINE_VISIBILITY: {+ return {+ ...state,+ alwaysShowDatelines: action.value,+ };+ }+ default:+ return state;+ }+};diff --git a/web/js/modules/global-unit/util.js b/web/js/modules/settings/util.jssimilarity index 100%rename from web/js/modules/global-unit/util.jsrename to web/js/modules/settings/util.jsdiff --git a/web/js/util/local-storage.js b/web/js/util/local-storage.jsindex b3c0bee73..a10b93015 100644--- a/web/js/util/local-storage.js+++ b/web/js/util/local-storage.js@@ -32,6 +32,7 @@ export default {NOTIFICATION_ALERT: 'alert',NOTIFICATION_MSG: 'message',GROUP_OVERLAYS: 'groupOverlays',+ ALWAYS_SHOW_DATELINES: 'alwaysShowDatelines',},getItem(key) {return enabled && localStorage.getItem(key);