Interactive interface for browsing global, full-resolution satellite imagery
add slight hit tolerance allowance for mobile devices
Ed Plato183c55c3c88d
diff --git a/web/css/geosearch.css b/web/css/geosearch.cssindex 6c29c1e37..553347922 100644--- a/web/css/geosearch.css+++ b/web/css/geosearch.css@@ -154,6 +154,10 @@}/* Additional Styling */+.coordinates-map-marker-dialog {+ z-index: 1;+}+.geosearch-input-alert-icon {right: 120px;}@@ -175,7 +179,7 @@right: 70px;}.geosearch-input-alert-icon {- right: 130px;+ right: 135px;}.geosearch-autocomplete {font-size: 16px;diff --git a/web/js/components/geosearch/coordinates-dialog.js b/web/js/components/geosearch/coordinates-dialog.jsindex 7643f527f..7c1570f68 100644--- a/web/js/components/geosearch/coordinates-dialog.js+++ b/web/js/components/geosearch/coordinates-dialog.js@@ -12,6 +12,7 @@ class CoordinatesDialog extends Component {this.state = {tooltipToggleTime: 0,showTooltips: true,+ isCopyToClipboardTooltipVisible: false,};}@@ -19,6 +20,7 @@ class CoordinatesDialog extends Component {onCopyToClipboard = () => {this.setState({tooltipToggleTime: Date.now(),+ isCopyToClipboardTooltipVisible: true,});}@@ -40,6 +42,12 @@ class CoordinatesDialog extends Component {removeCoordinatesDialog();}+ clearCopyToClipboardTooltip = () => {+ this.setState({+ isCopyToClipboardTooltipVisible: false,+ });+ }+// render minimize and remove dialog button controlsrenderDialogButtonControls = () => {const {@@ -91,9 +99,11 @@ class CoordinatesDialog extends Component {renderCopyToClipboardButton = () => {const { coordinatesMetadata, isMobile } = this.props;const { coordinates } = coordinatesMetadata;+ const { isCopyToClipboardTooltipVisible, showTooltips } = this.state;const buttonId = 'copy-coordinates-to-clipboard-button';const labelText = 'Copy coordinates to clipboard';+ const tooltipVisibilityCondition = !isMobile && !isCopyToClipboardTooltipVisible && showTooltips;return (<CopyToClipboardoptions={window.clipboardData ? {} : { format: 'text/plain' }}@@ -104,8 +114,12 @@ class CoordinatesDialog extends Component {id={buttonId}className={buttonId}>- {!isMobile && (- <UncontrolledTooltip placement="bottom" trigger="hover" target={buttonId}>+ {tooltipVisibilityCondition && (+ <UncontrolledTooltip+ placement="bottom"+ trigger="hover"+ target={buttonId}+ >{labelText}</UncontrolledTooltip>)}@@ -120,6 +134,7 @@ class CoordinatesDialog extends Component {coordinatesMetadata, tooltipId,} = this.props;const {+ showTooltips,tooltipToggleTime,} = this.state;const {@@ -129,9 +144,12 @@ class CoordinatesDialog extends Component {return (<div className={`tooltip-custom-black tooltip-static tooltip-coordinates-container ${tooltipId}`}>+ {showTooltips && (<CopyClipboardTooltiptooltipToggleTime={tooltipToggleTime}+ clearCopyToClipboardTooltip={this.clearCopyToClipboardTooltip}/>+ )}<div className="tooltip-coordinates-title">{title}</div><div className="tooltip-coordinates">{coordinates}</div>{this.renderDialogButtonControls()}diff --git a/web/js/components/geosearch/copy-tooltip.js b/web/js/components/geosearch/copy-tooltip.jsindex 6367ef8f5..d41bf35d6 100644--- a/web/js/components/geosearch/copy-tooltip.js+++ b/web/js/components/geosearch/copy-tooltip.js@@ -16,10 +16,15 @@ class CopyClipboardTooltip extends PureComponent {}componentDidUpdate(prevProps) {- const { tooltipToggleTime } = this.props;+ const { clearCopyToClipboardTooltip, tooltipToggleTime } = this.props;const toolTipChange = tooltipToggleTime !== prevProps.tooltipToggleTime;if (toolTipChange) {- this.updateToolTipState(toolTipChange);+ this.updateToolTipState();+ clearTimeout(this.showCopiedToolTipTimeout);+ this.showCopiedToolTipTimeout = setTimeout(() => {+ clearCopyToClipboardTooltip();+ this.setState({ showCopiedToolTip: false });+ }, 2000);}}@@ -28,36 +33,29 @@ class CopyClipboardTooltip extends PureComponent {clearTimeout(this.showCopiedToolTipTimeout);}- updateToolTipState = (toolTipChange) => {+ updateToolTipState = () => {this.setState({- showCopiedToolTip: toolTipChange,+ showCopiedToolTip: true,});}render() {const { showCopiedToolTip } = this.state;- if (showCopiedToolTip) {- clearTimeout(this.showCopiedToolTipTimeout);- this.showCopiedToolTipTimeout = setTimeout(() => {- this.setState({ showCopiedToolTip: false });- }, 2000);- }return (- <>- <Tooltip- placement="bottom"- isOpen={showCopiedToolTip}- hideArrow- target="copy-coordinates-to-clipboard-button"- >- Copied to clipboard!- </Tooltip>- </>+ <Tooltip+ placement="bottom"+ isOpen={showCopiedToolTip}+ hideArrow+ target="copy-coordinates-to-clipboard-button"+ >+ Copied to clipboard!+ </Tooltip>);}}CopyClipboardTooltip.propTypes = {+ clearCopyToClipboardTooltip: PropTypes.func,tooltipToggleTime: PropTypes.number,};diff --git a/web/js/components/geosearch/geosearch-input.js b/web/js/components/geosearch/geosearch-input.jsindex af6de2a9e..23ff6256e 100644--- a/web/js/components/geosearch/geosearch-input.js+++ b/web/js/components/geosearch/geosearch-input.js@@ -132,7 +132,7 @@ class SearchBox extends Component {<InputGroupAddonclassName="geosearch-input-group-addon geosearch-input-alert-icon"addonType="append"- title="The entered location is not avaialable."+ title="The entered location is not available."><FontAwesomeIcon icon="exclamation-triangle" size="1x" /></InputGroupAddon>diff --git a/web/js/components/geosearch/geosearch-modal.js b/web/js/components/geosearch/geosearch-modal.jsindex 43cf68ef8..05500960b 100644--- a/web/js/components/geosearch/geosearch-modal.js+++ b/web/js/components/geosearch/geosearch-modal.js@@ -5,7 +5,7 @@ import {Button, InputGroup, InputGroupAddon, UncontrolledTooltip,} from 'reactstrap';import {- throttle as lodashThrottle,+ debounce as lodashDebounce,get as lodashGet,} from 'lodash';import googleTagManager from 'googleTagManager';@@ -39,7 +39,7 @@ class GeosearchModal extends Component {showReverseGeocodeAlert: false,showNoSuggestionsAlert: false,};- this.throttleGetSuggestions = lodashThrottle(this.getSuggestions, 400, { leading: true, trailing: true });+ this.debounceGetSuggestions = lodashDebounce(this.getSuggestions, 400, { leading: true, trailing: true });}componentDidUpdate(prevProps) {@@ -63,8 +63,15 @@ class GeosearchModal extends Component {}// handle add/remove no suggestion alert based on inputValue and suggestionsif (inputValue && suggestions.length === 0 && prevProps.suggestions.length > 0) {- this.setNoSuggestionsAlert(true);- this.setInputAlertIcon(true);+ const prevInputValue = prevProps.inputValue;+ const prevSuggestedPlace = prevProps.suggestedPlace;+ const newSuggestedPlaceSelected = prevInputValue && prevSuggestedPlace.length > 0 && prevSuggestedPlace[0].text === prevInputValue;+ const isCoordinates = isValidCoordinates(inputValue);+ // prevent flag error on new place/coordinates being copy pasted+ if (!newSuggestedPlaceSelected && !isCoordinates) {+ this.setNoSuggestionsAlert(true);+ this.setInputAlertIcon(true);+ }} else if ((showNoSuggestionsAlert || showInputAlert) && (!inputValue || suggestions.length > 0)) {this.setNoSuggestionsAlert(false);this.setInputAlertIcon(false);@@ -179,18 +186,18 @@ class GeosearchModal extends Component {// check for coordinate valueconst coordinatesInputValue = isValidCoordinates(value);if (coordinatesInputValue) {- this.throttleGetSuggestions.cancel();+ this.debounceGetSuggestions.cancel();const { latitude, longitude } = coordinatesInputValue;this.clearAlerts();clearSuggestions();updatePendingCoordinates([longitude, latitude]);} else if (!value) {// clear on empty input- this.throttleGetSuggestions.cancel();+ this.debounceGetSuggestions.cancel();clearSuggestions();} else {// provide suggestions to populate search result menu item(s)- this.throttleGetSuggestions(value);+ this.debounceGetSuggestions(value);}}@@ -391,7 +398,7 @@ const mapStateToProps = (state) => {geosearch,} = state;const {- coordinates, isCoordinateSearchActive, isExpanded, suggestions,+ coordinates, isCoordinateSearchActive, isExpanded, suggestions, suggestedPlace,} = geosearch;const isMobile = browser.lessThan.medium;const geosearchMobileModalOpen = modal.isOpen && modal.id === 'TOOLBAR_GEOSEARCH_MOBILE';@@ -407,6 +414,7 @@ const mapStateToProps = (state) => {processMagicKey: (magicKey) => processMagicKey(magicKey, config),reverseGeocode: (coords) => reverseGeocode(coords, config),suggestions,+ suggestedPlace,};};@@ -447,6 +455,7 @@ GeosearchModal.propTypes = {setPlaceMarker: PropTypes.func,setSuggestion: PropTypes.func,suggestions: PropTypes.array,+ suggestedPlace: PropTypes.array,toggleReverseGeocodeActive: PropTypes.func,toggleShowGeosearch: PropTypes.func,updatePendingCoordinates: PropTypes.func,diff --git a/web/js/components/geosearch/geosearch.js b/web/js/components/geosearch/geosearch.jsindex ed3ee9069..7ac4790b9 100644--- a/web/js/components/geosearch/geosearch.js+++ b/web/js/components/geosearch/geosearch.js@@ -2,6 +2,9 @@ import React, { Component } from 'react';import PropTypes from 'prop-types';import { connect } from 'react-redux';import GeosearchModal from './geosearch-modal';+import {+ toggleShowGeosearch,+} from '../../modules/geosearch/actions';class Geosearch extends Component {constructor(props) {@@ -92,6 +95,12 @@ const mapStateToProps = (state) => {};};+const mapDispatchToProps = (dispatch) => ({+ toggleShowGeosearch: () => {+ dispatch(toggleShowGeosearch());+ },+});+Geosearch.propTypes = {isExpanded: PropTypes.bool,isFeatureEnabled: PropTypes.bool,@@ -102,4 +111,5 @@ Geosearch.propTypes = {export default connect(mapStateToProps,+ mapDispatchToProps,)(Geosearch);diff --git a/web/js/components/geosearch/ol-coordinates-marker-util.js b/web/js/components/geosearch/ol-coordinates-marker-util.jsindex d8cc7528a..44f5e334f 100644--- a/web/js/components/geosearch/ol-coordinates-marker-util.js+++ b/web/js/components/geosearch/ol-coordinates-marker-util.js@@ -37,7 +37,7 @@ const getCoordinatesDialogTitle = (geocodeProperties) => {};/**- * Create tooltip React DOM element+ * Create dialog React DOM element** @param {Object} map* @param {Object} config@@ -49,7 +49,7 @@ const getCoordinatesDialogTitle = (geocodeProperties) => {** @returns {Void}*/-export const renderCoordinatesTooltip = (map, config, coordinates, coordinatesMetadata, isMobile, clearCoordinates, toggleDialogVisible) => {+export const renderCoordinatesDialog = (map, config, coordinates, coordinatesMetadata, isMobile, clearCoordinates, toggleDialogVisible) => {const { projections } = config;const { proj } = map;const { crs } = projections[proj];@@ -60,6 +60,7 @@ export const renderCoordinatesTooltip = (map, config, coordinates, coordinatesMeconst tooltipId = util.encodeId(`coordinates-map-marker_${latitude},${longitude}`);const tooltipOverlay = new Overlay({id: tooltipId,+ className: 'coordinates-map-marker-dialog',element: tooltipElement,offset: [0, -40],positioning: 'bottom-center',@@ -78,9 +79,12 @@ export const renderCoordinatesTooltip = (map, config, coordinates, coordinatesMemap.addOverlay(tooltipOverlay);tooltipOverlay.setPosition(coordinatesPosition);+ const coordinatesTooltipDOMEl = tooltipOverlay.getElement();+// helper function to remove/hide tooltip overlayconst removeCoordinatesDialog = () => {toggleDialogVisible(false);+ ReactDOM.unmountComponentAtNode(coordinatesTooltipDOMEl);};ReactDOM.render((@@ -91,7 +95,9 @@ export const renderCoordinatesTooltip = (map, config, coordinates, coordinatesMeisMobile={isMobile}tooltipId={tooltipId}/>- ), tooltipOverlay.getElement());+ ), coordinatesTooltipDOMEl);++ return coordinatesTooltipDOMEl;};/**@@ -122,10 +128,11 @@ export const getCoordinatesMetadata = (geocodeProperties) => {** @param {Array} pixels* @param {Object} map+ * @param {Boolean} isMobile** @returns {Void}*/-export const isCoordinatesDialogAvailableAtPixel = (pixels, map) => {+export const isCoordinatesDialogAvailableAtPixel = (pixels, map, isMobile) => {// check for existing coordinate marker tooltip overlay and prevent multiple rendersconst mapOverlays = map.getOverlays().getArray();const mapMarkerId = 'coordinates-map-marker';@@ -137,6 +144,7 @@ export const isCoordinatesDialogAvailableAtPixel = (pixels, map) => {return;}+ const featureOptions = isMobile ? { hitTolerance: 5 } : {};const featureCheck = (feature) => feature.getId() === mapMarkerId;- return map.forEachFeatureAtPixel(pixels, featureCheck);+ return map.forEachFeatureAtPixel(pixels, featureCheck, featureOptions);};diff --git a/web/js/components/geosearch/ol-coordinates-marker.js b/web/js/components/geosearch/ol-coordinates-marker.jsindex 22b3cbb59..4e46d0ee9 100644--- a/web/js/components/geosearch/ol-coordinates-marker.js+++ b/web/js/components/geosearch/ol-coordinates-marker.js@@ -1,6 +1,5 @@import { connect } from 'react-redux';import {- debounce as lodashDebounce,isNaN as lodashIsNaN,} from 'lodash';import React, { Component } from 'react';@@ -20,12 +19,10 @@ 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.singleclick = this.singleclick.bind(this);+ this.mouseMove = this.mouseMove.bind(this);+ this.singleClick = this.singleClick.bind(this);this.rightClick = this.rightClick.bind(this);this.registerMouseListeners();}@@ -33,14 +30,14 @@ export class CoordinatesMarker extends Component {componentWillUnmount() {const { mouseEvents } = this.props;mouseEvents.off('mousemove', this.mouseMove);- mouseEvents.off('singleclick', this.singleclick);+ mouseEvents.off('singleclick', this.singleClick);mouseEvents.off('contextmenu', this.rightClick);}registerMouseListeners() {const { mouseEvents } = this.props;mouseEvents.on('mousemove', this.mouseMove);- mouseEvents.on('singleclick', this.singleclick);+ mouseEvents.on('singleclick', this.singleClick);mouseEvents.on('contextmenu', this.rightClick);}@@ -53,9 +50,12 @@ export class CoordinatesMarker extends Component {changeCursor,measureIsActive,} = this.props;++ if (!coord) {+ return;+ }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);@@ -68,9 +68,6 @@ export class CoordinatesMarker extends Component {} else if (!hasFeatures && isShowingClick) {changeCursor(false);}- const latFormat = getCoordinateFixedPrecision(lat);- const lonFormat = getCoordinateFixedPrecision(lon);- this.setState({ latitude: latFormat, longitude: lonFormat });}rightClick(e) {@@ -84,7 +81,7 @@ export class CoordinatesMarker extends Component {toggleReverseGeocodeActive(false);}- singleclick(e, map) {+ singleClick(e, map, crs) {const {config,isCoordinateSearchActive,@@ -92,10 +89,14 @@ export class CoordinatesMarker extends Component {setPlaceMarker,toggleReverseGeocodeActive,} = this.props;- const {- latitude,- longitude,- } = this.state;++ const pixels = e.pixel;+ const coord = map.getCoordinateFromPixel(pixels);++ const [lon, lat] = transform(coord, crs, 'EPSG:4326');++ const latitude = getCoordinateFixedPrecision(lat);+ const longitude = getCoordinateFixedPrecision(lon);if (measureIsActive) return;// handle reverse geocoding mouse click@@ -116,16 +117,16 @@ export class CoordinatesMarker extends Component {} else {// handle clicking on pixel and/or map markere.stopPropagation();- const pixels = e.pixel;this.getCoordinatesDialog(pixels, map);}}getCoordinatesDialog = (pixels, olMap) => {const {+ isMobile,toggleDialogVisible,} = this.props;- const isMarker = isCoordinatesDialogAvailableAtPixel(pixels, olMap);+ const isMarker = isCoordinatesDialogAvailableAtPixel(pixels, olMap, isMobile);if (isMarker) {toggleDialogVisible(true);@@ -193,6 +194,7 @@ CoordinatesMarker.propTypes = {changeCursor: PropTypes.func.isRequired,config: PropTypes.object.isRequired,isCoordinateSearchActive: PropTypes.bool.isRequired,+ isMobile: PropTypes.bool.isRequired,isShowingClick: PropTypes.bool.isRequired,measureIsActive: PropTypes.bool.isRequired,mouseEvents: PropTypes.object.isRequired,diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.jsindex 4366a8bd5..af2fb96a4 100644--- a/web/js/containers/toolbar.js+++ b/web/js/containers/toolbar.js@@ -245,7 +245,6 @@ class toolbarContainer extends Component {id={buttonId}className="wv-toolbar-button"aria-label={labelText}- title="Search by place name or reverse search using coordinates"onClick={handleButtonClick}>{this.renderTooltip(buttonId, labelText)}diff --git a/web/js/map/ui.js b/web/js/map/ui.jsindex 7ae591e8e..26343f380 100644--- a/web/js/map/ui.js+++ b/web/js/map/ui.js@@ -9,6 +9,7 @@ import {cloneDeep as lodashCloneDeep,find as lodashFind,} from 'lodash';+import ReactDOM from 'react-dom';import OlMap from 'ol/Map';import OlView from 'ol/View';import OlKinetic from 'ol/Kinetic';@@ -63,7 +64,7 @@ import { faIconPlusSVGDomEl, faIconMinusSVGDomEl } from './fa-map-icons';import { hasVectorLayers } from '../modules/layers/util';import { animateCoordinates, getCoordinatesMarker } from '../modules/geosearch/util';import { reverseGeocode } from '../modules/geosearch/util-api';-import { getCoordinatesMetadata, renderCoordinatesTooltip } from '../components/geosearch/ol-coordinates-marker-util';+import { getCoordinatesMetadata, renderCoordinatesDialog } from '../components/geosearch/ol-coordinates-marker-util';export default function mapui(models, config, store, ui) {const id = 'wv-map';@@ -101,6 +102,7 @@ export default function mapui(models, config, store, ui) {self.promiseDay = precache.promiseDay;self.selectedVectors = {};self.activeMarker = null;+ self.coordinatesDialogDOMEl = null;/*** Suscribe to redux store and listen for* specific action types@@ -307,7 +309,18 @@ export default function mapui(models, config, store, ui) {const toggleDialogVisible = (isVisible) => {store.dispatch({ type: TOGGLE_DIALOG_VISIBLE, value: isVisible });};- renderCoordinatesTooltip(self.selected, config, [latitude, longitude], coordinatesMetadata, isMobile, clearMarker, toggleDialogVisible);++ // render coordinates dialog+ const coordinatesTooltipDOMEl = renderCoordinatesDialog(+ self.selected,+ config,+ [latitude, longitude],+ coordinatesMetadata,+ isMobile,+ clearMarker,+ toggleDialogVisible,+ );+ self.coordinatesDialogDOMEl = coordinatesTooltipDOMEl;};/*@@ -333,6 +346,11 @@ export default function mapui(models, config, store, ui) {const { sources } = config;const { active } = layers;+ // unmount coordinate dialog to prevent residual tooltips being hovered+ if (self.coordinatesDialogDOMEl) {+ ReactDOM.unmountComponentAtNode(self.coordinatesDialogDOMEl);+ self.coordinatesDialogDOMEl = null;+ }// clear previous marker (if present) and get new markerremoveCoordinatesMarker();const marker = getCoordinatesMarker({ ui: self }, config, coordinates, results);diff --git a/web/js/modules/geosearch/reducers.js b/web/js/modules/geosearch/reducers.jsindex 1ead7e82e..705478fdf 100644--- a/web/js/modules/geosearch/reducers.js+++ b/web/js/modules/geosearch/reducers.js@@ -20,6 +20,7 @@ export const geosearchState = {isExpanded: !localStorageCollapseState,reverseGeocodeResults: null,suggestions: [],+ suggestedPlace: [],};export function geosearchReducer(state = geosearchState, action) {@@ -62,7 +63,7 @@ export function geosearchReducer(state = geosearchState, action) {case SET_SUGGESTION:return {...state,- suggestions: action.value,+ suggestedPlace: action.value,};case REQUEST_SUGGEST_PLACE_SUCCESS:return {@@ -78,6 +79,7 @@ export function geosearchReducer(state = geosearchState, action) {return {...state,suggestions: action.value,+ suggestedPlace: action.value,};default:return state;diff --git a/web/js/modules/geosearch/reducers.test.js b/web/js/modules/geosearch/reducers.test.jsindex 345df1a1c..6314db3a4 100644--- a/web/js/modules/geosearch/reducers.test.js+++ b/web/js/modules/geosearch/reducers.test.js@@ -128,13 +128,13 @@ describe('geosearchReducer', () => {}),).toEqual({...geosearchState,- suggestions: suggestion,+ suggestedPlace: suggestion,});},);test(`${CLEAR_SUGGESTIONS- } updates suggestions with clear value and `+ } updates suggestions and suggestedPlace with clear value and `+ 'should return new state',() => {expect(@@ -145,6 +145,7 @@ describe('geosearchReducer', () => {).toEqual({...geosearchState,suggestions: [],+ suggestedPlace: [],});},);