Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Place marker minimized url support (#7032)

christof-wittreichb2ac3e5ee24e
diff --git a/web/js/components/location-search/location-marker.js b/web/js/components/location-search/location-marker.js
index 70d49b8e4..eab3a3a39 100644
--- a/web/js/components/location-search/location-marker.js
+++ b/web/js/components/location-search/location-marker.js
@@ -26,7 +26,12 @@ const getDialogTitle = (geocodeProperties) => {
};
export default function LocationMarker ({
- reverseGeocodeResults, removeMarker, coordinatesObject, isMobile, dialogVisible = true,
+ reverseGeocodeResults,
+ removeMarker,
+ toggleHiddenMarker,
+ coordinatesObject,
+ isMobile,
+ dialogVisible = true,
}) {
const { longitude, latitude } = coordinatesObject;
const tooltipId = util.encodeId(`coordinates-map-marker_${longitude},${latitude}`);
@@ -34,14 +39,19 @@ export default function LocationMarker ({
const title = getDialogTitle(reverseGeocodeResults);
const [showDialog, setShowDialog] = useState(dialogVisible);
+ const toggleDialog = function(val) {
+ setShowDialog(val);
+ toggleHiddenMarker();
+ };
+
return (
- <div className="location-dialog-pin-wrapper ">
+ <div className="location-dialog-pin-wrapper">
{showDialog && (
<CoordinatesDialog
title={title}
coordinates={coordinates}
removeMarker={removeMarker}
- removeCoordinatesDialog={() => setShowDialog(false)}
+ removeCoordinatesDialog={() => toggleDialog(false)}
isMobile={isMobile}
tooltipId={tooltipId}
/>
@@ -51,7 +61,7 @@ export default function LocationMarker ({
src="images/map-pin.png"
height="32"
width="20"
- onClick={() => setShowDialog(true)}
+ onClick={() => toggleDialog(true)}
/>
</div>
);
@@ -60,6 +70,7 @@ export default function LocationMarker ({
LocationMarker.propTypes = {
reverseGeocodeResults: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),
isMobile: PropTypes.bool,
+ toggleHiddenMarker: PropTypes.func,
coordinatesObject: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),
removeMarker: PropTypes.func,
dialogVisible: PropTypes.bool,
diff --git a/web/js/components/location-search/location-marker.test.js b/web/js/components/location-search/location-marker.test.js
index b4b3498e2..d3c5670f0 100644
--- a/web/js/components/location-search/location-marker.test.js
+++ b/web/js/components/location-search/location-marker.test.js
@@ -24,6 +24,7 @@ jest.mock('../../util/util', () => ({
const baseProps = {
coordinatesObject: { latitude: 34.05, longitude: -118.24 },
reverseGeocodeResults: { address: null, error: null },
+ toggleHiddenMarker: jest.fn(),
removeMarker: jest.fn(),
isMobile: false,
dialogVisible: true,
diff --git a/web/js/mapUI/components/markers/markers.js b/web/js/mapUI/components/markers/markers.js
index c13072ce5..ae6386aa8 100644
--- a/web/js/mapUI/components/markers/markers.js
+++ b/web/js/mapUI/components/markers/markers.js
@@ -7,6 +7,7 @@ import { animateCoordinates, areCoordinatesWithinExtent, getCoordinatesMarker }
import {
setGeocodeResults as setGeocodeResultsAction,
removeMarker as removeMarkerAction,
+ toggleIsHidden as toggleIsHiddenAction,
} from '../../../modules/location-search/actions';
import { getActiveLayers, getMaxZoomLevelLayerCollection } from '../../../modules/layers/selectors';
@@ -22,6 +23,7 @@ function Markers(props) {
selectedMapMarkers,
proj,
removeMarker,
+ toggleIsHidden,
setGeocodeResults,
ui,
} = props;
@@ -90,11 +92,13 @@ function Markers(props) {
const results = geocodeResults;
if (!results) return undefined;
const remove = () => removeMarker(coordinatesObject);
+ const toggleHidden = () => toggleIsHidden(coordinatesObject);
const marker = getCoordinatesMarker(
proj,
coordinatesObject,
results,
remove,
+ toggleHidden,
isMobileDevice,
showDialog,
);
@@ -126,11 +130,11 @@ function Markers(props) {
removeAllCoordinatesMarkers();
if (coordinates && coordinates.length > 0) {
coordinates.forEach((coordinatesObject) => {
- const { longitude, latitude } = coordinatesObject;
+ const { longitude, latitude, isHidden } = coordinatesObject;
const coord = [longitude, latitude];
if (!areCoordinatesWithinExtent(proj, coord)) return;
reverseGeocode(getNormalizedCoordinate(coord), config).then((results) => {
- addMarkerAndUpdateStore(true, results, null, coordinatesObject);
+ addMarkerAndUpdateStore(!isHidden, results, null, coordinatesObject);
});
});
}
@@ -197,6 +201,9 @@ const mapDispatchToProps = (dispatch) => ({
removeMarker: (value) => {
dispatch(removeMarkerAction(value));
},
+ toggleIsHidden: (value) => {
+ dispatch(toggleIsHiddenAction(value));
+ },
});
export default React.memo(
@@ -215,6 +222,7 @@ Markers.propTypes = {
isMobileDevice: PropTypes.bool,
proj: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),
removeMarker: PropTypes.func,
+ toggleIsHidden: PropTypes.func,
selectedMap: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),
selectedMapMarkers: PropTypes.oneOfType([PropTypes.array, PropTypes.oneOf(['null'])]),
setGeocodeResults: PropTypes.func,
diff --git a/web/js/mapUI/components/markers/markers.test.js b/web/js/mapUI/components/markers/markers.test.js
index 69e0389e9..d4d0fe0ec 100644
--- a/web/js/mapUI/components/markers/markers.test.js
+++ b/web/js/mapUI/components/markers/markers.test.js
@@ -273,6 +273,7 @@ describe('Markers', () => {
coord,
results,
expect.any(Function),
+ expect.any(Function),
false,
true,
);
@@ -378,6 +379,7 @@ describe('Markers', () => {
mockCoordinatesObject,
mockResults,
expect.any(Function),
+ expect.any(Function),
false,
true,
);
diff --git a/web/js/modules/location-search/actions.js b/web/js/modules/location-search/actions.js
index 954a7c727..f3b5f987c 100644
--- a/web/js/modules/location-search/actions.js
+++ b/web/js/modules/location-search/actions.js
@@ -2,6 +2,7 @@ import {
CLEAR_SUGGESTIONS,
REMOVE_MARKER,
SET_MARKER,
+ TOGGLE_MARKER_HIDDEN,
SET_SUGGESTION,
SET_REVERSE_GEOCODE_RESULTS,
TOGGLE_DIALOG_VISIBLE,
@@ -110,6 +111,13 @@ export function removeMarker(coordinates) {
};
}
+export function toggleIsHidden(coordinates) {
+ return {
+ type: TOGGLE_MARKER_HIDDEN,
+ coordinates,
+ };
+}
+
export function setGeocodeResults(results) {
return {
type: SET_REVERSE_GEOCODE_RESULTS,
diff --git a/web/js/modules/location-search/actions.test.js b/web/js/modules/location-search/actions.test.js
index 3883267ac..b53ae0b2e 100644
--- a/web/js/modules/location-search/actions.test.js
+++ b/web/js/modules/location-search/actions.test.js
@@ -7,6 +7,7 @@ import {
setSuggestion,
setPlaceMarker,
removeMarker,
+ toggleIsHidden,
setGeocodeResults,
toggleDialogVisible,
getSuggestions,
@@ -18,6 +19,7 @@ import {
SET_SUGGESTION,
SET_REVERSE_GEOCODE_RESULTS,
REMOVE_MARKER,
+ TOGGLE_MARKER_HIDDEN,
TOGGLE_DIALOG_VISIBLE,
SET_MARKER,
} from './constants';
@@ -114,6 +116,15 @@ describe('Location Search actions', () => {
expect(removeMarker(coordinates)).toEqual(expectedAction);
});
+ test(`toggleIsHidden action dispatches ${TOGGLE_MARKER_HIDDEN} [locationsearch-actions-toggle-marker-hidden]`, () => {
+ const coordinates = { id: 123, longitude: -73.7075, latitude: 41.59, isHidden: false };
+ const expectedAction = {
+ type: TOGGLE_MARKER_HIDDEN,
+ coordinates,
+ };
+ expect(toggleIsHidden(coordinates)).toEqual(expectedAction);
+ });
+
test(`setGeocodeResults action returns ${SET_REVERSE_GEOCODE_RESULTS} as type and results as value [locationsearch-actions-set-geocode-results]`, () => {
const results = { address: { LongLabel: 'New York, NY, USA' } };
const expectedAction = {
diff --git a/web/js/modules/location-search/constants.js b/web/js/modules/location-search/constants.js
index 988ec8f20..eafed9b04 100644
--- a/web/js/modules/location-search/constants.js
+++ b/web/js/modules/location-search/constants.js
@@ -1,5 +1,6 @@
export const CLEAR_SUGGESTIONS = 'LOCATION_SEARCH/CLEAR_SUGGESTIONS';
export const REMOVE_MARKER = 'LOCATION_SEARCH/REMOVE_MARKER';
+export const TOGGLE_MARKER_HIDDEN = 'LOCATION_SEARCH/TOGGLE_MARKER_HIDDEN';
export const REQUEST_SUGGEST_PLACE_FAILURE = 'LOCATION_SEARCH/REQUEST_SUGGEST_PLACE_FAILURE';
export const REQUEST_SUGGEST_PLACE_SUCCESS = 'LOCATION_SEARCH/REQUEST_SUGGEST_PLACE_SUCCESS';
export const SET_REVERSE_GEOCODE_RESULTS = 'LOCATION_SEARCH/SET_REVERSE_GEOCODE_RESULTS';
diff --git a/web/js/modules/location-search/reducers.js b/web/js/modules/location-search/reducers.js
index c0ecb530c..246843c5d 100644
--- a/web/js/modules/location-search/reducers.js
+++ b/web/js/modules/location-search/reducers.js
@@ -1,6 +1,7 @@
import {
CLEAR_SUGGESTIONS,
REMOVE_MARKER,
+ TOGGLE_MARKER_HIDDEN,
REQUEST_SUGGEST_PLACE_FAILURE,
REQUEST_SUGGEST_PLACE_SUCCESS,
SET_REVERSE_GEOCODE_RESULTS,
@@ -51,6 +52,18 @@ export function locationSearchReducer(state = locationSearchState, action) {
coordinates: state.coordinates
.filter((coordinate) => action.coordinates.id !== coordinate.id),
};
+ case TOGGLE_MARKER_HIDDEN:
+ return {
+ ...state,
+ coordinates: state.coordinates
+ .map((coordinate) => action.coordinates.id !== coordinate.id
+ ? coordinate
+ : {
+ ...coordinate,
+ isHidden: !coordinate.isHidden,
+ },
+ ),
+ };
case SET_SUGGESTION:
return {
...state,
diff --git a/web/js/modules/location-search/reducers.test.js b/web/js/modules/location-search/reducers.test.js
index 9b5ccbdec..93e27a492 100644
--- a/web/js/modules/location-search/reducers.test.js
+++ b/web/js/modules/location-search/reducers.test.js
@@ -11,6 +11,7 @@ import {
SET_REVERSE_GEOCODE_RESULTS,
SET_SUGGESTION,
TOGGLE_REVERSE_GEOCODE,
+ TOGGLE_MARKER_HIDDEN,
TOGGLE_SHOW_LOCATION_SEARCH,
} from './constants';
@@ -23,8 +24,8 @@ const suggestion = [{
magicKey: 'test1234=',
text: 'New York, NY, USA',
}];
-const coordinatesObject = { id: 1234, latitude: 72, longitude: 40 };
-const coordinatesObject2 = { id: 5678, latitude: 34, longitude: -118 };
+const coordinatesObject = { id: 1234, latitude: 72, longitude: 40, isHidden: false };
+const coordinatesObject2 = { id: 5678, latitude: 34, longitude: -118, isHidden: true };
describe('locationSearch', () => {
test('locationSearch should return the initial state [locationstate-reducer-initial-state]', () => {
@@ -97,6 +98,52 @@ describe('locationSearch', () => {
},
);
+ test(
+ `${TOGGLE_MARKER_HIDDEN} toggles coordinate.isHidden to true and ` +
+ 'should return new state [locationsearch-reducer-marker-hidden]',
+ () => {
+ const stateWithExistingCoord = {
+ ...locationSearchState,
+ coordinates: [coordinatesObject],
+ };
+ expect(
+ locationSearchReducer(stateWithExistingCoord, {
+ type: TOGGLE_MARKER_HIDDEN,
+ coordinates: coordinatesObject,
+ }),
+ ).toEqual({
+ ...locationSearchState,
+ coordinates: [{
+ ...coordinatesObject,
+ isHidden: true,
+ }],
+ });
+ },
+ );
+
+ test(
+ `${TOGGLE_MARKER_HIDDEN} toggles coordinate.isHidden to false and ` +
+ 'should return new state [locationsearch-reducer-reverse-marker-hidden]',
+ () => {
+ const stateWithExistingCoord = {
+ ...locationSearchState,
+ coordinates: [coordinatesObject2],
+ };
+ expect(
+ locationSearchReducer(stateWithExistingCoord, {
+ type: TOGGLE_MARKER_HIDDEN,
+ coordinates: coordinatesObject2,
+ }),
+ ).toEqual({
+ ...locationSearchState,
+ coordinates: [{
+ ...coordinatesObject2,
+ isHidden: false,
+ }],
+ });
+ },
+ );
+
test(
`${SET_REVERSE_GEOCODE_RESULTS} updates reverseGeocodeResults and ` +
'should return new state [locationsearch-reducer-set-reverse-geocode-results]',
diff --git a/web/js/modules/location-search/util.js b/web/js/modules/location-search/util.js
index bd5777f61..e99b3bc76 100644
--- a/web/js/modules/location-search/util.js
+++ b/web/js/modules/location-search/util.js
@@ -48,7 +48,7 @@ export function areCoordinatesWithinExtent(proj, coordinates) {
* @param {Object} pinProps
* @param {Number} id
*/
-const createPin = function(coordinates, pinProps, id, removeMarkerPin) {
+const createPin = function(coordinates, pinProps, id, removeMarkerPin, toggleHiddenMarker) {
const overlayEl = document.createElement('div');
const root = createRoot(overlayEl);
const removeMarker = () => {
@@ -56,7 +56,7 @@ const createPin = function(coordinates, pinProps, id, removeMarkerPin) {
removeMarkerPin();
};
root.render(
- React.createElement(LocationMarker, { ...pinProps, removeMarker }),
+ React.createElement(LocationMarker, { ...pinProps, removeMarker, toggleHiddenMarker }),
);
const markerPin = new OlOverlay({
element: overlayEl,
@@ -64,6 +64,7 @@ const createPin = function(coordinates, pinProps, id, removeMarkerPin) {
positioning: 'bottom-center',
stopEvent: false,
id,
+ className: 'location-dialog-pin-wrapper-parent',
});
return markerPin;
@@ -81,6 +82,7 @@ export function getCoordinatesMarker(
coordinatesObject,
results,
removeMarker,
+ toggleHiddenMarker,
isMobile,
dialogVisible,
) {
@@ -102,7 +104,7 @@ export function getCoordinatesMarker(
};
// create Ol vector layer map pin
- const marker = createPin(transformedCoords, pinProps, id, removeMarker);
+ const marker = createPin(transformedCoords, pinProps, id, removeMarker, toggleHiddenMarker);
return marker;
}
@@ -129,7 +131,7 @@ export function mapLocationToLocationSearchState(
const coordinatesArray = s ? s.split('+') : [];
const isValid = coordinatesArray.length >= 1;
const validatedCoordinatesArray = coordinatesArray.map((coordinate) => {
- const [longitude, latitude] = coordinate
+ const [longitude, latitude, isHidden] = coordinate
? coordinate.split(',')
.map((coord) => Number(coord))
.filter((coord) => !lodashIsNaN(parseFloat(coord)))
@@ -140,6 +142,7 @@ export function mapLocationToLocationSearchState(
id: markerId,
latitude,
longitude,
+ isHidden: isHidden === 1,
};
return validatedCoordinates;
});
@@ -159,8 +162,9 @@ export function mapLocationToLocationSearchState(
export function serializeCoordinatesWrapper(coordinates, state) {
const { map, proj } = state;
- const serializeCoordinates = ({ longitude, latitude }) => {
+ const serializeCoordinates = ({ longitude, latitude, isHidden }) => {
const coordinateValues = [longitude, latitude];
+ if (isHidden) coordinateValues.push(1);
if (!map.ui.selected) return undefined;
const coordinatesWithinExtent = areCoordinatesWithinExtent(proj, coordinateValues);
if (!coordinatesWithinExtent) return undefined;
diff --git a/web/js/modules/location-search/util.test.js b/web/js/modules/location-search/util.test.js
index bbb3ae89a..74a955ee6 100644
--- a/web/js/modules/location-search/util.test.js
+++ b/web/js/modules/location-search/util.test.js
@@ -244,13 +244,15 @@ describe('mapLocationToLocationSearchState', () => {
test('parses multiple coordinates from s parameter separated by + [util-map-location-to-state-multiple]', () => {
const result = mapLocationToLocationSearchState(
- { s: '-74,40+-118,34' },
+ { s: '-74,40+-118,34,1' },
baseStoreFromLocation,
baseState,
);
expect(result.locationSearch.coordinates).toHaveLength(2);
expect(result.locationSearch.coordinates[0].longitude).toBe(-74);
+ expect(result.locationSearch.coordinates[0].isHidden).toBe(false);
expect(result.locationSearch.coordinates[1].longitude).toBe(-118);
+ expect(result.locationSearch.coordinates[1].isHidden).toBe(true);
});
test('returns empty coordinates array when s parameter is absent [util-map-location-to-state-no-s]', () => {
diff --git a/web/scss/components/tooltip.scss b/web/scss/components/tooltip.scss
index 5590cf2ca..22d57466b 100644
--- a/web/scss/components/tooltip.scss
+++ b/web/scss/components/tooltip.scss
@@ -145,6 +145,7 @@
&.tooltip-coordinates-container {
max-width: 420px;
bottom: 6px;
+ pointer-events: all;
& svg.svg-inline--fa.fa-copy {
position: absolute;
diff --git a/web/scss/features/location-search.scss b/web/scss/features/location-search.scss
index 7522f9fec..e8c607f15 100644
--- a/web/scss/features/location-search.scss
+++ b/web/scss/features/location-search.scss
@@ -249,6 +249,19 @@
}
}
-.location-dialog-pin-wrapper {
- text-align: center;
+.location-dialog-pin-wrapper-parent {
+ pointer-events: none !important;
+
+ & > div {
+ pointer-events: none;
+ }
+
+ .location-dialog-pin-wrapper {
+ text-align: center;
+ pointer-events: none;
+
+ img {
+ pointer-events: all;
+ }
+ }
}