Interactive interface for browsing global, full-resolution satellite imagery
move ol coordinates marker outside main ol coordinates, add reverse geocode extent alert
Ed Platoa2670d80eb42
diff --git a/web/js/components/geosearch/geosearch-input.js b/web/js/components/geosearch/geosearch-input.jsindex eaa754fab..97d31529b 100644--- a/web/js/components/geosearch/geosearch-input.js+++ b/web/js/components/geosearch/geosearch-input.js@@ -1,3 +1,4 @@+/* eslint no-nested-ternary: 0 */import React, { Component } from 'react';import PropTypes from 'prop-types';import Autocomplete from 'react-autocomplete';diff --git a/web/js/components/geosearch/geosearch-modal.js b/web/js/components/geosearch/geosearch-modal.jsindex 83edcd523..2b8cfe87b 100644--- a/web/js/components/geosearch/geosearch-modal.js+++ b/web/js/components/geosearch/geosearch-modal.js@@ -27,7 +27,7 @@ class SearchComponent extends Component {}componentDidUpdate(prevProps) {- const { coordinates } = this.props;+ const { coordinates, isCoordinateSearchActive } = this.props;const { showExtentAlert, showReverseGeocodeAlert } = this.state;if ((showReverseGeocodeAlert || showExtentAlert) && coordinates.length > 0) {@@ -38,6 +38,10 @@ class SearchComponent extends Component {this.setExtentAlert(false);}}+ // clear geocode click instruction alert if search no longer active+ if (!isCoordinateSearchActive && prevProps.isCoordinateSearchActive) {+ this.dismissReverseGeocodeAlert();+ }}// dismiss message instruction alert@@ -319,6 +323,7 @@ SearchComponent.propTypes = {geosearchMobileModalOpen: PropTypes.bool,inputValue: PropTypes.string,isCoordinatePairWithinExtent: PropTypes.func,+ isCoordinateSearchActive: PropTypes.bool,isExpanded: PropTypes.bool,isMobile: PropTypes.bool,searchResults: PropTypes.array,diff --git a/web/js/components/geosearch/geosearch.js b/web/js/components/geosearch/geosearch.jsindex 55812a847..0d6b92575 100644--- a/web/js/components/geosearch/geosearch.js+++ b/web/js/components/geosearch/geosearch.js@@ -44,6 +44,7 @@ class Geosearch extends React.Component {coordinates,geosearchMobileModalOpen,isCoordinatePairWithinExtent,+ isCoordinateSearchActive,isExpanded,selectCoordinatesToFly,toggleReverseGeocodeActive,@@ -63,6 +64,7 @@ class Geosearch extends React.Component {geosearchMobileModalOpen={geosearchMobileModalOpen}inputValue={inputValue}isCoordinatePairWithinExtent={isCoordinatePairWithinExtent}+ isCoordinateSearchActive={isCoordinateSearchActive}isExpanded={isExpanded}isMobile={isMobile}searchResults={searchResults}@@ -112,7 +114,7 @@ const mapStateToProps = (state) => {const { features: { geocodeSearch: isFeatureEnabled } } = config;const { isActive } = measure;const { gifActive } = animation;- const { coordinates, isExpanded } = geosearch;+ const { coordinates, isCoordinateSearchActive, isExpanded } = geosearch;const { isDistractionFreeModeActive } = ui;const isMobile = browser.lessThan.medium;const snapshotModalOpen = modal.isOpen && modal.id === 'TOOLBAR_SNAPSHOT';@@ -122,6 +124,7 @@ const mapStateToProps = (state) => {return {coordinates,+ isCoordinateSearchActive,isExpanded,geosearchMobileModalOpen,isCoordinatePairWithinExtent: (targetCoordinates) => areCoordinatesWithinExtent(map, config, targetCoordinates),@@ -148,6 +151,7 @@ const mapDispatchToProps = (dispatch) => ({Geosearch.propTypes = {isCoordinatePairWithinExtent: PropTypes.func,+ isCoordinateSearchActive: PropTypes.bool,isFeatureEnabled: PropTypes.bool,clearCoordinates: PropTypes.func,coordinates: PropTypes.array,diff --git a/web/js/components/geosearch/ol-coordinates-marker.js b/web/js/components/geosearch/ol-coordinates-marker.jsindex d2e61dd0c..3dfec62b3 100644--- a/web/js/components/geosearch/ol-coordinates-marker.js+++ b/web/js/components/geosearch/ol-coordinates-marker.js@@ -1,25 +1,42 @@import { connect } from 'react-redux';import {debounce as lodashDebounce,+ isNaN as lodashIsNaN,} from 'lodash';-import React from 'react';+import React, { Component } from 'react';import PropTypes from 'prop-types';import { transform } from 'ol/proj';+import Alert from '../util/alert';import { changeCursor as changeCursorActionCreator } from '../../modules/map/actions';import { getCoordinatesDialogAtMapPixel } from './ol-coordinates-marker-util';-import { clearCoordinates } from '../../modules/geosearch/actions';+import { clearCoordinates, selectCoordinatesToFly, toggleReverseGeocodeActive } from '../../modules/geosearch/actions';+import { areCoordinatesWithinExtent, reverseGeocode } from '../../modules/geosearch/selectors';-export class CoordinatesInteractions extends React.Component {+export class CoordinatesMarker extends Component {constructor(props) {super(props);+ this.state = {+ latitude: null,+ longitude: null,+ showExtentAlert: false,+ };this.mouseMove = lodashDebounce(this.mouseMove.bind(this), 8);+ this.mouseClick = this.mouseClick.bind(this);this.singleClick = this.singleClick.bind(this);this.registerMouseListeners();}+ componentWillUnmount() {+ const { mouseEvents } = this.props;+ mouseEvents.off('mousemove', this.mouseMove);+ mouseEvents.off('click', this.mouseClick);+ mouseEvents.OFF('singleclick', this.singleClick);+ }+registerMouseListeners() {const { mouseEvents } = this.props;mouseEvents.on('mousemove', this.mouseMove);+ mouseEvents.on('click', this.mouseClick);mouseEvents.on('singleclick', this.singleClick);}@@ -34,6 +51,7 @@ export class CoordinatesInteractions extends React.Component {} = this.props;const [lon, lat] = transform(coord, crs, 'EPSG:4326');if (lon < -250 || lon > 250 || lat < -90 || lat > 90) {+ this.setState({ latitude: null, longitude: null });return;}const hasFeatures = map.hasFeatureAtPixel(pixels);@@ -52,6 +70,7 @@ export class CoordinatesInteractions extends React.Component {} else if (!hasFeatures && isShowingClick) {changeCursor(false);}+ this.setState({ latitude: lat, longitude: lon });}singleClick(e, map) {@@ -65,6 +84,38 @@ export class CoordinatesInteractions extends React.Component {this.getCoordinatesDialog(pixels, map);}+ mouseClick(e, map) {+ const {+ config,+ measureIsActive,+ selectCoordinatesToFly,+ isCoordinateSearchActive,+ toggleReverseGeocodeActive,+ } = this.props;+ const {+ latitude,+ longitude,+ } = this.state;++ if (measureIsActive) return;+ // handle reverse geocoding mouse click+ if (isCoordinateSearchActive) {+ // show alert warning and exit mode if outside current map extent+ const validNums = !lodashIsNaN(parseFloat(latitude)) && !lodashIsNaN(parseFloat(longitude));+ const withinExtent = areCoordinatesWithinExtent({ ui: { selected: map } }, config, [longitude, latitude]);+ if (!validNums || !withinExtent) {+ this.setState({ showExtentAlert: true });+ toggleReverseGeocodeActive(false);+ return;+ }+ // get available reverse geocoding for coordinates and fly to point+ reverseGeocode([longitude, latitude]).then((results) => {+ selectCoordinatesToFly([longitude, latitude], results);+ });+ this.setState({ showExtentAlert: false });+ }+ }+getCoordinatesDialog = (pixels, olMap) => {const {config,@@ -74,8 +125,26 @@ export class CoordinatesInteractions extends React.Component {getCoordinatesDialogAtMapPixel(pixels, olMap, config, isMobile, clearCoordinates);}+ // render geosearch extent alert for selecting points outside of the current map extent+ renderExtentAlert = () => {+ const message = 'The selected coordinates are outside of the current map extent. Select a new point or try a different projection.';+ return (+ <Alert+ id="ol-coordinates-geosearch-select-coordinates-extent-alert"+ isOpen+ title="Selected Coordinates Outside Current Map Projection"+ timeout={15000}+ message={message}+ onDismiss={() => this.setState({ showExtentAlert: false })}+ />+ );+ }+render() {- return null;+ const { showExtentAlert } = this.state;+ return showExtentAlert+ ? this.renderExtentAlert()+ : null;}}@@ -87,18 +156,27 @@ function mapStateToProps(state) {measure,geosearch,} = state;- const { coordinates } = geosearch;+ const { coordinates, isCoordinateSearchActive } = geosearch;const isMobile = browser.lessThan.medium;return {config,map,coordinates,+ isCoordinateSearchActive,isMobile,isShowingClick: map.isClickable,measureIsActive: measure.isActive,};-} const mapDispatchToProps = (dispatch) => ({+}++const mapDispatchToProps = (dispatch) => ({+ selectCoordinatesToFly: (coordinates, reverseGeocodeResults) => {+ dispatch(selectCoordinatesToFly(coordinates, reverseGeocodeResults));+ },+ toggleReverseGeocodeActive: (isActive) => {+ dispatch(toggleReverseGeocodeActive(isActive));+ },changeCursor: (bool) => {dispatch(changeCursorActionCreator(bool));},@@ -106,16 +184,19 @@ function mapStateToProps(state) {dispatch(clearCoordinates());},});-CoordinatesInteractions.propTypes = {+CoordinatesMarker.propTypes = {changeCursor: PropTypes.func.isRequired,config: PropTypes.object.isRequired,clearCoordinates: PropTypes.func.isRequired,+ isCoordinateSearchActive: PropTypes.bool.isRequired,isMobile: PropTypes.bool.isRequired,isShowingClick: PropTypes.bool.isRequired,measureIsActive: PropTypes.bool.isRequired,mouseEvents: PropTypes.object.isRequired,+ selectCoordinatesToFly: PropTypes.func.isRequired,+ toggleReverseGeocodeActive: PropTypes.func.isRequired,};export default connect(mapStateToProps,mapDispatchToProps,-)(CoordinatesInteractions);+)(CoordinatesMarker);diff --git a/web/js/components/map/ol-coordinates.js b/web/js/components/map/ol-coordinates.jsindex 46fd7eb49..f90c6f350 100644--- a/web/js/components/map/ol-coordinates.js+++ b/web/js/components/map/ol-coordinates.js@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';import { transform } from 'ol/proj';import Coordinates from './coordinates';import util from '../../util/util';-import { reverseGeocode } from '../../modules/geosearch/selectors';export default class OlCoordinates extends React.Component {constructor(props) {@@ -17,36 +16,22 @@ export default class OlCoordinates extends React.Component {};this.mouseMove = this.mouseMove.bind(this);this.mouseOut = this.mouseOut.bind(this);- this.mouseClick = this.mouseClick.bind(this);this.changeFormat = this.changeFormat.bind(this);this.registerMouseListeners();}componentWillUnmount() {const { mouseEvents } = this.props;- mouseEvents.off('click', this.mouseClick);mouseEvents.off('mousemove', this.mouseMove);mouseEvents.off('mouseout', this.mouseOut);}registerMouseListeners() {const { mouseEvents } = this.props;- mouseEvents.on('click', this.mouseClick);mouseEvents.on('mousemove', this.mouseMove);mouseEvents.on('mouseout', this.mouseOut);}- mouseClick() {- const { selectCoordinatesToFly, isCoordinateSearchActive } = this.props;- const { latitude, longitude } = this.state;-- if (isCoordinateSearchActive) {- reverseGeocode([longitude, latitude]).then((results) => {- selectCoordinatesToFly([longitude, latitude], results);- });- }- }-mouseMove(event, map, crs) {const pixels = map.getEventPixel(event);const coord = map.getCoordinateFromPixel(pixels);@@ -101,11 +86,12 @@ export default class OlCoordinates extends React.Component {}render() {+ const { isDistractionFreeModeActive } = this.props;const {hasMouse, format, latitude, longitude, crs,} = this.state;// Don't render until a mouse is being used- if (!hasMouse) {+ if (isDistractionFreeModeActive || !hasMouse) {return null;}@@ -125,6 +111,5 @@ export default class OlCoordinates extends React.Component {OlCoordinates.propTypes = {mouseEvents: PropTypes.object.isRequired,- isCoordinateSearchActive: PropTypes.bool,- selectCoordinatesToFly: PropTypes.func,+ isDistractionFreeModeActive: PropTypes.bool.isRequired,};diff --git a/web/js/containers/map-interactions/map-interactions.js b/web/js/containers/map-interactions/map-interactions.jsindex dc8f5ee78..79391bff3 100644--- a/web/js/containers/map-interactions/map-interactions.js+++ b/web/js/containers/map-interactions/map-interactions.js@@ -1,27 +1,24 @@-import React from 'react';+import React, { PureComponent } from 'react';import { connect } from 'react-redux';import PropTypes from 'prop-types';import OlCoordinates from '../../components/map/ol-coordinates';import OlVectorInteractions from './ol-vector-interactions';import OlMeasureTool from '../../components/map/ol-measure-tool';import OlCoordinatesMarker from '../../components/geosearch/ol-coordinates-marker';-import { selectCoordinatesToFly } from '../../modules/geosearch/actions';-class MapInteractions extends React.PureComponent {+class MapInteractions extends PureComponent {getMapClasses = () => {const { isShowingClick, isDistractionFreeModeActive, isCoordinateSearchActive } = this.props;let mapClasses = 'wv-map';mapClasses += isShowingClick && !isCoordinateSearchActive ? ' cursor-pointer' : '';- mapClasses += isCoordinateSearchActive ? ' cursor-crosshair' : '';+ mapClasses += !isDistractionFreeModeActive && isCoordinateSearchActive ? ' cursor-crosshair' : '';mapClasses += isDistractionFreeModeActive ? ' distraction-free-active' : '';return mapClasses;};render() {const {- selectCoordinatesToFly,isDistractionFreeModeActive,- isCoordinateSearchActive,mouseEvents,} = this.props;const mapClasses = this.getMapClasses();@@ -31,15 +28,10 @@ class MapInteractions extends React.PureComponent {id="wv-map"className={mapClasses}/>- {!isDistractionFreeModeActive && (- <>- <OlCoordinates- mouseEvents={mouseEvents}- selectCoordinatesToFly={selectCoordinatesToFly}- isCoordinateSearchActive={isCoordinateSearchActive}- />- </>- )}+ <OlCoordinates+ mouseEvents={mouseEvents}+ isDistractionFreeModeActive={isDistractionFreeModeActive}+ /><OlVectorInteractionsmouseEvents={mouseEvents}/>@@ -52,30 +44,25 @@ class MapInteractions extends React.PureComponent {}}function mapStateToProps(state) {- const { geosearch, map, ui } = state;+ const {+ config, geosearch, map, ui,+ } = state;const { isDistractionFreeModeActive } = ui;const { isCoordinateSearchActive } = geosearch;return {+ config,isShowingClick: map.isClickable,isDistractionFreeModeActive,- isCoordinateSearchActive: !isDistractionFreeModeActive && isCoordinateSearchActive,+ isCoordinateSearchActive,};}-const mapDispatchToProps = (dispatch) => ({- selectCoordinatesToFly: (coordinates, reverseGeocodeResults) => {- dispatch(selectCoordinatesToFly(coordinates, reverseGeocodeResults));- },-});-MapInteractions.propTypes = {isDistractionFreeModeActive: PropTypes.bool.isRequired,isShowingClick: PropTypes.bool.isRequired,mouseEvents: PropTypes.object.isRequired,isCoordinateSearchActive: PropTypes.bool,- selectCoordinatesToFly: PropTypes.func,};export default connect(mapStateToProps,- mapDispatchToProps,)(MapInteractions);