Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add geosearch actions and reducers tests

Ed Plato8d22d5c96b7a
diff --git a/e2e/features/compare/compare-test.js b/e2e/features/compare/compare-test.js
index b98ba6af7..324c41009 100644
--- a/e2e/features/compare/compare-test.js
+++ b/e2e/features/compare/compare-test.js
@@ -18,9 +18,16 @@ module.exports = {
reuseables.loadAndSkipTour(c, TIME_LIMIT);
},
// load A|B and verify that it is active
+<<<<<<< HEAD
'A|B is loaded': (c) => {
c.url(c.globals.url + localQuerystrings.swipeAndAIsActive);
c.waitForElementVisible(localSelectors.swipeDragger, TIME_LIMIT);
+=======
+ 'A|B is loaded': function(client) {
+ client.url(client.globals.url + localQuerystrings.swipeAndAIsActive);
+ client.waitForElementVisible(localSelectors.swipeDragger, TIME_LIMIT);
+ client.pause(1000);
+>>>>>>> 6001fb02e (add delay for compare test, add class back to measure tooltip for tests)
},
'Animation is disabled when compare mode active': (c) => {
diff --git a/e2e/features/geosearch/geosearch-mobile-test.js b/e2e/features/geosearch/geosearch-mobile-test.js
new file mode 100644
index 000000000..74e7d664b
--- /dev/null
+++ b/e2e/features/geosearch/geosearch-mobile-test.js
@@ -0,0 +1,30 @@
+const reuseables = require('../../reuseables/skip-tour.js');
+const localSelectors = require('../../reuseables/selectors.js');
+
+const TIME_LIMIT = 10000;
+
+const {
+ geosearchToolbarButton,
+ geosearchMobileDialog,
+} = localSelectors;
+
+module.exports = {
+ before(client) {
+ reuseables.loadAndSkipTour(client, TIME_LIMIT);
+ client.resizeWindow(375, 667); // iPhone 6/7/8 dimensions
+ client.pause(300);
+ },
+ 'Geosearch mobile dialog is not visible by default': (client) => {
+ client.waitForElementVisible(geosearchToolbarButton, TIME_LIMIT);
+ client.expect.element(geosearchMobileDialog).to.not.be.present;
+ },
+ 'Clicking geosearch toolbar button opens the geosearch mobile dialog': (client) => {
+ client.waitForElementVisible(geosearchToolbarButton, TIME_LIMIT);
+ client.click(geosearchToolbarButton);
+ client.pause(500);
+ client.expect.element(geosearchMobileDialog).to.be.present;
+ },
+ after(client) {
+ client.end();
+ },
+};
diff --git a/e2e/features/geosearch/geosearch-test.js b/e2e/features/geosearch/geosearch-test.js
new file mode 100644
index 000000000..e945f334b
--- /dev/null
+++ b/e2e/features/geosearch/geosearch-test.js
@@ -0,0 +1,35 @@
+const reuseables = require('../../reuseables/skip-tour.js');
+const localSelectors = require('../../reuseables/selectors.js');
+
+const TIME_LIMIT = 10000;
+
+const {
+ geosearchToolbarButton,
+ geosearchComponent,
+ geosearchMinimizeButton,
+} = localSelectors;
+
+module.exports = {
+ before(client) {
+ reuseables.loadAndSkipTour(client, TIME_LIMIT);
+ },
+ 'Geosearch component is visible by default': (client) => {
+ client.waitForElementVisible(geosearchComponent, TIME_LIMIT);
+ client.expect.element(geosearchComponent).to.be.present;
+ },
+ 'Clicking the minimize button minimizes the geosearch component': (client) => {
+ client.waitForElementVisible(geosearchComponent, TIME_LIMIT);
+ client.click(geosearchMinimizeButton);
+ client.pause(500);
+ client.expect.element(geosearchComponent).to.not.be.present;
+ },
+ 'Clicking geosearch toolbar button expands the geosearch component': (client) => {
+ client.waitForElementVisible(geosearchToolbarButton, TIME_LIMIT);
+ client.click(geosearchToolbarButton);
+ client.pause(500);
+ client.expect.element(geosearchComponent).to.be.present;
+ },
+ after(client) {
+ client.end();
+ },
+};
diff --git a/e2e/reuseables/selectors.js b/e2e/reuseables/selectors.js
index 389454d32..2f1d08fa3 100644
--- a/e2e/reuseables/selectors.js
+++ b/e2e/reuseables/selectors.js
@@ -122,4 +122,10 @@ module.exports = {
socialToolbar: '#toolbar_share_link',
socialCopyLinkButton: '#wv-link-button',
socialLinkInput: '#permalink_content',
+
+ // geosearch
+ geosearchToolbarButton: '#wv-geosearch-button',
+ geosearchComponent: '.geosearch-component',
+ geosearchMobileDialog: '#toolbar_geosearch_mobile',
+ geosearchMinimizeButton: '.geosearch-search-minimize-button',
};
diff --git a/web/css/geosearch.css b/web/css/geosearch.css
index 828500635..690b1a403 100644
--- a/web/css/geosearch.css
+++ b/web/css/geosearch.css
@@ -19,6 +19,7 @@
}
.geosearch-item {
+ word-wrap: break-word;
padding: 5px 0 5px 7px;
color: #333;
&:hover {
diff --git a/web/css/tooltip.css b/web/css/tooltip.css
index 8d428ee56..8d4610a03 100644
--- a/web/css/tooltip.css
+++ b/web/css/tooltip.css
@@ -120,7 +120,13 @@
&.tooltip-static::before {
border-top-color: #000;
}
+ &.tooltip-coordinates-container {
+ max-width: 320px;
+ }
.tooltip-coordinates-title {
+ white-space: pre-wrap;
+ word-wrap: break-word;
+ line-height: 17px;
font-size: 16px;
padding-right: 23px;
}
@@ -135,7 +141,7 @@
margin-left: 8px;
border-left: 1px solid #777;
padding-left: 6px;
- &.coordinates-dialog-close {
+ &.close-coordinates-tooltip {
position: absolute;
top: 4px;
right: 6px;
diff --git a/web/images/b.png b/web/images/b.png
deleted file mode 100644
index 33e608b0c..000000000
Binary files a/web/images/b.png and /dev/null differ
diff --git a/web/images/o1.png b/web/images/o1.png
deleted file mode 100644
index d0d604da9..000000000
Binary files a/web/images/o1.png and /dev/null differ
diff --git a/web/images/o3.png b/web/images/o3.png
deleted file mode 100644
index a00c71fcb..000000000
Binary files a/web/images/o3.png and /dev/null differ
diff --git a/web/images/y.png b/web/images/y.png
deleted file mode 100644
index 6ec75b1d8..000000000
Binary files a/web/images/y.png and /dev/null differ
diff --git a/web/js/app.js b/web/js/app.js
index 34f0758aa..c8493152a 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -246,7 +246,6 @@ export default connect(
mapDispatchToProps,
)(App);
App.propTypes = {
- // config: PropTypes.object,
isAnimationWidgetActive: PropTypes.bool,
isMobile: PropTypes.bool,
isTourActive: PropTypes.bool,
diff --git a/web/js/components/geosearch/coordinates-dialog.js b/web/js/components/geosearch/coordinates-dialog.js
index c7caa5d9e..24f9b18d7 100644
--- a/web/js/components/geosearch/coordinates-dialog.js
+++ b/web/js/components/geosearch/coordinates-dialog.js
@@ -18,7 +18,7 @@ class CoordinatesDialog extends PureComponent {
const latitudeText = `Latitude: ${features.latitude} °`;
const longitudeText = `Longitude: ${features.longitude} °`;
return (
- <div className="tooltip-custom-black tooltip-static">
+ <div className="tooltip-custom-black tooltip-static tooltip-coordinates-container">
<div className="tooltip-coordinates-title">{title}</div>
<div className="tooltip-coordinates-group">
<div>
@@ -28,7 +28,7 @@ class CoordinatesDialog extends PureComponent {
{longitudeText}
</div>
</div>
- <span className="close-tooltip coordinates-dialog-close" onClick={toggleWithClose}>
+ <span className="close-tooltip close-coordinates-tooltip" onClick={toggleWithClose}>
<FontAwesomeIcon icon={faTimes} fixedWidth />
</span>
</div>
diff --git a/web/js/components/geosearch/geosearch-helpers.js b/web/js/components/geosearch/geosearch-helpers.js
deleted file mode 100644
index 30500e40c..000000000
--- a/web/js/components/geosearch/geosearch-helpers.js
+++ /dev/null
@@ -1,103 +0,0 @@
-import safeLocalStorage from '../../util/local-storage';
-
-const { SEARCH_TOKEN } = safeLocalStorage.keys;
-
-export function getTokenDataFromStorage() {
- const tokenData = safeLocalStorage.getItem(SEARCH_TOKEN);
- if (tokenData) {
- return JSON.parse(tokenData);
- }
- return {};
-}
-
-export function getTokenFromStorage() {
- const tokenData = getTokenDataFromStorage();
- return tokenData.token;
-}
-
-function getTokenExpiryFromStorage() {
- const tokenData = getTokenDataFromStorage();
- return tokenData.expires;
-}
-
-export function isTokenExpired() {
- const time = Date.now();
- const expires = getTokenExpiryFromStorage();
- if (!expires) {
- return true;
- }
- return expires <= time;
-}
-
-function setTokenDataToStorage(tokenData) {
- safeLocalStorage.setItem(SEARCH_TOKEN, JSON.stringify(tokenData));
-}
-
-export function setTokenFromStorage() {
- return fetchToken().then((result) => {
- const req = JSON.parse(result);
- const expires = Date.now() + req.expires_in * 1000; // 7200 -> 7200000 -or- 2 hours
- const tokenData = {
- expires,
- token: req.access_token,
- };
- return tokenData;
- }).then((tokenData) => new Promise((resolve) => setTimeout(() => resolve(tokenData), 8000)))
- .then((tokenData) => {
- setTokenDataToStorage(tokenData);
- return tokenData;
- });
-}
-
-export function fetchTokenData() {
- const y = setTokenFromStorage();
- return {
- token: wrapPromise(y),
- };
-}
-
-// Suspense integrations like Relay implement
-// a contract like this to integrate with React.
-// Real implementations can be significantly more complex.
-// Don't copy-paste this into your project!
-function wrapPromise(promise) {
- let status = 'pending';
- let result;
- const suspender = promise.then(
- (r) => {
- status = 'success';
- result = r;
- },
- (e) => {
- status = 'error';
- result = e;
- },
- );
- return {
- read() {
- if (status === 'pending') {
- throw suspender;
- } else if (status === 'error') {
- throw result;
- } else if (status === 'success') {
- return result;
- }
- },
- };
-}
-
-// TODO: ADD ENV VARIABLES FOR CLIENT ID, CLIENT SECRET
-const formdata = new FormData();
-
-const requestOptions = {
- method: 'POST',
- body: formdata,
- redirect: 'follow',
-};
-
-function fetchToken() {
- return fetch('https://www.arcgis.com/sharing/rest/oauth2/token', requestOptions)
- .then((response) => response.text())
- .then((result) => result)
- .catch((error) => console.log('error', error));
-}
diff --git a/web/js/components/geosearch/geosearch-input.js b/web/js/components/geosearch/geosearch-input.js
index 91847df91..b2e066399 100644
--- a/web/js/components/geosearch/geosearch-input.js
+++ b/web/js/components/geosearch/geosearch-input.js
@@ -11,6 +11,7 @@ class SearchBox extends Component {
this.state = {
};
this.highlightedItem = null;
+ this.geosearchInput = null;
}
componentDidMount() {
@@ -18,7 +19,9 @@ class SearchBox extends Component {
// timeout necessary to trigger input focus
if (isExpanded || geosearchMobileModalOpen) {
setTimeout(() => {
- this.geosearchInput.focus();
+ if (this.geosearchInput) {
+ this.geosearchInput.focus();
+ }
}, 1);
}
}
diff --git a/web/js/components/geosearch/geosearch-modal.js b/web/js/components/geosearch/geosearch-modal.js
index 32439fc54..761a8cf01 100644
--- a/web/js/components/geosearch/geosearch-modal.js
+++ b/web/js/components/geosearch/geosearch-modal.js
@@ -55,19 +55,19 @@ class SearchComponent extends Component {
// handle submitting search after inputing coordinates
onCoordinateInputSelect = () => {
- const { handleSelectCordinatesToFly } = this.props;
+ const { selectCoordinatesToFly } = this.props;
const { coordinatesPending } = this.state;
const [longitude, latitude] = coordinatesPending;
reverseGeocode([longitude, latitude]).then((results) => {
- handleSelectCordinatesToFly([longitude, latitude], results);
+ selectCoordinatesToFly([longitude, latitude], results);
});
this.updatePendingCoordinates([]);
}
// handle selecting menu item in search results
onSelect=(value, item) => {
- const { handleSelectCordinatesToFly } = this.props;
+ const { selectCoordinatesToFly } = this.props;
this.updateSearchResults([item]);
this.updateValue(value);
@@ -85,7 +85,7 @@ class SearchComponent extends Component {
const { x, y } = location;
const parsedX = parseFloat(x.toPrecision(9));
const parsedY = parseFloat(y.toPrecision(9));
- handleSelectCordinatesToFly([parsedX, parsedY], addressAttributes);
+ selectCoordinatesToFly([parsedX, parsedY], addressAttributes);
}
});
}
@@ -120,12 +120,12 @@ class SearchComponent extends Component {
}
}
- // initiate instruction alert and activate store level handleReverseGeocodeActive
+ // initiate instruction alert and activate store level toggleReverseGeocodeActive
selectCoordinatesFromMap = (e) => {
e.preventDefault();
const isTouchDevice = e.type === 'touchend';
- const { handleReverseGeocodeActive } = this.props;
- handleReverseGeocodeActive(true);
+ const { toggleReverseGeocodeActive } = this.props;
+ toggleReverseGeocodeActive(true);
this.setState({
isTouchDevice,
showAlert: true,
@@ -137,8 +137,8 @@ class SearchComponent extends Component {
clearCoordinatesMarker = (e) => {
e.preventDefault();
e.stopPropagation();
- const { handleClearCoordinatesClick } = this.props;
- handleClearCoordinatesClick();
+ const { clearCoordinates } = this.props;
+ clearCoordinates();
}
render() {
@@ -238,13 +238,13 @@ class SearchComponent extends Component {
}
SearchComponent.propTypes = {
- handleClearCoordinatesClick: PropTypes.func,
+ clearCoordinates: PropTypes.func,
coordinates: PropTypes.array,
geosearchMobileModalOpen: PropTypes.bool,
isExpanded: PropTypes.bool,
isMobile: PropTypes.bool,
- handleSelectCordinatesToFly: PropTypes.func,
- handleReverseGeocodeActive: PropTypes.func,
+ selectCoordinatesToFly: PropTypes.func,
+ toggleReverseGeocodeActive: PropTypes.func,
toggleShowGeosearch: PropTypes.func,
};
diff --git a/web/js/components/geosearch/geosearch.js b/web/js/components/geosearch/geosearch.js
index fec8f52ea..8e126ef58 100644
--- a/web/js/components/geosearch/geosearch.js
+++ b/web/js/components/geosearch/geosearch.js
@@ -9,9 +9,6 @@ import {
toggleShowGeosearch,
toggleReverseGeocodeActive,
} from '../../modules/geosearch/actions';
-import {
- onToggle,
-} from '../../modules/modal/actions';
class Geosearch extends React.Component {
constructor(props) {
@@ -27,35 +24,14 @@ class Geosearch extends React.Component {
}
}
- handleClearCoordinatesClick = () => {
- const { clearCoordinates, coordinatesDialogOpen, onToggle } = this.props;
- if (coordinatesDialogOpen) {
- onToggle();
- }
- clearCoordinates();
- }
-
- handleSelectCordinatesToFly = (coordinates, addressAttributes) => {
- const { selectCoordinatesToFly, coordinatesDialogOpen, onToggle } = this.props;
- if (coordinatesDialogOpen) {
- onToggle();
- }
- selectCoordinatesToFly(coordinates, addressAttributes);
- }
-
- handleReverseGeocodeActive = (isActive) => {
- const { toggleReverseGeocodeActive, coordinatesDialogOpen, onToggle } = this.props;
- if (coordinatesDialogOpen) {
- onToggle();
- }
- toggleReverseGeocodeActive(isActive);
- }
-
renderSearchComponent = (isMobile) => {
const {
+ clearCoordinates,
coordinates,
geosearchMobileModalOpen,
isExpanded,
+ selectCoordinatesToFly,
+ toggleReverseGeocodeActive,
toggleShowGeosearch,
} = this.props;
@@ -65,9 +41,9 @@ class Geosearch extends React.Component {
geosearchMobileModalOpen={geosearchMobileModalOpen}
isExpanded={isExpanded}
isMobile={isMobile}
- handleClearCoordinatesClick={this.handleClearCoordinatesClick}
- handleSelectCordinatesToFly={this.handleSelectCordinatesToFly}
- handleReverseGeocodeActive={this.handleReverseGeocodeActive}
+ clearCoordinates={clearCoordinates}
+ selectCoordinatesToFly={selectCoordinatesToFly}
+ toggleReverseGeocodeActive={toggleReverseGeocodeActive}
toggleShowGeosearch={toggleShowGeosearch}
/>
);
@@ -75,22 +51,21 @@ class Geosearch extends React.Component {
render() {
const {
- isDistractionFreeModeActive,
isExpanded,
isFeatureEnabled,
isMobile,
- shouldBeCollapsed,
+ shouldCollapseFromOtherUI,
} = this.props;
if (!isFeatureEnabled) {
return null;
}
- const shouldShowComponent = isExpanded && !shouldBeCollapsed && !isDistractionFreeModeActive;
+ const shouldShowComponent = isExpanded && !shouldCollapseFromOtherUI;
return (
<>
{isMobile
? this.renderSearchComponent(true)
- : shouldShowComponent && this.renderSearchComponent()}
+ : shouldShowComponent && this.renderSearchComponent(false)}
</>
);
}
@@ -107,41 +82,38 @@ const mapStateToProps = (state) => {
ui,
} = state;
const { features: { geocodeSearch: isFeatureEnabled } } = config;
+ const { isActive } = measure;
+ const { gifActive } = animation;
const { coordinates, isExpanded } = geosearch;
const { isDistractionFreeModeActive } = ui;
const isMobile = browser.lessThan.medium;
const snapshotModalOpen = modal.isOpen && modal.id === 'TOOLBAR_SNAPSHOT';
const geosearchMobileModalOpen = modal.isOpen && modal.id === 'TOOLBAR_GEOSEARCH_MOBILE';
- const coordinatesDialogOpen = modal.isOpen && modal.id.includes('COORDINATES_VECTOR_DIALOG');
- // Collapse when Image download / GIF / is open or measure tool active
- const shouldBeCollapsed = snapshotModalOpen || measure.isActive || animation.gifActive;
+ // Collapse when image download, GIF, measure tool, or distraction free mode is active
+ const shouldCollapseFromOtherUI = snapshotModalOpen || isActive || gifActive || isDistractionFreeModeActive;
return {
coordinates,
isExpanded,
- coordinatesDialogOpen,
geosearchMobileModalOpen,
isMobile,
- shouldBeCollapsed,
+ shouldCollapseFromOtherUI,
isFeatureEnabled,
- isDistractionFreeModeActive,
};
};
+
const mapDispatchToProps = (dispatch) => ({
- selectCoordinatesToFly: (coordinates, addressAttributes) => {
- dispatch(selectCoordinatesToFly(coordinates, addressAttributes));
- },
- toggleShowGeosearch: () => {
- dispatch(toggleShowGeosearch());
- },
clearCoordinates: () => {
dispatch(clearCoordinates());
},
+ selectCoordinatesToFly: (coordinates, addressAttributes) => {
+ dispatch(selectCoordinatesToFly(coordinates, addressAttributes));
+ },
toggleReverseGeocodeActive: (isActive) => {
dispatch(toggleReverseGeocodeActive(isActive));
},
- onToggle: () => {
- dispatch(onToggle());
+ toggleShowGeosearch: () => {
+ dispatch(toggleShowGeosearch());
},
});
@@ -149,14 +121,11 @@ Geosearch.propTypes = {
isFeatureEnabled: PropTypes.bool,
clearCoordinates: PropTypes.func,
coordinates: PropTypes.array,
- coordinatesDialogOpen: PropTypes.bool,
geosearchMobileModalOpen: PropTypes.bool,
isExpanded: PropTypes.bool,
- isDistractionFreeModeActive: PropTypes.bool,
isMobile: PropTypes.bool,
- onToggle: PropTypes.func,
selectCoordinatesToFly: PropTypes.func,
- shouldBeCollapsed: PropTypes.bool,
+ shouldCollapseFromOtherUI: PropTypes.bool,
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 cac6578b9..62da61607 100644
--- a/web/js/components/geosearch/ol-coordinates-marker-util.js
+++ b/web/js/components/geosearch/ol-coordinates-marker-util.js
@@ -4,7 +4,7 @@ import Overlay from 'ol/Overlay';
import React from 'react';
import ReactDOM from 'react-dom';
import CoordinatesDialog from './coordinates-dialog';
-import { polarCoordinatesTransform } from '../../modules/geosearch/selectors';
+import { coordinatesCRSTransform } from '../../modules/projection/util';
/**
* Get parsed precision coordinate number
@@ -31,13 +31,15 @@ function getCoordinateDisplayPrecision(coordinate) {
*
* @returns {Void}
*/
-function renderTooltip(map, coordinates, coordinatesMetadata) {
+function renderTooltip(map, config, coordinates, coordinatesMetadata) {
+ const { projections } = config;
const { proj } = map;
+ const { crs } = projections[proj];
const [latitude, longitude] = coordinates;
// create tooltip overlay
const tooltipElement = document.createElement('div');
- const tooltipId = `coordinates-map-maker-${latitude},${longitude}`;
+ const tooltipId = `coordinates-map-marker-${latitude},${longitude}`;
const tooltipOverlay = new Overlay({
id: tooltipId,
element: tooltipElement,
@@ -51,8 +53,7 @@ function renderTooltip(map, coordinates, coordinatesMetadata) {
if (proj === 'geographic') {
coordinatesPosition = [longitude, latitude];
} else {
- const transformedCoordinates = polarCoordinatesTransform([longitude, latitude], map.proj);
- coordinatesPosition = transformedCoordinates;
+ coordinatesPosition = coordinatesCRSTransform([longitude, latitude], 'EPSG:4326', crs);
}
// add tooltip overlay to map and position based on marker coordinates
@@ -80,12 +81,12 @@ function renderTooltip(map, coordinates, coordinatesMetadata) {
*
* @returns {Void}
*/
-export default function getCoordinatesDialogAtMapPixel(pixels, map) {
+export default function getCoordinatesDialogAtMapPixel(pixels, map, config) {
// check for existing coordinate marker tooltip overlay and prevent multiple renders
const mapOverlays = map.getOverlays().getArray();
const coordinatesTooltipOverlay = mapOverlays.filter((overlay) => {
const { id } = overlay;
- return id && id.contains('coordinates-map-maker');
+ return id && id.includes('coordinates-map-marker');
});
if (coordinatesTooltipOverlay.length > 0) {
return;
@@ -93,7 +94,7 @@ export default function getCoordinatesDialogAtMapPixel(pixels, map) {
map.forEachFeatureAtPixel(pixels, (feature) => {
const featureId = feature.getId();
- if (featureId === 'coordinates-map-maker') {
+ if (featureId === 'coordinates-map-marker') {
const featureProperties = feature.getProperties();
const { latitude, longitude, reverseGeocodeResults } = featureProperties;
@@ -132,7 +133,7 @@ export default function getCoordinatesDialogAtMapPixel(pixels, map) {
};
// create tooltip overlay React DOM element
- renderTooltip(map, [latitude, longitude], coordinatesMetadata);
+ renderTooltip(map, config, [latitude, longitude], coordinatesMetadata);
}
});
}
diff --git a/web/js/components/geosearch/ol-coordinates-marker.js b/web/js/components/geosearch/ol-coordinates-marker.js
index a5e5361bc..187199922 100644
--- a/web/js/components/geosearch/ol-coordinates-marker.js
+++ b/web/js/components/geosearch/ol-coordinates-marker.js
@@ -40,7 +40,7 @@ export class CoordinatesInteractions extends React.Component {
let isActiveLayer = false;
map.forEachFeatureAtPixel(pixels, (feature) => {
const featureId = feature.getId();
- const isMarker = featureId === 'coordinates-map-maker';
+ const isMarker = featureId === 'coordinates-map-marker';
if (isMarker) {
isActiveLayer = true;
}
@@ -71,6 +71,7 @@ export class CoordinatesInteractions extends React.Component {
function mapStateToProps(state) {
const {
+ config,
map,
measure,
geosearch,
@@ -81,7 +82,7 @@ function mapStateToProps(state) {
map,
coordinates,
isShowingClick: map.isClickable,
- getCoordinatesDialog: (pixels, olMap) => getCoordinatesDialogAtMapPixel(pixels, olMap),
+ getCoordinatesDialog: (pixels, olMap) => getCoordinatesDialogAtMapPixel(pixels, olMap, config),
measureIsActive: measure.isActive,
};
} const mapDispatchToProps = (dispatch) => ({
diff --git a/web/js/components/geosearch/util.js b/web/js/components/geosearch/util.js
index 306d77114..24d6e8761 100644
--- a/web/js/components/geosearch/util.js
+++ b/web/js/components/geosearch/util.js
@@ -1,50 +1,4 @@
import CoordinateParser from 'coordinate-parser';
-// import safeLocalStorage from '../../util/local-storage';
-
-// const { SEARCH_TOKEN } = safeLocalStorage.keys;
-
-// export function getTokenDataFromStorage() {
-// const tokenData = safeLocalStorage.getItem(SEARCH_TOKEN);
-// if (tokenData) {
-// return JSON.parse(tokenData);
-// }
-// return {};
-// }
-
-// export function getTokenFromStorage() {
-// const tokenData = getTokenDataFromStorage();
-// return tokenData.token;
-// }
-
-// function getTokenExpiryFromStorage() {
-// const tokenData = getTokenDataFromStorage();
-// return tokenData.expires;
-// }
-
-// export function isTokenExpired() {
-// const time = Date.now();
-// const expires = getTokenExpiryFromStorage();
-// if (!expires) {
-// return true;
-// }
-// return expires <= time;
-// }
-
-// function setTokenDataToStorage(tokenData) {
-// safeLocalStorage.setItem(SEARCH_TOKEN, JSON.stringify(tokenData));
-// }
-
-// TEMP TOKEN FUNC USED IN COMPONENT
-// function Token() {
-// // Try to read user info, although it might not have loaded yet
-// let token;
-// if (isTokenExpired()) {
-// token = tokenData.token.read();
-// } else {
-// token = getTokenFromStorage();
-// }
-// return <h1>{token.access_token}</h1>;
-// }
export default function isValidCoordinates(position) {
try {
diff --git a/web/js/components/measure-tool/measure-button.js b/web/js/components/measure-tool/measure-button.js
index 1e3fb6278..b136d6621 100644
--- a/web/js/components/measure-tool/measure-button.js
+++ b/web/js/components/measure-tool/measure-button.js
@@ -84,17 +84,13 @@ class MeasureButton extends React.Component {
onMouseDown={this.onButtonClick}
disabled={isActive}
>
-<<<<<<< HEAD
<UncontrolledTooltip
placement="top"
target={buttonId}
>
{labelText}
</UncontrolledTooltip>
- <FontAwesomeIcon icon="ruler" size="2x" />
-=======
- <FontAwesomeIcon icon={faRuler} size={faSize} />
->>>>>>> 859ca3689 (add ismobile check for conditional fa button size, clean up geosearch container)
+ <FontAwesomeIcon icon="ruler" size={faSize} />
</Button>
</>
);
diff --git a/web/js/components/measure-tool/measure-tooltip.js b/web/js/components/measure-tool/measure-tooltip.js
index 2cbc1f18b..5731a90bc 100644
--- a/web/js/components/measure-tool/measure-tooltip.js
+++ b/web/js/components/measure-tool/measure-tooltip.js
@@ -102,7 +102,7 @@ export default function MeasureTooltip(props) {
};
return (
- <div className={`tooltip-custom-black ${activeStaticClass}`}>
+ <div className={`tooltip-measure tooltip-custom-black ${activeStaticClass}`}>
<span dangerouslySetInnerHTML={{ __html: getMeasurementValue() }} />
{!active && (
<span className="close-tooltip" onClick={onRemove}>
diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.js
index a1240b7db..def5e8952 100644
--- a/web/js/containers/toolbar.js
+++ b/web/js/containers/toolbar.js
@@ -235,8 +235,6 @@ class toolbarContainer extends Component {
id="wv-geosearch-button"
className="wv-toolbar-button"
title="Search by place name or reverse search using coordinates"
- // onTouchEnd={toggleShowGeosearch}
- // onMouseDown={toggleShowGeosearch}
onClick={handleButtonClick}
>
<FontAwesomeIcon icon="search-location" size={faSize} />
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index 226c2e10a..05ca2e1b3 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -4,7 +4,7 @@ import { get as lodashGet, assign as lodashAssign } from 'lodash';
import { modalReducer, modalAboutPage } from './modal/reducers';
import feedbackReducer from './feedback/reducers';
import projectionReducer from './projection/reducer';
-import geosearchReducer from './geosearch/reducers';
+import { geosearchReducer } from './geosearch/reducers';
import { shortLink } from './link/reducers';
import {
requestedEvents,
diff --git a/web/js/modules/geosearch/actions.js b/web/js/modules/geosearch/actions.js
index d784a9b43..20f257978 100644
--- a/web/js/modules/geosearch/actions.js
+++ b/web/js/modules/geosearch/actions.js
@@ -50,17 +50,17 @@ export function selectCoordinatesToFly(coordinates, reverseGeocodeResults) {
if (reverseGeocodeResults) {
const { error } = reverseGeocodeResults;
if (error) {
- console.log('ERROR REVERSE GEOCODING - Typically, the coordinates are not geocoding with data.', error);
+ console.log(`ERROR REVERSE GEOCODING - ${error.message} ${error.details}`);
}
}
const marker = addCoordinatesMarker(activeMarker, config, map, coordinates, reverseGeocodeResults);
if (!marker) {
console.log('ERROR ADDING MARKER - Coordinates are outside range of current map projection extent.');
- dispatch({
+ return dispatch({
type: SELECT_COORDINATES_TO_FLY,
value: false,
- coordinates,
+ coordinates: [],
activeMarker: null,
});
}
@@ -68,7 +68,7 @@ export function selectCoordinatesToFly(coordinates, reverseGeocodeResults) {
const activeLayers = active.filter((layer) => layer.projections[proj.id] !== undefined);
const maxZoom = getMaxZoomLevelLayerCollection(activeLayers, zoom, proj.id, sources);
- animateCoordinates(map, coordinates, maxZoom);
+ animateCoordinates(map, config, coordinates, maxZoom);
dispatch({
type: SELECT_COORDINATES_TO_FLY,
@@ -86,7 +86,9 @@ export function clearCoordinates() {
const { map, geosearch } = state;
const { activeMarker } = geosearch;
- removeCoordinatesMarker(activeMarker, map);
+ if (activeMarker) {
+ removeCoordinatesMarker(activeMarker, map);
+ }
dispatch({
type: CLEAR_COORDINATES,
});
diff --git a/web/js/modules/geosearch/actions.test.js b/web/js/modules/geosearch/actions.test.js
new file mode 100644
index 000000000..04303657a
--- /dev/null
+++ b/web/js/modules/geosearch/actions.test.js
@@ -0,0 +1,41 @@
+import configureMockStore from 'redux-mock-store';
+import thunk from 'redux-thunk';
+import {
+ toggleShowGeosearch,
+ toggleReverseGeocodeActive,
+} from './actions';
+import {
+ TOGGLE_REVERSE_GEOCODE_ACTIVE,
+ TOGGLE_SHOW_GEOSEARCH,
+} from './constants';
+
+const middlewares = [thunk];
+const mockStore = configureMockStore(middlewares);
+
+// test variables
+const isExpanded = true;
+
+describe('Geosearch actions', () => {
+ test(`toggleShowGeosearch action returns ${TOGGLE_SHOW_GEOSEARCH} as type and ${
+ !isExpanded} as value`, () => {
+ const expectedAction = {
+ type: TOGGLE_SHOW_GEOSEARCH,
+ value: false,
+ };
+ const store = mockStore({
+ geosearch: {
+ isExpanded: true,
+ },
+ });
+ store.dispatch(toggleShowGeosearch());
+ expect(store.getActions()[0]).toEqual(expectedAction);
+ });
+ test(`toggleReverseGeocodeActive action returns ${TOGGLE_REVERSE_GEOCODE_ACTIVE} as type and ${
+ true} as value`, () => {
+ const expectedAction = {
+ type: TOGGLE_REVERSE_GEOCODE_ACTIVE,
+ value: true,
+ };
+ expect(toggleReverseGeocodeActive(true)).toEqual(expectedAction);
+ });
+});
diff --git a/web/js/modules/geosearch/reducers.js b/web/js/modules/geosearch/reducers.js
index d6c2bddb8..c184179c2 100644
--- a/web/js/modules/geosearch/reducers.js
+++ b/web/js/modules/geosearch/reducers.js
@@ -9,7 +9,7 @@ import {
import { getLocalStorageCollapseState } from './util';
const localStorageCollapseState = getLocalStorageCollapseState();
-const geosearchState = {
+export const geosearchState = {
isCoordinateSearchActive: false,
isExpanded: !localStorageCollapseState,
coordinates: [],
@@ -17,7 +17,7 @@ const geosearchState = {
reverseGeocodeResults: null,
};
-export default function geosearchReducer(state = geosearchState, action) {
+export function geosearchReducer(state = geosearchState, action) {
switch (action.type) {
case UPDATE_ACTIVE_MARKER:
return lodashAssign({}, state, {
diff --git a/web/js/modules/geosearch/reducers.test.js b/web/js/modules/geosearch/reducers.test.js
new file mode 100644
index 000000000..c4171c0ab
--- /dev/null
+++ b/web/js/modules/geosearch/reducers.test.js
@@ -0,0 +1,114 @@
+import {
+ geosearchReducer,
+ geosearchState,
+} from './reducers';
+import {
+ CLEAR_COORDINATES,
+ SELECT_COORDINATES_TO_FLY,
+ TOGGLE_REVERSE_GEOCODE_ACTIVE,
+ TOGGLE_SHOW_GEOSEARCH,
+ UPDATE_ACTIVE_MARKER,
+} from './constants';
+
+// test variables
+const reverseGeocodeResults = {
+ address: {},
+ location: {},
+};
+
+describe('geosearchReducer', () => {
+ test(' should return the initial state', () => {
+ expect(geosearchReducer(undefined, {})).toEqual(
+ geosearchState,
+ );
+ });
+ test(
+ `${CLEAR_COORDINATES
+ } resets cooridnates, activeMarker, and geocode results`
+ + 'should return new state',
+ () => {
+ expect(
+ geosearchReducer(geosearchState, {
+ type: CLEAR_COORDINATES,
+ }),
+ ).toEqual({
+ ...geosearchState,
+ coordinates: [],
+ activeMarker: null,
+ reverseGeocodeResults: null,
+ });
+ },
+ );
+ test(
+ `${TOGGLE_SHOW_GEOSEARCH
+ } shows geosearch isExpanded and `
+ + 'should return new state',
+ () => {
+ expect(
+ geosearchReducer(geosearchState, {
+ type: TOGGLE_SHOW_GEOSEARCH,
+ value: true,
+ }),
+ ).toEqual({
+ ...geosearchState,
+ isExpanded: true,
+ });
+ },
+ );
+ test(
+ `${TOGGLE_REVERSE_GEOCODE_ACTIVE
+ } toggles isCoordinateSearchActive to true and `
+ + 'should return new state',
+ () => {
+ expect(
+ geosearchReducer(geosearchState, {
+ type: TOGGLE_REVERSE_GEOCODE_ACTIVE,
+ value: true,
+ }),
+ ).toEqual({
+ ...geosearchState,
+ isCoordinateSearchActive: true,
+ });
+ },
+ );
+ test(
+ `${UPDATE_ACTIVE_MARKER
+ } updates action value and reverseGeocodeResults objects and `
+ + 'should return new state',
+ () => {
+ expect(
+ geosearchReducer(geosearchState, {
+ type: UPDATE_ACTIVE_MARKER,
+ value: {},
+ reverseGeocodeResults,
+ }),
+ ).toEqual({
+ ...geosearchState,
+ activeMarker: {},
+ reverseGeocodeResults,
+ });
+ },
+ );
+ test(
+ `${SELECT_COORDINATES_TO_FLY
+ } updates activeMarker, coordinates, and reverseGeocodeResults `
+ + 'and sets isCoordinateSearchActive to false and should return new state',
+ () => {
+ expect(
+ geosearchReducer(geosearchState, {
+ type: SELECT_COORDINATES_TO_FLY,
+ value: false,
+ coordinates: [],
+ activeMarker: {},
+ reverseGeocodeResults,
+ }),
+ ).toEqual({
+ ...geosearchState,
+ isCoordinateSearchActive: false,
+ coordinates: [],
+ activeMarker: {},
+ reverseGeocodeResults,
+ });
+ },
+ );
+});
diff --git a/web/js/modules/geosearch/selectors.js b/web/js/modules/geosearch/selectors.js
index 35c75777f..069a6cf81 100644
--- a/web/js/modules/geosearch/selectors.js
+++ b/web/js/modules/geosearch/selectors.js
@@ -6,39 +6,35 @@ import {
Style as OlStyle,
Icon as OlIcon,
} from 'ol/style';
-import * as olProj from 'ol/proj';
import { containsXY } from 'ol/extent';
+import { coordinatesCRSTransform } from '../projection/util';
+
+export function animateCoordinates(map, config, coordinates, zoom) {
+ const { projections } = config;
+ const { selected } = map.ui;
+ const { proj } = selected;
+ const { crs } = projections[proj];
-export function animateCoordinates(map, coordinates, zoom) {
- const { ui } = map;
- const { proj } = ui.selected;
let targetCoordinates = coordinates;
if (proj !== 'geographic') {
- targetCoordinates = polarCoordinatesTransform(coordinates, proj);
+ targetCoordinates = coordinatesCRSTransform(coordinates, 'EPSG:4326', crs);
}
- ui.animate.fly(targetCoordinates, zoom);
-}
-
-export function polarCoordinatesTransform(coordinates, proj) {
- const projObj = {
- arctic: 'EPSG:3413',
- antarctic: 'EPSG:3031',
- };
- return olProj.transform(coordinates, 'EPSG:4326', projObj[proj]);
+ map.ui.animate.fly(targetCoordinates, zoom);
}
export function areCoordinatesWithinExtent(map, config, coordinates) {
const { projections } = config;
const { selected } = map.ui;
- const projMaxExtent = projections[selected.proj].maxExtent;
+ const { proj } = selected;
+ const { maxExtent, crs } = projections[proj];
let coordinatesWithinExtent;
let transformedCoordinates;
- if (selected.proj !== 'geographic') {
- transformedCoordinates = polarCoordinatesTransform(coordinates, selected.proj);
- coordinatesWithinExtent = containsXY(projMaxExtent, transformedCoordinates[0], transformedCoordinates[1]);
+ if (proj !== 'geographic') {
+ transformedCoordinates = coordinatesCRSTransform(coordinates, 'EPSG:4326', crs);
+ coordinatesWithinExtent = containsXY(maxExtent, transformedCoordinates[0], transformedCoordinates[1]);
} else {
- coordinatesWithinExtent = containsXY(projMaxExtent, coordinates[0], coordinates[1]);
+ coordinatesWithinExtent = containsXY(maxExtent, coordinates[0], coordinates[1]);
}
return {
coordinatesWithinExtent,
@@ -76,7 +72,7 @@ export function removeCoordinatesMarker(activeMarker, map) {
const mapOverlays = proj[mapProjection].getOverlays().getArray();
const coordinatesTooltipOverlay = mapOverlays.filter((overlay) => {
const { id } = overlay;
- return id && id.contains('coordinates-map-maker');
+ return id && id.includes('coordinates-map-marker');
});
if (coordinatesTooltipOverlay.length > 0) {
proj[mapProjection].removeOverlay(coordinatesTooltipOverlay[0]);
@@ -106,7 +102,7 @@ const createPin = function(coordinates, transformedCoordinates = false, reverseG
});
iconFeature.setStyle(iconStyle);
- iconFeature.setId('coordinates-map-maker');
+ iconFeature.setId('coordinates-map-marker');
const vectorSource = new OlSourceVector({
wrapX: false,
diff --git a/web/js/modules/projection/util.js b/web/js/modules/projection/util.js
index 7e6a79266..04fe0c7d1 100644
--- a/web/js/modules/projection/util.js
+++ b/web/js/modules/projection/util.js
@@ -1,5 +1,17 @@
import { get as lodashGet } from 'lodash';
import update from 'immutability-helper';
+import * as olProj from 'ol/proj';
+
+/**
+ * Transform coordinates from one projection to another
+ *
+ * @param {Array} coordinates | longitude, latitude ex: [40.21875, -76.218750]
+ * @param {String} inputCRS | coordinate system of coordinates ex: "EPSG:4326"
+ * @param {String} targetCRS | target output with transformed cooridnates ex: "EPSG:3031"
+ */
+export function coordinatesCRSTransform(coordinates, inputCRS, targetCRS) {
+ return olProj.transform(coordinates, inputCRS, targetCRS);
+}
export function getProjInitialState(config) {
const selected = lodashGet(
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index 618fa1e91..b6539ba05 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -220,7 +220,7 @@ function getModalContentsAtPixel(mapProps, config, compareState) {
const { pixels, map, swipeOffset } = mapProps;
map.forEachFeatureAtPixel(pixels, (feature, layer) => {
const featureId = feature.getId();
- if (featureId === 'coordinates-map-maker') {
+ if (featureId === 'coordinates-map-marker') {
isCoordinatesMarker = true;
return;
}