Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

update features config and doc

Ed Plato10b97cf1d84c
diff --git a/config/default/common/features.json b/config/default/common/features.json
index 7b49f54d5..329e5a8e0 100644
--- a/config/default/common/features.json
+++ b/config/default/common/features.json
@@ -8,7 +8,6 @@
"tour": true,
"feedback": true,
"previewSnapshots": true,
- "geocodeSearch": true,
"googleTagManager": {
"id": "GTM-WNP7MLF"
},
@@ -21,6 +20,9 @@
},
"naturalEvents": {
"host": "https://eonet.sci.gsfc.nasa.gov/api/v3"
+ },
+ "geocodeSearch": {
+ "url": "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/"
}
},
"scripts": [
diff --git a/doc/features.md b/doc/features.md
index a01635484..0b85ad24d 100644
--- a/doc/features.md
+++ b/doc/features.md
@@ -29,7 +29,7 @@ edit `config/default/common/features.json` and set `"dataDownload": true`.
## GeocodeSearch
This feature uses the [ArcGIS World Geocoding Service](https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm) to find addresses based on input text, coordinates, and by clicking a spot on the map. To enable,
-edit `config/default/common/features.json` and set `"geocodeSearch": true`.
+edit `config/default/common/features.json` and set `"geocodeSearch"` object `"url"` to use the ArcGIS request URL used by the [ArcGIS World Geocoding Service](https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm).
## URL Shortening
diff --git a/e2e/features/geosearch/geosearch-test.js b/e2e/features/geosearch/geosearch-test.js
index e77445334..c9b0c4bf9 100644
--- a/e2e/features/geosearch/geosearch-test.js
+++ b/e2e/features/geosearch/geosearch-test.js
@@ -12,8 +12,7 @@ const {
geosearchMinimizeButton,
tooltipCoordinatesContainer,
tooltipCoordinatesTitle,
- tooltipCoordinatesLatitude,
- tooltipCoordinatesLongitude,
+ tooltipCoordinates,
} = localSelectors;
module.exports = {
@@ -47,8 +46,7 @@ module.exports = {
},
'Coordinates title and detailed coordinates are correct': (c) => {
c.assert.containsText(tooltipCoordinatesTitle, 'Washington, District of Columbia');
- c.assert.containsText(tooltipCoordinatesLatitude, 'Latitude: 38.8904°');
- c.assert.containsText(tooltipCoordinatesLongitude, 'Longitude: -77.0320°');
+ c.assert.containsText(tooltipCoordinates, '38.8904°, -77.0320°');
},
'Clicking minimize tooltip hides the coordinates dialog': (c) => {
c.click('.minimize-coordinates-tooltip');
@@ -60,8 +58,7 @@ module.exports = {
c.waitForElementVisible(tooltipCoordinatesContainer, TIME_LIMIT);
c.expect.element(testMarkerNoDetailsEncodedID).to.be.present;
c.assert.containsText(tooltipCoordinatesTitle, '5.0000°, -51.5000°');
- c.assert.containsText(tooltipCoordinatesLatitude, 'Latitude: 5.0000°');
- c.assert.containsText(tooltipCoordinatesLongitude, 'Longitude: -51.5000°');
+ c.assert.containsText(tooltipCoordinates, '5.0000°, -51.5000°');
},
after(c) {
c.end();
diff --git a/e2e/reuseables/selectors.js b/e2e/reuseables/selectors.js
index 9f4b3c8d0..c2a0f8605 100644
--- a/e2e/reuseables/selectors.js
+++ b/e2e/reuseables/selectors.js
@@ -130,6 +130,5 @@ module.exports = {
geosearchMinimizeButton: '.geosearch-search-minimize-button',
tooltipCoordinatesContainer: '.tooltip-coordinates-container',
tooltipCoordinatesTitle: '.tooltip-coordinates-title',
- tooltipCoordinatesLatitude: '.tooltip-coordinates-latitude',
- tooltipCoordinatesLongitude: '.tooltip-coordinates-longitude',
+ tooltipCoordinates: '.tooltip-coordinates',
};
diff --git a/web/css/tooltip.css b/web/css/tooltip.css
index 4fbe1855b..0b6058627 100644
--- a/web/css/tooltip.css
+++ b/web/css/tooltip.css
@@ -142,13 +142,9 @@
font-size: 16px;
padding-right: 50px;
}
- .tooltip-coordinates-group {
- display: flex;
+ .tooltip-coordinates {
margin-top: 6px;
- & div:nth-child(2) {
- padding-left: 15px;
- padding-right: 26px;
- }
+ padding-right: 26px;
}
.close-tooltip,
.minimize-tooltip {
diff --git a/web/js/components/geosearch/coordinates-dialog.js b/web/js/components/geosearch/coordinates-dialog.js
index d2cfbe0c9..ca9129f4f 100644
--- a/web/js/components/geosearch/coordinates-dialog.js
+++ b/web/js/components/geosearch/coordinates-dialog.js
@@ -90,14 +90,14 @@ class CoordinatesDialog extends Component {
// render copy to clipboard button
renderCopyToClipboardButton = () => {
const { coordinatesMetadata, isMobile } = this.props;
- const { latitude, longitude } = coordinatesMetadata;
+ const { coordinates } = coordinatesMetadata;
const buttonId = 'copy-coordinates-to-clipboard-button';
const labelText = 'Copy coordinates to clipboard';
return (
<CopyToClipboard
options={window.clipboardData ? {} : { format: 'text/plain' }}
- text={`${latitude}, ${longitude}`}
+ text={coordinates}
onCopy={this.onCopyToClipboard}
>
<div
@@ -124,28 +124,17 @@ class CoordinatesDialog extends Component {
} = this.state;
const {
- latitude,
- longitude,
+ coordinates,
title,
} = coordinatesMetadata;
- const latitudeText = `Latitude: ${latitude}`;
- const longitudeText = `Longitude: ${longitude}`;
-
return (
<div className={`tooltip-custom-black tooltip-static tooltip-coordinates-container ${tooltipId}`}>
<CopyClipboardTooltip
tooltipToggleTime={tooltipToggleTime}
/>
<div className="tooltip-coordinates-title">{title}</div>
- <div className="tooltip-coordinates-group">
- <div className="tooltip-coordinates-latitude">
- {latitudeText}
- </div>
- <div className="tooltip-coordinates-longitude">
- {longitudeText}
- </div>
- </div>
+ <div className="tooltip-coordinates">{coordinates}</div>
{this.renderDialogButtonControls()}
{this.renderCopyToClipboardButton()}
</div>
diff --git a/web/js/components/geosearch/geosearch-input.js b/web/js/components/geosearch/geosearch-input.js
index 6bcf54bbf..2c833b56a 100644
--- a/web/js/components/geosearch/geosearch-input.js
+++ b/web/js/components/geosearch/geosearch-input.js
@@ -28,11 +28,14 @@ class SearchBox extends Component {
handleSubmitClick = (e) => {
e.preventDefault();
const {
- onSelect, coordinatesPending, onCoordinateInputSelect, searchResults,
+ coordinatesPending,
+ onCoordinateInputSelect,
+ onSelect,
+ suggestions,
} = this.props;
if (coordinatesPending.length > 0) {
onCoordinateInputSelect();
- } else if (searchResults.length > 0 && this.highlightedItem) {
+ } else if (suggestions.length > 0 && this.highlightedItem) {
onSelect(this.highlightedItem.text, this.highlightedItem);
}
}
@@ -182,9 +185,9 @@ class SearchBox extends Component {
// condtional autocomplete wrapper styling
getWrapperStyle = () => {
const {
+ inputValue,
isMobile,
showExtentAlert,
- inputValue,
} = this.props;
// handle mobile/desktop input padding with/without alert
@@ -206,7 +209,7 @@ class SearchBox extends Component {
isMobile,
onChange,
onSelect,
- searchResults,
+ suggestions,
} = this.props;
const placeHolderText = isMobile
@@ -226,7 +229,7 @@ class SearchBox extends Component {
}}
wrapperStyle={this.getWrapperStyle()}
value={inputValue}
- items={searchResults}
+ items={suggestions}
getItemValue={(item) => item.text}
onSelect={onSelect}
onChange={onChange}
@@ -244,15 +247,15 @@ class SearchBox extends Component {
SearchBox.propTypes = {
clearInput: PropTypes.func,
coordinatesPending: PropTypes.array,
- onCoordinateInputSelect: PropTypes.func,
- searchResults: PropTypes.array,
geosearchMobileModalOpen: PropTypes.bool,
inputValue: PropTypes.string,
isExpanded: PropTypes.bool,
isMobile: PropTypes.bool,
- onSelect: PropTypes.func,
onChange: PropTypes.func,
+ onCoordinateInputSelect: PropTypes.func,
+ onSelect: PropTypes.func,
showExtentAlert: PropTypes.bool,
+ suggestions: PropTypes.array,
};
export default SearchBox;
diff --git a/web/js/components/geosearch/geosearch-modal.js b/web/js/components/geosearch/geosearch-modal.js
index e8310d5bd..803a053c0 100644
--- a/web/js/components/geosearch/geosearch-modal.js
+++ b/web/js/components/geosearch/geosearch-modal.js
@@ -11,19 +11,17 @@ import googleTagManager from 'googleTagManager';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import SearchBox from './geosearch-input';
import Alert from '../util/alert';
-
import isValidCoordinates from './util';
-import { reverseGeocode, suggest, processMagicKey } from '../../modules/geosearch/selectors';
-class SearchComponent extends Component {
+class GeosearchModal extends Component {
constructor(props) {
super(props);
this.state = {
isTouchDevice: false,
- showReverseGeocodeAlert: false,
showExtentAlert: false,
+ showReverseGeocodeAlert: false,
};
- this.throttleSuggest = lodashThrottle(suggest.bind(this), 500);
+ this.throttlegetSuggestions = lodashThrottle(this.getSuggestions, 400, { leading: true, trailing: true });
}
componentDidUpdate(prevProps) {
@@ -44,6 +42,12 @@ class SearchComponent extends Component {
}
}
+ // suggest place with text input to get place suggestions
+ getSuggestions = (val) => {
+ const { getSuggestions } = this.props;
+ getSuggestions(val);
+ }
+
// dismiss message instruction alert
dismissReverseGeocodeAlert = () => this.setState({ showReverseGeocodeAlert: false });
@@ -53,11 +57,12 @@ class SearchComponent extends Component {
// handle submitting search after inputing coordinates
onCoordinateInputSelect = () => {
const {
+ clearSuggestions,
coordinatesPending,
isCoordinatePairWithinExtent,
+ reverseGeocode,
selectCoordinatesToFly,
updatePendingCoordinates,
- updateSearchResults,
updateValue,
} = this.props;
@@ -71,7 +76,7 @@ class SearchComponent extends Component {
});
this.setExtentAlert(false);
updateValue('');
- updateSearchResults([]);
+ clearSuggestions();
updatePendingCoordinates([]);
}
}
@@ -80,12 +85,13 @@ class SearchComponent extends Component {
onSelect = (value, item) => {
const {
isCoordinatePairWithinExtent,
+ processMagicKey,
selectCoordinatesToFly,
- updateSearchResults,
+ setSuggestion,
updateValue,
} = this.props;
updateValue(value);
- updateSearchResults([item]);
+ setSuggestion([item]);
const {
magicKey,
} = item;
@@ -117,43 +123,38 @@ class SearchComponent extends Component {
onChange = (e, value) => {
e.preventDefault();
const {
- updateSearchResults, updateValue, updatePendingCoordinates,
+ clearSuggestions,
+ updateValue,
+ updatePendingCoordinates,
} = this.props;
updateValue(value);
// check for coordinate value
const coordinatesInputValue = isValidCoordinates(value);
if (coordinatesInputValue) {
- this.throttleSuggest.cancel();
+ this.throttlegetSuggestions.cancel();
const { latitude, longitude } = coordinatesInputValue;
this.setExtentAlert(false);
- updateSearchResults([]);
+ clearSuggestions();
updatePendingCoordinates([longitude, latitude]);
+ } else if (!value) {
+ // clear on empty input
+ this.throttlegetSuggestions.cancel();
+ clearSuggestions();
} else {
- this.throttleSuggest.cancel();
- if (!value) {
- updateSearchResults([]);
- } else {
- // provide suggestions to populate search result menu item(s)
- return this.throttleSuggest(value).then((items) => {
- if (lodashGet(items, 'suggestions')) {
- const { suggestions } = items;
- updateSearchResults(suggestions);
- } else {
- updateSearchResults([]);
- }
- });
- }
+ // provide suggestions to populate search result menu item(s)
+ this.throttlegetSuggestions(value);
}
}
// clear text input and search results
clearInput = () => {
const {
- updateSearchResults, updateValue,
+ clearSuggestions,
+ updateValue,
} = this.props;
updateValue('');
- updateSearchResults([]);
+ clearSuggestions();
this.setState({
showReverseGeocodeAlert: false,
showExtentAlert: false,
@@ -279,7 +280,7 @@ class SearchComponent extends Component {
isMobile,
coordinatesPending,
inputValue,
- searchResults,
+ suggestions,
} = this.props;
const {
showExtentAlert,
@@ -298,15 +299,15 @@ class SearchComponent extends Component {
clearInput={this.clearInput}
coordinates={coordinates}
coordinatesPending={coordinatesPending}
+ geosearchMobileModalOpen={geosearchMobileModalOpen}
inputValue={inputValue}
+ isExpanded={isExpanded}
+ isMobile={isMobile}
onChange={this.onChange}
onCoordinateInputSelect={this.onCoordinateInputSelect}
onSelect={this.onSelect}
- searchResults={searchResults}
- geosearchMobileModalOpen={geosearchMobileModalOpen}
- isExpanded={isExpanded}
- isMobile={isMobile}
showExtentAlert={showExtentAlert}
+ suggestions={suggestions}
/>
{/* Add coordinate marker button */}
{this.renderAddCoordinateButton()}
@@ -317,7 +318,8 @@ class SearchComponent extends Component {
}
}
-SearchComponent.propTypes = {
+GeosearchModal.propTypes = {
+ clearSuggestions: PropTypes.func,
coordinates: PropTypes.array,
coordinatesPending: PropTypes.array,
geosearchMobileModalOpen: PropTypes.bool,
@@ -326,13 +328,16 @@ SearchComponent.propTypes = {
isCoordinateSearchActive: PropTypes.bool,
isExpanded: PropTypes.bool,
isMobile: PropTypes.bool,
- searchResults: PropTypes.array,
+ processMagicKey: PropTypes.func,
+ reverseGeocode: PropTypes.func,
selectCoordinatesToFly: PropTypes.func,
+ setSuggestion: PropTypes.func,
+ suggestions: PropTypes.array,
+ getSuggestions: PropTypes.func,
toggleReverseGeocodeActive: PropTypes.func,
toggleShowGeosearch: PropTypes.func,
updatePendingCoordinates: PropTypes.func,
- updateSearchResults: PropTypes.func,
updateValue: PropTypes.func,
};
-export default SearchComponent;
+export default GeosearchModal;
diff --git a/web/js/components/geosearch/geosearch.js b/web/js/components/geosearch/geosearch.js
index 0d6b92575..c5aec2d78 100644
--- a/web/js/components/geosearch/geosearch.js
+++ b/web/js/components/geosearch/geosearch.js
@@ -4,20 +4,26 @@ import { connect } from 'react-redux';
import GeosearchModal from './geosearch-modal';
import {
clearCoordinates,
+ clearSuggestions,
selectCoordinatesToFly,
toggleShowGeosearch,
toggleReverseGeocodeActive,
+ setSuggestion,
+ getSuggestions,
} from '../../modules/geosearch/actions';
import {
areCoordinatesWithinExtent,
} from '../../modules/geosearch/selectors';
+import {
+ processMagicKey,
+ reverseGeocode,
+} from '../../modules/geosearch/util';
class Geosearch extends React.Component {
constructor(props) {
super(props);
this.state = {
inputValue: '',
- searchResults: [],
coordinatesPending: [],
};
}
@@ -32,9 +38,6 @@ class Geosearch extends React.Component {
// update input value
updateValue = (inputValue) => this.setState({ inputValue });
- // update list of suggested search results
- updateSearchResults = (searchResults) => this.setState({ searchResults });
-
// update array of pending coordinates
updatePendingCoordinates = (coordinatesPending) => this.setState({ coordinatesPending });
@@ -43,17 +46,21 @@ class Geosearch extends React.Component {
clearCoordinates,
coordinates,
geosearchMobileModalOpen,
+ getSuggestions,
isCoordinatePairWithinExtent,
isCoordinateSearchActive,
isExpanded,
+ processMagicKey,
+ reverseGeocode,
selectCoordinatesToFly,
+ setSuggestion,
+ suggestions,
toggleReverseGeocodeActive,
toggleShowGeosearch,
} = this.props;
const {
coordinatesPending,
inputValue,
- searchResults,
} = this.state;
return (
@@ -62,17 +69,20 @@ class Geosearch extends React.Component {
coordinates={coordinates}
coordinatesPending={coordinatesPending}
geosearchMobileModalOpen={geosearchMobileModalOpen}
+ getSuggestions={getSuggestions}
inputValue={inputValue}
isCoordinatePairWithinExtent={isCoordinatePairWithinExtent}
isCoordinateSearchActive={isCoordinateSearchActive}
isExpanded={isExpanded}
isMobile={isMobile}
- searchResults={searchResults}
+ processMagicKey={processMagicKey}
+ reverseGeocode={reverseGeocode}
selectCoordinatesToFly={selectCoordinatesToFly}
+ setSuggestion={setSuggestion}
+ suggestions={suggestions}
toggleReverseGeocodeActive={toggleReverseGeocodeActive}
toggleShowGeosearch={toggleShowGeosearch}
updatePendingCoordinates={this.updatePendingCoordinates}
- updateSearchResults={this.updateSearchResults}
updateValue={this.updateValue}
/>
);
@@ -111,10 +121,13 @@ const mapStateToProps = (state) => {
geosearch,
ui,
} = state;
- const { features: { geocodeSearch: isFeatureEnabled } } = config;
+ const { features: { geocodeSearch: { url: requestUrl } } } = config;
+ const isFeatureEnabled = !!requestUrl;
const { isActive } = measure;
const { gifActive } = animation;
- const { coordinates, isCoordinateSearchActive, isExpanded } = geosearch;
+ const {
+ coordinates, isCoordinateSearchActive, isExpanded, suggestions,
+ } = geosearch;
const { isDistractionFreeModeActive } = ui;
const isMobile = browser.lessThan.medium;
const snapshotModalOpen = modal.isOpen && modal.id === 'TOOLBAR_SNAPSHOT';
@@ -124,13 +137,16 @@ const mapStateToProps = (state) => {
return {
coordinates,
- isCoordinateSearchActive,
- isExpanded,
geosearchMobileModalOpen,
isCoordinatePairWithinExtent: (targetCoordinates) => areCoordinatesWithinExtent(map, config, targetCoordinates),
+ isCoordinateSearchActive,
+ isExpanded,
+ isFeatureEnabled,
isMobile,
+ processMagicKey: (magicKey) => processMagicKey(magicKey, config),
+ reverseGeocode: (coords) => reverseGeocode(coords, config),
shouldCollapseFromOtherUI,
- isFeatureEnabled,
+ suggestions,
};
};
@@ -147,19 +163,33 @@ const mapDispatchToProps = (dispatch) => ({
toggleShowGeosearch: () => {
dispatch(toggleShowGeosearch());
},
+ getSuggestions: (val) => {
+ dispatch(getSuggestions(val));
+ },
+ clearSuggestions: () => {
+ dispatch(clearSuggestions());
+ },
+ setSuggestion: (suggestion) => {
+ dispatch(setSuggestion(suggestion));
+ },
});
Geosearch.propTypes = {
- isCoordinatePairWithinExtent: PropTypes.func,
- isCoordinateSearchActive: PropTypes.bool,
- isFeatureEnabled: PropTypes.bool,
clearCoordinates: PropTypes.func,
coordinates: PropTypes.array,
geosearchMobileModalOpen: PropTypes.bool,
+ getSuggestions: PropTypes.func,
+ isCoordinatePairWithinExtent: PropTypes.func,
+ isCoordinateSearchActive: PropTypes.bool,
isExpanded: PropTypes.bool,
+ isFeatureEnabled: PropTypes.bool,
isMobile: PropTypes.bool,
+ processMagicKey: PropTypes.func,
+ reverseGeocode: PropTypes.func,
selectCoordinatesToFly: PropTypes.func,
+ setSuggestion: PropTypes.func,
shouldCollapseFromOtherUI: PropTypes.bool,
+ suggestions: PropTypes.array,
toggleReverseGeocodeActive: PropTypes.func,
toggleShowGeosearch: PropTypes.func,
};
diff --git a/web/js/components/geosearch/ol-coordinates-marker-util.js b/web/js/components/geosearch/ol-coordinates-marker-util.js
index d456fa44a..abd0488de 100644
--- a/web/js/components/geosearch/ol-coordinates-marker-util.js
+++ b/web/js/components/geosearch/ol-coordinates-marker-util.js
@@ -151,10 +151,10 @@ export const getCoordinatesMetadata = (geocodeProperties) => {
// build title based on available parameters
const title = getCoordinatesDialogTitle(address, error, formattedLatitude, formattedLongitude);
+ const coordinates = `${formattedLatitude.trim()}, ${formattedLongitude.trim()}`;
return {
- latitude: formattedLatitude.trim(),
- longitude: formattedLongitude.trim(),
+ coordinates,
title,
};
};
diff --git a/web/js/components/geosearch/ol-coordinates-marker.js b/web/js/components/geosearch/ol-coordinates-marker.js
index 59e46ceb7..091021d9f 100644
--- a/web/js/components/geosearch/ol-coordinates-marker.js
+++ b/web/js/components/geosearch/ol-coordinates-marker.js
@@ -10,7 +10,8 @@ import Alert from '../util/alert';
import { changeCursor as changeCursorActionCreator } from '../../modules/map/actions';
import { getCoordinatesDialogAtMapPixel } from './ol-coordinates-marker-util';
import { clearCoordinates, selectCoordinatesToFly, toggleReverseGeocodeActive } from '../../modules/geosearch/actions';
-import { areCoordinatesWithinExtent, reverseGeocode } from '../../modules/geosearch/selectors';
+import { areCoordinatesWithinExtent } from '../../modules/geosearch/selectors';
+import { reverseGeocode } from '../../modules/geosearch/util';
export class CoordinatesMarker extends Component {
constructor(props) {
@@ -109,7 +110,7 @@ export class CoordinatesMarker extends Component {
return;
}
// get available reverse geocoding for coordinates and fly to point
- reverseGeocode([longitude, latitude]).then((results) => {
+ reverseGeocode([longitude, latitude], config).then((results) => {
selectCoordinatesToFly([longitude, latitude], results);
});
this.setState({ showExtentAlert: false });
diff --git a/web/js/containers/share.js b/web/js/containers/share.js
index f3943d892..ff9ca5b70 100644
--- a/web/js/containers/share.js
+++ b/web/js/containers/share.js
@@ -234,8 +234,8 @@ function mapStateToProps(state) {
};
}
const mapDispatchToProps = (dispatch) => ({
- requestShortLink: (location, signal) => dispatch(
- requestShortLink(location, 'application/json', null, signal),
+ requestShortLink: (location, options) => dispatch(
+ requestShortLink(location, 'application/json', null, options),
),
});
diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.js
index a6cca4cad..210590f2d 100644
--- a/web/js/containers/toolbar.js
+++ b/web/js/containers/toolbar.js
@@ -213,10 +213,10 @@ class toolbarContainer extends Component {
shouldBeCollapsed,
toggleShowGeosearch,
} = this.props;
- const { features: { geocodeSearch: isFeatureEnabled } } = config;
+ const { features: { geocodeSearch: { url: requestUrl } } } = config;
const buttonId = 'wv-geosearch-button';
const labelText = 'Search places by location';
-
+ const isFeatureEnabled = !!requestUrl;
// do not render if geosearch feature isn't enabled
if (!isFeatureEnabled) {
return null;
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index b9ef6eeeb..0cee4b945 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -55,7 +55,8 @@ import { getLeadingExtent } from '../modules/map/util';
import { updateVectorSelection } from '../modules/vector-styles/util';
import { faIconPlusSVGDomEl, faIconMinusSVGDomEl } from './fa-map-icons';
import { hasVectorLayers } from '../modules/layers/util';
-import { addCoordinatesMarker, reverseGeocode, removeCoordinatesMarker } from '../modules/geosearch/selectors';
+import { addCoordinatesMarker, removeCoordinatesMarker } from '../modules/geosearch/selectors';
+import { reverseGeocode } from '../modules/geosearch/util';
import { getCoordinatesMetadata, renderCoordinatesTooltip } from '../components/geosearch/ol-coordinates-marker-util';
export default function mapui(models, config, store, ui) {
@@ -212,7 +213,7 @@ export default function mapui(models, config, store, ui) {
const { geosearch } = state;
const { activeMarker, coordinates } = geosearch;
if (coordinates && coordinates.length > 0) {
- reverseGeocode(coordinates).then((results) => {
+ reverseGeocode(coordinates, config).then((results) => {
addMarkerAndUpdateStore(activeMarker, coordinates, results);
});
}
diff --git a/web/js/modules/core/actions.js b/web/js/modules/core/actions.js
index 25454b940..d5960f145 100644
--- a/web/js/modules/core/actions.js
+++ b/web/js/modules/core/actions.js
@@ -4,12 +4,12 @@ export function requestAction(
url,
mimeType,
id,
- signal,
+ options,
TIMEOUT_AMOUNT,
) {
// let didTimeOut = false;
dispatch(startRequest(actionName, id));
- return new Promise((resolve, reject) => fetch(url, { signal })
+ return new Promise((resolve, reject) => fetch(url, options)
.then((response) => (mimeType === 'application/json'
? response.json()
: response.text()
diff --git a/web/js/modules/geosearch/actions.js b/web/js/modules/geosearch/actions.js
index 185777d86..9f6842e56 100644
--- a/web/js/modules/geosearch/actions.js
+++ b/web/js/modules/geosearch/actions.js
@@ -1,7 +1,9 @@
import {
CLEAR_COORDINATES,
+ CLEAR_SUGGESTIONS,
SELECT_COORDINATES_TO_FLY,
+ SET_SUGGESTION,
TOGGLE_REVERSE_GEOCODE_ACTIVE,
TOGGLE_SHOW_GEOSEARCH,
} from './constants';
@@ -11,8 +13,12 @@ import {
removeCoordinatesMarker,
} from './selectors';
import { getMaxZoomLevelLayerCollection } from '../layers/selectors';
-import { setLocalStorageCollapseState } from './util';
+import {
+ GEOSEARCH_REQUEST_OPTIONS,
+ setLocalStorageCollapseState,
+} from './util';
import { getCoordinatesMetadata, renderCoordinatesTooltip } from '../../components/geosearch/ol-coordinates-marker-util';
+import { requestAction } from '../core/actions';
// toggle show geosearch component
export function toggleShowGeosearch() {
@@ -117,3 +123,46 @@ export function clearCoordinates() {
});
};
}
+
+export function clearSuggestions() {
+ return (dispatch) => {
+ dispatch({
+ type: CLEAR_SUGGESTIONS,
+ });
+ };
+}
+
+export function setSuggestion(suggestion) {
+ return (dispatch) => {
+ dispatch({
+ type: SET_SUGGESTION,
+ value: suggestion,
+ });
+ };
+}
+
+const {
+ REQUEST_OPTIONS,
+ GEOCODE_SUGGEST_CATEGORIES,
+ CONSTANT_REQUEST_PARAMETERS,
+} = GEOSEARCH_REQUEST_OPTIONS;
+
+export function getSuggestions(val) {
+ return (dispatch, getState) => {
+ const { config } = getState();
+ const { features: { geocodeSearch: { url: requestUrl } } } = config;
+
+ const encodedValue = encodeURIComponent(val);
+ const encodedCategories = encodeURIComponent(GEOCODE_SUGGEST_CATEGORIES.join(','));
+ const request = `${requestUrl}suggest?text=${encodedValue}${CONSTANT_REQUEST_PARAMETERS}&category=${encodedCategories}`;
+
+ return requestAction(
+ dispatch,
+ 'GEOSEARCH/REQUEST_SUGGEST_PLACE',
+ request,
+ '',
+ 'geosearch-suggest-place',
+ REQUEST_OPTIONS,
+ );
+ };
+}
diff --git a/web/js/modules/geosearch/constants.js b/web/js/modules/geosearch/constants.js
index 73a82b060..d46c16dff 100644
--- a/web/js/modules/geosearch/constants.js
+++ b/web/js/modules/geosearch/constants.js
@@ -1,5 +1,9 @@
export const CLEAR_COORDINATES = 'GEOSEARCH/CLEAR_COORDINATES';
+export const CLEAR_SUGGESTIONS = 'GEOSEARCH/CLEAR_SUGGESTIONS';
+export const REQUEST_SUGGEST_PLACE_FAILURE = 'GEOSEARCH/REQUEST_SUGGEST_PLACE_FAILURE';
+export const REQUEST_SUGGEST_PLACE_SUCCESS = 'GEOSEARCH/REQUEST_SUGGEST_PLACE_SUCCESS';
export const SELECT_COORDINATES_TO_FLY = 'GEOSEARCH/SELECT_COORDINATES_TO_FLY';
+export const SET_SUGGESTION = 'GEOSEARCH/SET_SUGGESTION';
export const TOGGLE_REVERSE_GEOCODE_ACTIVE = 'GEOSEARCH/TOGGLE_REVERSE_GEOCODE_ACTIVE';
export const TOGGLE_SHOW_GEOSEARCH = 'GEOSEARCH/TOGGLE_SHOW_GEOSEARCH';
export const UPDATE_ACTIVE_MARKER = 'GEOSEARCH/UPDATE_ACTIVE_MARKER';
diff --git a/web/js/modules/geosearch/reducers.js b/web/js/modules/geosearch/reducers.js
index eda00fbf2..87418ce6b 100644
--- a/web/js/modules/geosearch/reducers.js
+++ b/web/js/modules/geosearch/reducers.js
@@ -1,6 +1,10 @@
import {
CLEAR_COORDINATES,
+ CLEAR_SUGGESTIONS,
+ REQUEST_SUGGEST_PLACE_FAILURE,
+ REQUEST_SUGGEST_PLACE_SUCCESS,
SELECT_COORDINATES_TO_FLY,
+ SET_SUGGESTION,
TOGGLE_REVERSE_GEOCODE_ACTIVE,
TOGGLE_SHOW_GEOSEARCH,
UPDATE_ACTIVE_MARKER,
@@ -9,11 +13,12 @@ import { getLocalStorageCollapseState } from './util';
const localStorageCollapseState = getLocalStorageCollapseState();
export const geosearchState = {
+ activeMarker: null,
+ coordinates: [],
isCoordinateSearchActive: false,
isExpanded: !localStorageCollapseState,
- coordinates: [],
- activeMarker: null,
reverseGeocodeResults: null,
+ suggestions: [],
};
export function geosearchReducer(state = geosearchState, action) {
@@ -49,6 +54,26 @@ export function geosearchReducer(state = geosearchState, action) {
...state,
isCoordinateSearchActive: action.value,
};
+ case CLEAR_SUGGESTIONS:
+ return {
+ ...state,
+ suggestions: [],
+ };
+ case SET_SUGGESTION:
+ return {
+ ...state,
+ suggestions: action.value,
+ };
+ case REQUEST_SUGGEST_PLACE_SUCCESS:
+ return {
+ ...state,
+ suggestions: JSON.parse(action.response).suggestions,
+ };
+ case REQUEST_SUGGEST_PLACE_FAILURE:
+ return {
+ ...state,
+ suggestions: [],
+ };
default:
return state;
}
diff --git a/web/js/modules/geosearch/selectors.js b/web/js/modules/geosearch/selectors.js
index 6892bd132..d25c978d5 100644
--- a/web/js/modules/geosearch/selectors.js
+++ b/web/js/modules/geosearch/selectors.js
@@ -128,73 +128,3 @@ const createPin = function(coordinates, transformedCoordinates = false, reverseG
return vectorLayer;
};
-
-// ArcGIS World Geocoding Service API Requests and Options
-const GEOCODE_OPTIONS = {
- urlBase: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/',
- requestOptions: {
- method: 'GET',
- redirect: 'follow',
- },
-};
-// language code EN (English) and required f request format parameters
-const constantRequestParameters = '&langCode=en&f=json';
-
-// https://developers.arcgis.com/rest/geocode/api-reference/geocoding-category-filtering.htm
-// necessary to filter to remove fast food type suggestions, but still include relavant Places of Interest
-const GEOCODE_SUGGEST_CATEGORIES = [
- 'Address',
- 'Street Address',
- 'Populated Place',
- 'Education',
- 'Land Features',
- 'Water Features',
- 'Museum',
- 'Tourist Attraction',
- 'Scientific Research',
- 'Government Office',
- 'Business Facility',
- 'Primary Postal',
- 'Airport',
-];
-
-export async function suggest(val) {
- const { requestOptions, urlBase } = GEOCODE_OPTIONS;
- const encodedValue = encodeURIComponent(val);
- const encodedCategories = encodeURIComponent(GEOCODE_SUGGEST_CATEGORIES.join(','));
- const request = `${urlBase}suggest?text=${encodedValue}${constantRequestParameters}&category=${encodedCategories}`;
-
- try {
- const response = await fetch(request, requestOptions);
- const result = await response.text();
- return JSON.parse(result);
- } catch (error) {
- return console.log('error', error);
- }
-}
-
-export async function processMagicKey(magicKey) {
- const { requestOptions, urlBase } = GEOCODE_OPTIONS;
- const request = `${urlBase}findAddressCandidates?outFields=*${constantRequestParameters}&magicKey=${magicKey}=`;
-
- try {
- const response = await fetch(request, requestOptions);
- const result = await response.text();
- return JSON.parse(result);
- } catch (error) {
- return console.log('error', error);
- }
-}
-
-export async function reverseGeocode(coordinates) {
- const { requestOptions, urlBase } = GEOCODE_OPTIONS;
- const request = `${urlBase}reverseGeocode?location=${coordinates}${constantRequestParameters}`;
-
- try {
- const response = await fetch(request, requestOptions);
- const result = await response.text();
- return JSON.parse(result);
- } catch (error) {
- return console.log('error', error);
- }
-}
diff --git a/web/js/modules/geosearch/util.js b/web/js/modules/geosearch/util.js
index c8e94fae5..a640ea24f 100644
--- a/web/js/modules/geosearch/util.js
+++ b/web/js/modules/geosearch/util.js
@@ -2,6 +2,65 @@ import update from 'immutability-helper';
import safeLocalStorage from '../../util/local-storage';
const { GEOSEARCH_COLLAPSED } = safeLocalStorage.keys;
+
+// ArcGIS World Geocoding Service API Request Options
+export const GEOSEARCH_REQUEST_OPTIONS = {
+ REQUEST_OPTIONS: {
+ method: 'GET',
+ redirect: 'follow',
+ },
+ // https://developers.arcgis.com/rest/geocode/api-reference/geocoding-category-filtering.htm
+ // necessary to filter to remove fast food type suggestions, but still include relavant Places of Interest
+ GEOCODE_SUGGEST_CATEGORIES: [
+ 'Address',
+ 'Street Address',
+ 'Populated Place',
+ 'Education',
+ 'Land Features',
+ 'Water Features',
+ 'Museum',
+ 'Tourist Attraction',
+ 'Scientific Research',
+ 'Government Office',
+ 'Business Facility',
+ 'Primary Postal',
+ 'Airport',
+ ],
+ // language code EN (English) and required f request format parameters
+ CONSTANT_REQUEST_PARAMETERS: '&langCode=en&f=json',
+};
+
+const {
+ REQUEST_OPTIONS,
+ CONSTANT_REQUEST_PARAMETERS,
+} = GEOSEARCH_REQUEST_OPTIONS;
+
+export async function processMagicKey(magicKey, config) {
+ const { features: { geocodeSearch: { url: requestUrl } } } = config;
+ const request = `${requestUrl}findAddressCandidates?outFields=*${CONSTANT_REQUEST_PARAMETERS}&magicKey=${magicKey}=`;
+
+ try {
+ const response = await fetch(request, REQUEST_OPTIONS);
+ const result = await response.text();
+ return JSON.parse(result);
+ } catch (error) {
+ return console.log('error', error);
+ }
+}
+
+export async function reverseGeocode(coordinates, config) {
+ const { features: { geocodeSearch: { url: requestUrl } } } = config;
+ const request = `${requestUrl}reverseGeocode?location=${coordinates}${CONSTANT_REQUEST_PARAMETERS}`;
+
+ try {
+ const response = await fetch(request, REQUEST_OPTIONS);
+ const result = await response.text();
+ return JSON.parse(result);
+ } catch (error) {
+ return console.log('error', error);
+ }
+}
+
/**
*
* @param {*} parameters
diff --git a/web/js/modules/link/actions.js b/web/js/modules/link/actions.js
index 6878b301f..f93aca087 100644
--- a/web/js/modules/link/actions.js
+++ b/web/js/modules/link/actions.js
@@ -7,13 +7,13 @@ export function updatePermalink(queryString) {
queryString,
};
}
-export function requestShortLink(location, type, signal) {
+export function requestShortLink(location, type, options) {
return (dispatch) => requestAction(
dispatch,
REQUEST_SHORT_LINK,
location,
type,
null, // id
- signal,
+ options,
);
}