Interactive interface for browsing global, full-resolution satellite imagery
move add/remove marker and related tooltip to use dom
Ed Plato8c18669b643e
diff --git a/web/js/components/geosearch/geosearch-modal.js b/web/js/components/geosearch/geosearch-modal.jsindex 6e9992c16..43cf68ef8 100644--- a/web/js/components/geosearch/geosearch-modal.js+++ b/web/js/components/geosearch/geosearch-modal.js@@ -15,11 +15,11 @@ import Alert from '../util/alert';import { getCoordinateFixedPrecision, isValidCoordinates } from './util';import {clearSuggestions,- selectCoordinatesToFly,- toggleShowGeosearch,- toggleReverseGeocodeActive,- setSuggestion,getSuggestions,+ setPlaceMarker,+ setSuggestion,+ toggleReverseGeocodeActive,+ toggleShowGeosearch,} from '../../modules/geosearch/actions';import {areCoordinatesWithinExtent,@@ -106,19 +106,19 @@ class GeosearchModal extends Component {coordinatesPending,isCoordinatePairWithinExtent,reverseGeocode,- selectCoordinatesToFly,+ setPlaceMarker,updatePendingCoordinates,updateValue,} = this.props;const coordinatesWithinExtent = isCoordinatePairWithinExtent(coordinatesPending);- if (coordinatesWithinExtent === false) {+ if (!coordinatesWithinExtent) {this.setExtentAlert(true);this.setInputAlertIcon(true);} else {const [longitude, latitude] = coordinatesPending;reverseGeocode([longitude, latitude]).then((results) => {- selectCoordinatesToFly([longitude, latitude], results);+ setPlaceMarker([longitude, latitude], results);});this.clearAlerts();updateValue('');@@ -132,7 +132,7 @@ class GeosearchModal extends Component {const {isCoordinatePairWithinExtent,processMagicKey,- selectCoordinatesToFly,+ setPlaceMarker,setSuggestion,updateValue,} = this.props;@@ -156,14 +156,14 @@ class GeosearchModal extends Component {const parsedY = getCoordinateFixedPrecision(y);const coordinatesWithinExtent = isCoordinatePairWithinExtent([parsedX, parsedY]);- if (coordinatesWithinExtent === false) {+ if (!coordinatesWithinExtent) {this.setExtentAlert(true);this.setInputAlertIcon(true);} else {- selectCoordinatesToFly([parsedX, parsedY], addressAttributes);+ setPlaceMarker([parsedX, parsedY], addressAttributes);}}- });+ }).catch((error) => console.error(error));}// handle input value change including text/coordinates typing, pasting, cutting@@ -411,8 +411,8 @@ const mapStateToProps = (state) => {};const mapDispatchToProps = (dispatch) => ({- selectCoordinatesToFly: (coordinates, addressAttributes) => {- dispatch(selectCoordinatesToFly(coordinates, addressAttributes));+ setPlaceMarker: (coordinates, addressAttributes) => {+ dispatch(setPlaceMarker(coordinates, addressAttributes));},toggleReverseGeocodeActive: (isActive) => {dispatch(toggleReverseGeocodeActive(isActive));@@ -444,7 +444,7 @@ GeosearchModal.propTypes = {isMobile: PropTypes.bool,processMagicKey: PropTypes.func,reverseGeocode: PropTypes.func,- selectCoordinatesToFly: PropTypes.func,+ setPlaceMarker: PropTypes.func,setSuggestion: PropTypes.func,suggestions: PropTypes.array,toggleReverseGeocodeActive: PropTypes.func,diff --git a/web/js/components/geosearch/ol-coordinates-marker-util.js b/web/js/components/geosearch/ol-coordinates-marker-util.jsindex 5754e417e..d8cc7528a 100644--- a/web/js/components/geosearch/ol-coordinates-marker-util.js+++ b/web/js/components/geosearch/ol-coordinates-marker-util.js@@ -9,18 +9,14 @@ import { getFormattedCoordinates } from './util';/*** getCoordinatesDialogTitle*- * @param {Object} address- * @param {Object} error- * @param {String} formattedLatitude- * @param {String} formattedLongitude+ * @param {Object} geocodeProperties | address, error*- * @returns {String} title+ * @returns {String | undefined} title*/-const getCoordinatesDialogTitle = (address, error, formattedLatitude, formattedLongitude) => {+const getCoordinatesDialogTitle = (geocodeProperties) => {+ const { address, error } = geocodeProperties;let title;- if (error) {- title = `${formattedLatitude.trim()}, ${formattedLongitude.trim()}`;- } else if (address) {+ if (address && !error) {/* eslint-disable camelcase */const {Addr_type,@@ -80,12 +76,10 @@ export const renderCoordinatesTooltip = (map, config, coordinates, coordinatesMe// add tooltip overlay to map and position based on marker coordinatesmap.addOverlay(tooltipOverlay);- toggleDialogVisible(true);tooltipOverlay.setPosition(coordinatesPosition);// helper function to remove/hide tooltip overlayconst removeCoordinatesDialog = () => {- map.removeOverlay(tooltipOverlay);toggleDialogVisible(false);};@@ -109,18 +103,17 @@ export const renderCoordinatesTooltip = (map, config, coordinates, coordinatesMe*/export const getCoordinatesMetadata = (geocodeProperties) => {const { latitude, longitude, reverseGeocodeResults } = geocodeProperties;- const { address, error } = reverseGeocodeResults;// get formatted coordinatesconst [formattedLatitude, formattedLongitude] = getFormattedCoordinates(latitude, longitude);// build title based on available parameters- const title = getCoordinatesDialogTitle(address, error, formattedLatitude, formattedLongitude);+ const title = getCoordinatesDialogTitle(reverseGeocodeResults, formattedLatitude, formattedLongitude);const coordinates = `${formattedLatitude.trim()}, ${formattedLongitude.trim()}`;return {coordinates,- title,+ title: title || coordinates,};};@@ -129,14 +122,10 @@ export const getCoordinatesMetadata = (geocodeProperties) => {** @param {Array} pixels* @param {Object} map- * @param {Object} config- * @param {Boolean} isMobile- * @param {Function} clearCoordinates- * @param {Function} toggleDialogVisible** @returns {Void}*/-export const getCoordinatesDialogAtMapPixel = (pixels, map, config, isMobile, clearCoordinates, toggleDialogVisible) => {+export const isCoordinatesDialogAvailableAtPixel = (pixels, map) => {// check for existing coordinate marker tooltip overlay and prevent multiple rendersconst mapOverlays = map.getOverlays().getArray();const mapMarkerId = 'coordinates-map-marker';@@ -148,17 +137,6 @@ export const getCoordinatesDialogAtMapPixel = (pixels, map, config, isMobile, clreturn;}- map.forEachFeatureAtPixel(pixels, (feature) => {- const featureId = feature.getId();- if (featureId === mapMarkerId) {- const featureProperties = feature.getProperties();- const { latitude, longitude } = featureProperties;-- // get metadata for tooltip- const coordinatesMetadata = getCoordinatesMetadata(featureProperties);-- // create tooltip overlay React DOM element- renderCoordinatesTooltip(map, config, [latitude, longitude], coordinatesMetadata, isMobile, clearCoordinates, toggleDialogVisible);- }- });+ const featureCheck = (feature) => feature.getId() === mapMarkerId;+ return map.forEachFeatureAtPixel(pixels, featureCheck);};diff --git a/web/js/components/geosearch/ol-coordinates-marker.js b/web/js/components/geosearch/ol-coordinates-marker.jsindex 336498165..22b3cbb59 100644--- a/web/js/components/geosearch/ol-coordinates-marker.js+++ b/web/js/components/geosearch/ol-coordinates-marker.js@@ -8,9 +8,9 @@ import PropTypes from 'prop-types';import { transform } from 'ol/proj';import Alert from '../util/alert';import { changeCursor as changeCursorActionCreator } from '../../modules/map/actions';-import { getCoordinatesDialogAtMapPixel } from './ol-coordinates-marker-util';+import { isCoordinatesDialogAvailableAtPixel } from './ol-coordinates-marker-util';import {- clearCoordinates, selectCoordinatesToFly, toggleDialogVisible, toggleReverseGeocodeActive,+ setPlaceMarker, toggleDialogVisible, toggleReverseGeocodeActive,} from '../../modules/geosearch/actions';import { areCoordinatesWithinExtent } from '../../modules/geosearch/util';import { reverseGeocode } from '../../modules/geosearch/util-api';@@ -60,14 +60,8 @@ export class CoordinatesMarker extends Component {}const hasFeatures = map.hasFeatureAtPixel(pixels);if (hasFeatures && !isShowingClick && !measureIsActive) {- let isActiveLayer = false;- map.forEachFeatureAtPixel(pixels, (feature) => {- const featureId = feature.getId();- const isMarker = featureId === 'coordinates-map-marker';- if (isMarker) {- isActiveLayer = true;- }- });+ const featureCheck = (feature) => feature.getId() === 'coordinates-map-marker';+ const isActiveLayer = map.forEachFeatureAtPixel(pixels, featureCheck);if (isActiveLayer) {changeCursor(true);}@@ -93,9 +87,9 @@ export class CoordinatesMarker extends Component {singleclick(e, map) {const {config,- measureIsActive,- selectCoordinatesToFly,isCoordinateSearchActive,+ measureIsActive,+ setPlaceMarker,toggleReverseGeocodeActive,} = this.props;const {@@ -116,7 +110,7 @@ export class CoordinatesMarker extends Component {}// get available reverse geocoding for coordinates and fly to pointreverseGeocode([longitude, latitude], config).then((results) => {- selectCoordinatesToFly([longitude, latitude], results);+ setPlaceMarker([longitude, latitude], results);});this.setState({ showExtentAlert: false });} else {@@ -129,12 +123,13 @@ export class CoordinatesMarker extends Component {getCoordinatesDialog = (pixels, olMap) => {const {- config,- clearCoordinates,- isMobile,toggleDialogVisible,} = this.props;- getCoordinatesDialogAtMapPixel(pixels, olMap, config, isMobile, clearCoordinates, toggleDialogVisible);+ const isMarker = isCoordinatesDialogAvailableAtPixel(pixels, olMap);++ if (isMarker) {+ toggleDialogVisible(true);+ }}// render geosearch extent alert for selecting points outside of the current map extent@@ -154,9 +149,7 @@ export class CoordinatesMarker extends Component {render() {const { showExtentAlert } = this.state;- return showExtentAlert- ? this.renderExtentAlert()- : null;+ return showExtentAlert && this.renderExtentAlert();}}@@ -183,32 +176,27 @@ function mapStateToProps(state) {}const mapDispatchToProps = (dispatch) => ({- selectCoordinatesToFly: (coordinates, reverseGeocodeResults) => {- dispatch(selectCoordinatesToFly(coordinates, reverseGeocodeResults));- },- toggleReverseGeocodeActive: (isActive) => {- dispatch(toggleReverseGeocodeActive(isActive));- },changeCursor: (bool) => {dispatch(changeCursorActionCreator(bool));},- clearCoordinates: () => {- dispatch(clearCoordinates());+ setPlaceMarker: (coordinates, reverseGeocodeResults) => {+ dispatch(setPlaceMarker(coordinates, reverseGeocodeResults));},toggleDialogVisible: (isVisible) => {dispatch(toggleDialogVisible(isVisible));},+ toggleReverseGeocodeActive: (isActive) => {+ dispatch(toggleReverseGeocodeActive(isActive));+ },});CoordinatesMarker.propTypes = {changeCursor: PropTypes.func.isRequired,config: PropTypes.object.isRequired,- clearCoordinates: PropTypes.func.isRequired,isCoordinateSearchActive: PropTypes.bool.isRequired,- isMobile: PropTypes.bool.isRequired,isShowingClick: PropTypes.bool.isRequired,measureIsActive: PropTypes.bool.isRequired,mouseEvents: PropTypes.object.isRequired,- selectCoordinatesToFly: PropTypes.func.isRequired,+ setPlaceMarker: PropTypes.func.isRequired,toggleDialogVisible: PropTypes.func.isRequired,toggleReverseGeocodeActive: PropTypes.func.isRequired,};diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.jsindex fd27fbc28..ed833e439 100644--- a/web/js/containers/image-download.js+++ b/web/js/containers/image-download.js@@ -16,7 +16,6 @@ import {hasSubDaily as hasSubDailySelector,getLayers,} from '../modules/layers/selectors';-import { removeCoordinatesOverlayFromAllProjections } from '../modules/geosearch/util';import {resolutionsGeo,resolutionsPolar,@@ -180,11 +179,6 @@ function mapStateToProps(state) {util.warn(`Redirecting image download to: ${url}`);}- if (markerCoordinates.length > 0) {- // clear coordinates dialog for image crop panel- removeCoordinatesOverlayFromAllProjections(map.ui.proj);- }-return {proj,url,diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.jsindex 63032a355..4366a8bd5 100644--- a/web/js/containers/toolbar.js+++ b/web/js/containers/toolbar.js@@ -30,9 +30,8 @@ import { notificationWarnings } from '../modules/image-download/constants';import Notify from '../components/image-download/notify';import { hasCustomPaletteInActiveProjection } from '../modules/palettes/util';import { getLayers } from '../modules/layers/selectors';-// GeoSearchimport Geosearch from '../components/geosearch/geosearch';-import { toggleShowGeosearch } from '../modules/geosearch/actions';+import { toggleShowGeosearch, toggleDialogVisible } from '../modules/geosearch/actions';Promise.config({ cancellation: true });@@ -102,10 +101,18 @@ class toolbarContainer extends Component {async openImageDownload() {const {- openModal, hasCustomPalette, isRotated, hasGraticule, activePalettes, rotation, refreshStateAfterImageDownload,+ openModal,+ hasCustomPalette,+ isRotated,+ hasGraticule,+ activePalettes,+ rotation,+ refreshStateAfterImageDownload,+ toggleDialogVisible,} = this.props;const paletteStore = lodashCloneDeep(activePalettes);+ toggleDialogVisible(false);await this.getPromise(hasCustomPalette, 'palette', clearCustoms, 'Notice');await this.getPromise(isRotated, 'rotate', clearRotate, 'Reset rotation');await this.getPromise(hasGraticule, 'graticule', clearGraticule, 'Remove Graticule?');@@ -389,6 +396,9 @@ const mapDispatchToProps = (dispatch) => ({toggleDistractionFreeMode: () => {dispatch(toggleDistractionFreeMode());},+ toggleDialogVisible: (isVisible) => {+ dispatch(toggleDialogVisible(isVisible));+ },toggleShowGeosearch: () => {dispatch(toggleShowGeosearch());},@@ -468,5 +478,6 @@ toolbarContainer.propTypes = {requestNotifications: PropTypes.func,rotation: PropTypes.number,shouldBeCollapsed: PropTypes.bool,+ toggleDialogVisible: PropTypes.func,toggleShowGeosearch: PropTypes.func,};diff --git a/web/js/map/ui.js b/web/js/map/ui.jsindex 79a257ef1..7ae591e8e 100644--- a/web/js/map/ui.js+++ b/web/js/map/ui.js@@ -34,7 +34,12 @@ import { mapUtilZoomAction, getActiveLayerGroup } from './util';import mapCompare from './compare/compare';import { LOCATION_POP_ACTION } from '../redux-location-state-customs';import { CHANGE_PROJECTION } from '../modules/projection/constants';-import { CLEAR_MARKER, SET_MARKER, TOGGLE_DIALOG_VISIBLE } from '../modules/geosearch/constants';+import {+ CLEAR_MARKER,+ SET_MARKER,+ SET_REVERSE_GEOCODE_RESULTS,+ TOGGLE_DIALOG_VISIBLE,+} from '../modules/geosearch/constants';import { SELECT_DATE } from '../modules/date/constants';import util from '../util/util';import * as layerConstants from '../modules/layers/constants';@@ -45,6 +50,7 @@ import { setStyleFunction } from '../modules/vector-styles/selectors';import {getLayers,isRenderable as isRenderableLayer,+ getMaxZoomLevelLayerCollection,} from '../modules/layers/selectors';import { EXIT_ANIMATION, STOP_ANIMATION } from '../modules/animation/constants';import {@@ -55,7 +61,7 @@ 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, removeCoordinatesMarker } from '../modules/geosearch/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';@@ -94,6 +100,7 @@ export default function mapui(models, config, store, ui) {const createLayer = self.createLayer = layerBuilder.createLayer;self.promiseDay = precache.promiseDay;self.selectedVectors = {};+ self.activeMarker = null;/*** Suscribe to redux store and listen for* specific action types@@ -104,6 +111,18 @@ export default function mapui(models, config, store, ui) {const def = lodashFind(action.layers, { id: action.id });return addLayer(def);}+ case CLEAR_MARKER:+ return removeCoordinatesMarker();+ case SET_MARKER:+ return addMarkerAndUpdateStore(null, true);+ case TOGGLE_DIALOG_VISIBLE: {+ if (action.value) {+ addCoordinatesTooltip();+ } else {+ removeCoordinatesTooltip();+ }+ return;+ }case CLEAR_ROTATE:return rotation.reset(self.selected);case REFRESH_ROTATE:@@ -211,65 +230,139 @@ export default function mapui(models, config, store, ui) {const handleActiveMapMarker = () => {const state = store.getState();const { geosearch } = state;- const { activeMarker, coordinates } = geosearch;+ const { coordinates } = geosearch;if (coordinates && coordinates.length > 0) {reverseGeocode(coordinates, config).then((results) => {- addMarkerAndUpdateStore(activeMarker, coordinates, results);+ addMarkerAndUpdateStore(results);});}};/*- * Add map coordinate marker and update store+ * Remove coordinates tooltip from all projections*- * @method addMarkerAndUpdateStore+ * @method removeCoordinatesTooltip* @static*- * @param {Object} activeMarker- * @param {Array} coordinates- * @param {Object} results- ** @returns {void}*/- const addMarkerAndUpdateStore = (activeMarker, coordinates, results) => {- const state = store.getState();- const { browser, geosearch } = state;- const isMobile = browser.lessThan.medium;- const marker = addCoordinatesMarker(activeMarker, config, { ui: self }, coordinates, results);- const { isCoordinatesDialogOpen } = geosearch;+ const removeCoordinatesTooltip = () => {+ const mapProjections = Object.keys(self.proj);+ mapProjections.forEach((mapProjection) => {+ const mapOverlays = self.proj[mapProjection].getOverlays().getArray();+ const coordinatesTooltipOverlay = mapOverlays.filter((overlay) => {+ const { id } = overlay;+ return id && id.includes('coordinates-map-marker');+ });+ if (coordinatesTooltipOverlay.length > 0) {+ self.proj[mapProjection].removeOverlay(coordinatesTooltipOverlay[0]);+ }+ });+ };- // prevent marker if outside of extent- if (!marker) {- return false;+ /*+ * Remove coordinates marker+ *+ * @method removeCoordinatesMarker+ * @static+ *+ * @returns {void}+ */+ const removeCoordinatesMarker = () => {+ if (self.activeMarker) {+ self.activeMarker.setMap(null);+ self.selected.removeLayer(self.activeMarker);}+ // remove tooltip from all projections+ removeCoordinatesTooltip();+ };- // handle render initial tooltip+ /*+ * Add map marker coordinate tooltip+ *+ * @method addCoordinatesTooltip+ * @static+ *+ * @param {Object} geocodeResults+ *+ * @returns {void}+ */+ const addCoordinatesTooltip = (geocodeResults) => {+ const state = store.getState();+ const {+ browser, geosearch,+ } = state;+ const { coordinates, reverseGeocodeResults } = geosearch;+ const results = geocodeResults || reverseGeocodeResults;+ const isMobile = browser.lessThan.medium;const [longitude, latitude] = coordinates;const geocodeProperties = { latitude, longitude, reverseGeocodeResults: results };const coordinatesMetadata = getCoordinatesMetadata(geocodeProperties);// handle clearing cooridnates using created markerconst clearMarker = () => {- removeCoordinatesMarker(marker, { ui: self });store.dispatch({ type: CLEAR_MARKER });};// handle toggling dialog visibility to retain preference between proj changesconst toggleDialogVisible = (isVisible) => {store.dispatch({ type: TOGGLE_DIALOG_VISIBLE, value: isVisible });};+ renderCoordinatesTooltip(self.selected, config, [latitude, longitude], coordinatesMetadata, isMobile, clearMarker, toggleDialogVisible);+ };- // only render dialog if new marker or not previously minimized- const isDialogOpen = !activeMarker || (activeMarker && isCoordinatesDialogOpen);+ /*+ * Add map coordinate marker and update store+ *+ * @method addMarkerAndUpdateStore+ * @static+ *+ * @param {Object} geocodeResults+ * @param {Boolean} isInit+ *+ * @returns {void}+ */+ const addMarkerAndUpdateStore = (geocodeResults, isInit) => {+ const state = store.getState();+ const {+ geosearch, layers, proj,+ } = state;+ const {+ coordinates, isCoordinatesDialogOpen, reverseGeocodeResults,+ } = geosearch;+ const results = geocodeResults || reverseGeocodeResults;+ const { sources } = config;+ const { active } = layers;++ // clear previous marker (if present) and get new marker+ removeCoordinatesMarker();+ const marker = getCoordinatesMarker({ ui: self }, config, coordinates, results);++ // prevent marker if outside of extent+ if (!marker) {+ return false;+ }++ self.activeMarker = marker;+ self.selected.addLayer(marker);+ self.selected.renderSync();++ if (isInit) {+ // fly to coordinates and render coordinates tooltip on init SET_MARKER+ const zoom = self.selected.getView().getZoom();+ const activeLayers = active.filter((layer) => layer.projections[proj.id] !== undefined);+ const maxZoom = getMaxZoomLevelLayerCollection(activeLayers, zoom, proj.id, sources);+ animateCoordinates({ ui: self }, config, coordinates, maxZoom);+ }++ // handle render initial tooltip+ const isDialogOpen = isInit || isCoordinatesDialogOpen;if (isDialogOpen) {- renderCoordinatesTooltip(self.selected, config, [latitude, longitude], coordinatesMetadata, isMobile, clearMarker, toggleDialogVisible);+ addCoordinatesTooltip(results);}store.dispatch({- type: SET_MARKER,- coordinates,- value: marker,- reverseGeocodeResults: results,- isCoordinatesDialogOpen: isDialogOpen,+ type: SET_REVERSE_GEOCODE_RESULTS,+ value: results,});};@@ -451,11 +544,10 @@ export default function mapui(models, config, store, ui) {const reloadLayers = self.reloadLayers = function(map) {map = map || self.selected;const state = store.getState();- const { geosearch, layers, proj } = state;+ const { layers, proj } = state;const compareState = state.compare;const layerGroupStr = compareState.activeString;const activeLayers = layers[layerGroupStr];- const { activeMarker, coordinates, reverseGeocodeResults } = geosearch;if (!config.features.compare || !compareState.active) {const compareMapDestroyed = !compareState.active && compareMapUi.active;if (compareMapDestroyed) {@@ -473,8 +565,8 @@ export default function mapui(models, config, store, ui) {map.addLayer(createLayer(def));});// add active map marker back after destroying from layer/compare change- if (activeMarker) {- addMarkerAndUpdateStore(activeMarker, coordinates, reverseGeocodeResults);+ if (self.activeMarker) {+ addMarkerAndUpdateStore();}} else {const stateArray = [['active', 'selected'], ['activeB', 'selectedB']];@@ -491,8 +583,8 @@ export default function mapui(models, config, store, ui) {});compareMapUi.create(map, compareState.mode);// add active map marker back in compare mode post createLayer- if (activeMarker) {- addMarkerAndUpdateStore(activeMarker, coordinates, reverseGeocodeResults);+ if (self.activeMarker) {+ addMarkerAndUpdateStore();}}updateLayerVisibilities();diff --git a/web/js/modules/geosearch/actions.js b/web/js/modules/geosearch/actions.jsindex b391da6fe..02901f231 100644--- a/web/js/modules/geosearch/actions.js+++ b/web/js/modules/geosearch/actions.js@@ -9,19 +9,12 @@ import {} from './constants';import { requestAction } from '../core/actions';import {- addCoordinatesMarker,- animateCoordinates,- removeCoordinatesMarker,+ areCoordinatesWithinExtent,setLocalStorageCollapseState,} from './util';import {GEOSEARCH_REQUEST_OPTIONS,} from './util-api';-import {- getCoordinatesMetadata,- renderCoordinatesTooltip,-} from '../../components/geosearch/ol-coordinates-marker-util';-import { getMaxZoomLevelLayerCollection } from '../layers/selectors';const {REQUEST_OPTIONS,@@ -29,7 +22,9 @@ const {CONSTANT_REQUEST_PARAMETERS,} = GEOSEARCH_REQUEST_OPTIONS;-// toggle show geosearch component+/**+ * Toggle show geosearch component+ */export function toggleShowGeosearch() {return (dispatch, getState) => {const state = getState();@@ -47,25 +42,28 @@ export function toggleShowGeosearch() {};}-// toggle reverse geocode - if active, next click on map will add marker and get coordinates-export function toggleReverseGeocodeActive(isCoordinateSearchActive) {+/**+ * Toggle reverse geocode+ * @param {Boolean} isActive+ */+export function toggleReverseGeocodeActive(isActive) {return {type: TOGGLE_REVERSE_GEOCODE,- value: isCoordinateSearchActive,+ value: isActive,};}-// use given coordinates to fly to that point, add marker, and display initial coordinates dialog-export function selectCoordinatesToFly(coordinates, reverseGeocodeResults) {+/**+ * Set coordinates and reverse geocode results for place+ * @param {Array} coordinates+ * @param {Object} reverseGeocodeResults+ */+export function setPlaceMarker(coordinates, reverseGeocodeResults) {return (dispatch, getState) => {const state = getState();const {- browser, config, geosearch, map, layers, proj,+ config, map,} = state;- const { sources } = config;- const { active } = layers;- const { activeMarker } = geosearch;- const isMobile = browser.lessThan.medium;if (reverseGeocodeResults) {const { error } = reverseGeocodeResults;@@ -74,71 +72,39 @@ export function selectCoordinatesToFly(coordinates, reverseGeocodeResults) {}}- const marker = addCoordinatesMarker(activeMarker, config, map, coordinates, reverseGeocodeResults);- if (!marker) {+ const coordinatesWithinExtent = areCoordinatesWithinExtent(map, config, coordinates);+ if (!coordinatesWithinExtent) {return dispatch({type: SET_MARKER,- value: null,coordinates: [],isCoordinatesDialogOpen: false,});}- // fly to coordinates and render coordinates tooltip- const zoom = map.ui.selected.getView().getZoom();- const activeLayers = active.filter((layer) => layer.projections[proj.id] !== undefined);- const maxZoom = getMaxZoomLevelLayerCollection(activeLayers, zoom, proj.id, sources);- animateCoordinates(map, config, coordinates, maxZoom);-- // handle render initial tooltip- const [longitude, latitude] = coordinates;- const geocodeProperties = {- latitude,- longitude,- reverseGeocodeResults,- };- const coordinatesMetadata = getCoordinatesMetadata(geocodeProperties);- const clearMarker = () => {- removeCoordinatesMarker(marker, map);- dispatch({- type: CLEAR_MARKER,- });- };- const toggleDialog = (isVisible) => {- dispatch({- type: TOGGLE_DIALOG_VISIBLE,- value: isVisible,- });- };- renderCoordinatesTooltip(map.ui.selected, config, [latitude, longitude], coordinatesMetadata, isMobile, clearMarker, toggleDialog);-dispatch({type: SET_MARKER,reverseGeocodeResults,coordinates,- value: marker,isCoordinatesDialogOpen: true,});};}-// clear coordinates including marker and dialog (if open), adding new marker will clear any active marker+/**+ * Clear coordinates including marker and dialog (if open)+ */export function clearCoordinates() {- return (dispatch, getState) => {- const state = getState();- const { map, geosearch } = state;- const { activeMarker } = geosearch;-- if (activeMarker) {- removeCoordinatesMarker(activeMarker, map);- }+ return (dispatch) => {dispatch({type: CLEAR_MARKER,});};}-// clear place suggestions+/**+ * Toggle show coordinates dialog+ * @param {Boolean} isVisible+ */export function toggleDialogVisible(isVisible) {return (dispatch) => {dispatch({@@ -148,7 +114,9 @@ export function toggleDialogVisible(isVisible) {};}-// clear place suggestions+/**+ * Clear place suggestions+ */export function clearSuggestions() {return (dispatch) => {dispatch({@@ -158,7 +126,10 @@ export function clearSuggestions() {};}-// set place suggestion+/**+ * Set place suggestion+ * @param {Array} suggestion | suggestion object+ */export function setSuggestion(suggestion) {return (dispatch) => {dispatch({@@ -168,7 +139,10 @@ export function setSuggestion(suggestion) {};}-// get place suggestions using ArcGIS suggest API+/**+ * Get place suggestions using ArcGIS suggest API+ * @param {String} val | input text to suggest places+ */export function getSuggestions(val) {return (dispatch, getState) => {const { config } = getState();@@ -176,7 +150,7 @@ export function getSuggestions(val) {const encodedValue = encodeURIComponent(val);const encodedCategories = encodeURIComponent(GEOCODE_SUGGEST_CATEGORIES.join(','));- const request = `${requestUrl}suggest?text=${encodedValue}${CONSTANT_REQUEST_PARAMETERS}&category=${encodedCategories}`;+ const request = `${requestUrl}suggest?${CONSTANT_REQUEST_PARAMETERS}&text=${encodedValue}&category=${encodedCategories}`;return requestAction(dispatch,diff --git a/web/js/modules/geosearch/constants.js b/web/js/modules/geosearch/constants.jsindex abd68857c..292adcaed 100644--- a/web/js/modules/geosearch/constants.js+++ b/web/js/modules/geosearch/constants.js@@ -2,6 +2,7 @@ export const CLEAR_MARKER = 'GEOSEARCH/CLEAR_MARKER';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 SET_REVERSE_GEOCODE_RESULTS = 'GEOSEARCH/SET_REVERSE_GEOCODE_RESULTS';export const SET_MARKER = 'GEOSEARCH/SET_MARKER';export const SET_SUGGESTION = 'GEOSEARCH/SET_SUGGESTION';export const TOGGLE_DIALOG_VISIBLE = 'GEOSEARCH/TOGGLE_DIALOG_VISIBLE';diff --git a/web/js/modules/geosearch/reducers.js b/web/js/modules/geosearch/reducers.jsindex 8c85e9388..1ead7e82e 100644--- a/web/js/modules/geosearch/reducers.js+++ b/web/js/modules/geosearch/reducers.js@@ -3,6 +3,7 @@ import {CLEAR_SUGGESTIONS,REQUEST_SUGGEST_PLACE_FAILURE,REQUEST_SUGGEST_PLACE_SUCCESS,+ SET_REVERSE_GEOCODE_RESULTS,SET_MARKER,SET_SUGGESTION,TOGGLE_DIALOG_VISIBLE,@@ -13,7 +14,6 @@ import { getLocalStorageCollapseState } from './util';const localStorageCollapseState = getLocalStorageCollapseState();export const geosearchState = {- activeMarker: null,coordinates: [],isCoordinateSearchActive: false,isCoordinatesDialogOpen: false,@@ -39,10 +39,14 @@ export function geosearchReducer(state = geosearchState, action) {...state,isCoordinateSearchActive: action.value,};+ case SET_REVERSE_GEOCODE_RESULTS:+ return {+ ...state,+ reverseGeocodeResults: action.value,+ };case SET_MARKER:return {...state,- activeMarker: action.value,coordinates: action.coordinates,isCoordinateSearchActive: false,reverseGeocodeResults: action.reverseGeocodeResults,@@ -51,7 +55,6 @@ export function geosearchReducer(state = geosearchState, action) {case CLEAR_MARKER:return {...state,- activeMarker: null,coordinates: [],reverseGeocodeResults: null,isCoordinatesDialogOpen: false,diff --git a/web/js/modules/geosearch/reducers.test.js b/web/js/modules/geosearch/reducers.test.jsindex cd7bbec47..345df1a1c 100644--- a/web/js/modules/geosearch/reducers.test.js+++ b/web/js/modules/geosearch/reducers.test.js@@ -80,13 +80,12 @@ describe('geosearchReducer', () => {);test(`${SET_MARKER- } updates activeMarker, coordinates, reverseGeocodeResults `+ } updates coordinates, reverseGeocodeResults `+ 'and sets isCoordinateSearchActive to false and should return new state',() => {expect(geosearchReducer(geosearchState, {type: SET_MARKER,- value: {},coordinates,reverseGeocodeResults,isCoordinatesDialogOpen: true,@@ -95,7 +94,6 @@ describe('geosearchReducer', () => {...geosearchState,isCoordinateSearchActive: false,coordinates,- activeMarker: {},reverseGeocodeResults,isCoordinatesDialogOpen: true,});@@ -103,7 +101,7 @@ describe('geosearchReducer', () => {);test(`${CLEAR_MARKER- } resets cooridnates, activeMarker, and geocode results`+ } resets cooridnates and geocode results`+ 'should return new state',() => {expect(@@ -113,7 +111,6 @@ describe('geosearchReducer', () => {).toEqual({...geosearchState,coordinates: [],- activeMarker: null,reverseGeocodeResults: null,isCoordinatesDialogOpen: false,});diff --git a/web/js/modules/geosearch/util-api.js b/web/js/modules/geosearch/util-api.jsindex 0721c5292..d3bc6c4d0 100644--- a/web/js/modules/geosearch/util-api.js+++ b/web/js/modules/geosearch/util-api.js@@ -22,7 +22,7 @@ export const GEOSEARCH_REQUEST_OPTIONS = {'Airport',],// language code EN (English) and required f request format parameters- CONSTANT_REQUEST_PARAMETERS: '&langCode=en&f=json',+ CONSTANT_REQUEST_PARAMETERS: 'f=json&langCode=en',};const {@@ -30,9 +30,13 @@ const {CONSTANT_REQUEST_PARAMETERS,} = GEOSEARCH_REQUEST_OPTIONS;+/**+ * @param {String} magicKey+ * @param {Object} config+ */export async function processMagicKey(magicKey, config) {const { features: { geocodeSearch: { url: requestUrl } } } = config;- const request = `${requestUrl}findAddressCandidates?outFields=*${CONSTANT_REQUEST_PARAMETERS}&magicKey=${magicKey}=`;+ const request = `${requestUrl}findAddressCandidates?${CONSTANT_REQUEST_PARAMETERS}&outFields=*&magicKey=${magicKey}=`;try {const response = await fetch(request, REQUEST_OPTIONS);@@ -43,9 +47,13 @@ export async function processMagicKey(magicKey, config) {}}+/**+ * @param {Array} coordinates+ * @param {Object} config+ */export async function reverseGeocode(coordinates, config) {const { features: { geocodeSearch: { url: requestUrl } } } = config;- const request = `${requestUrl}reverseGeocode?location=${coordinates}${CONSTANT_REQUEST_PARAMETERS}`;+ const request = `${requestUrl}reverseGeocode?${CONSTANT_REQUEST_PARAMETERS}&location=${coordinates}`;try {const response = await fetch(request, REQUEST_OPTIONS);diff --git a/web/js/modules/geosearch/util.js b/web/js/modules/geosearch/util.jsindex 1ac99c716..01b5ba434 100644--- a/web/js/modules/geosearch/util.js+++ b/web/js/modules/geosearch/util.js@@ -14,7 +14,13 @@ import safeLocalStorage from '../../util/local-storage';const { GEOSEARCH_COLLAPSED } = safeLocalStorage.keys;-// animate coordinates marker+/**+ * Animate coordinates marker+ * @param {Object} map+ * @param {Object} config+ * @param {Array} coordinates+ * @param {Number} zoom+ */export function animateCoordinates(map, config, coordinates, zoom) {const { projections } = config;const { selected } = map.ui;@@ -28,7 +34,12 @@ export function animateCoordinates(map, config, coordinates, zoom) {map.ui.animate.fly([x, y], zoom);}-// check if coordinates are within selected map extent+/**+ * Check if coordinates are within selected map extent+ * @param {Object} map+ * @param {Object} config+ * @param {Array} coordinates+ */export function areCoordinatesWithinExtent(map, config, coordinates) {const { projections } = config;const { selected } = map.ui;@@ -44,16 +55,19 @@ export function areCoordinatesWithinExtent(map, config, coordinates) {return coordinatesWithinExtent;}-// add coordinates marker-export function addCoordinatesMarker(activeMarker, config, map, coordinates, reverseGeocodeResults) {+/**+ * Get coordinates marker+ * @param {Object} map+ * @param {Object} config+ * @param {Array} coordinates+ * @param {Object} reverseGeocodeResults+ */+export function getCoordinatesMarker(map, config, coordinates, reverseGeocodeResults) {const { projections } = config;const { selected } = map.ui;const { proj } = selected;const { crs } = projections[proj];- // remove any markers- removeCoordinatesMarker(activeMarker, map);-// only add marker within current map extentconst coordinatesWithinExtent = areCoordinatesWithinExtent(map, config, coordinates);if (!coordinatesWithinExtent) {@@ -68,39 +82,15 @@ export function addCoordinatesMarker(activeMarker, config, map, coordinates, rev// create Ol vector layer map pinconst marker = createPin(coordinates, transformedCoordinates, reverseGeocodeResults);- selected.addLayer(marker);- selected.renderSync();return marker;}-// remove coordinates tooltip from all projections-export function removeCoordinatesOverlayFromAllProjections(proj) {- const mapProjections = Object.keys(proj);- mapProjections.forEach((mapProjection) => {- const mapOverlays = proj[mapProjection].getOverlays().getArray();- const coordinatesTooltipOverlay = mapOverlays.filter((overlay) => {- const { id } = overlay;- return id && id.includes('coordinates-map-marker');- });- if (coordinatesTooltipOverlay.length > 0) {- proj[mapProjection].removeOverlay(coordinatesTooltipOverlay[0]);- }- });-}--// remove coordinates marker-export function removeCoordinatesMarker(activeMarker, map) {- const { selected, proj } = map.ui;- // remove marker- if (activeMarker) {- activeMarker.setMap(null);- selected.removeLayer(activeMarker);- }- // remove tooltip from all projections- removeCoordinatesOverlayFromAllProjections(proj);-}--// create Ol vector layer map pin+/**+ * Create Ol vector layer map pin+ * @param {Array} coordinates+ * @param {Array} transformedCoordinates+ * @param {Object} reverseGeocodeResults+ */const createPin = function(coordinates, transformedCoordinates = false, reverseGeocodeResults = {}) {const [longitude, latitude] = coordinates;const iconFeature = new OlFeature({@@ -136,8 +126,9 @@ const createPin = function(coordinates, transformedCoordinates = false, reverseG/***- * @param {*} parameters- * @param {*} stateFromLocation+ * @param {Object} parameters+ * @param {Object} stateFromLocation+ * @param {Object} state*/export function mapLocationToGeosearchState(parameters,@@ -150,7 +141,8 @@ export function mapLocationToGeosearchState(.map((coord) => Number(coord)).filter((coord) => !lodashIsNaN(parseFloat(coord))): [];- const coordinates = validCoordinates.length === 2+ const isValid = validCoordinates.length === 2;+ const coordinates = isValid? validCoordinates: [];@@ -162,6 +154,7 @@ export function mapLocationToGeosearchState(geosearch: {coordinates: { $set: coordinates },isExpanded: { $set: isExpanded },+ isCoordinatesDialogOpen: { $set: isValid },},});