Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add ol coordinates marker component, helper function for map cursor classes

Ed Plato84ba566a35c5
diff --git a/web/css/timeline.css b/web/css/timeline.css
index aa7d20461..02c791fd9 100644
--- a/web/css/timeline.css
+++ b/web/css/timeline.css
@@ -801,7 +801,7 @@ button:focus {
}
.wv-toggle-data-matching-main .react-switch-case {
- width: 45px;
+ width: 35px;
}
.wv-toggle-data-matching-main > div.react-switch-label-case.switch-col {
diff --git a/web/js/components/geosearch/coordinates-dialog.js b/web/js/components/geosearch/coordinates-dialog.js
new file mode 100644
index 000000000..c7caa5d9e
--- /dev/null
+++ b/web/js/components/geosearch/coordinates-dialog.js
@@ -0,0 +1,43 @@
+/* eslint-disable no-restricted-syntax */
+import React, { PureComponent } from 'react';
+import PropTypes from 'prop-types';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { faTimes } from '@fortawesome/free-solid-svg-icons';
+
+class CoordinatesDialog extends PureComponent {
+ render() {
+ const {
+ toggleWithClose, coordinatesMetadata,
+ } = this.props;
+
+ const {
+ features, // { latitude, longitude }
+ title, // "Wairau Valley"
+ } = coordinatesMetadata;
+
+ const latitudeText = `Latitude: ${features.latitude} °`;
+ const longitudeText = `Longitude: ${features.longitude} °`;
+ return (
+ <div className="tooltip-custom-black tooltip-static">
+ <div className="tooltip-coordinates-title">{title}</div>
+ <div className="tooltip-coordinates-group">
+ <div>
+ {latitudeText}
+ </div>
+ <div>
+ {longitudeText}
+ </div>
+ </div>
+ <span className="close-tooltip coordinates-dialog-close" onClick={toggleWithClose}>
+ <FontAwesomeIcon icon={faTimes} fixedWidth />
+ </span>
+ </div>
+ );
+ }
+}
+
+export default CoordinatesDialog;
+CoordinatesDialog.propTypes = {
+ toggleWithClose: PropTypes.func,
+ coordinatesMetadata: PropTypes.object,
+};
diff --git a/web/js/components/geosearch/geosearch-input.js b/web/js/components/geosearch/geosearch-input.js
index e00f172ca..91847df91 100644
--- a/web/js/components/geosearch/geosearch-input.js
+++ b/web/js/components/geosearch/geosearch-input.js
@@ -82,6 +82,7 @@ class SearchBox extends Component {
coordinates, inputValue, isMobile,
} = this.props;
const hasCoordinates = coordinates.length > 0;
+ // eslint-disable-next-line no-nested-ternary
const buttonContainerRight = hasCoordinates
? isMobile ? '67px' : '62px'
: '31px';
diff --git a/web/js/components/geosearch/ol-coordinates-marker-util.js b/web/js/components/geosearch/ol-coordinates-marker-util.js
new file mode 100644
index 000000000..cac6578b9
--- /dev/null
+++ b/web/js/components/geosearch/ol-coordinates-marker-util.js
@@ -0,0 +1,138 @@
+/* eslint-disable no-restricted-syntax */
+/* eslint-disable no-nested-ternary */
+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';
+
+/**
+ * Get parsed precision coordinate number
+ * @param {String} coordinate
+ * @returns {Number} parsed coordinate with modified precision
+ */
+function getCoordinateDisplayPrecision(coordinate) {
+ const coordinateNumber = Number(coordinate);
+ const coordinatePrecision = Math.abs(coordinateNumber) > 100
+ ? 7
+ : coordinateNumber < 0
+ ? 7
+ : 6;
+
+ return parseFloat(coordinateNumber.toPrecision(coordinatePrecision));
+}
+
+/**
+ * Create tooltip React DOM element
+ *
+ * @param {Object} map
+ * @param {Array} coordinates
+ * @param {Object} coordinatesMetadata
+ *
+ * @returns {Void}
+ */
+function renderTooltip(map, coordinates, coordinatesMetadata) {
+ const { proj } = map;
+ const [latitude, longitude] = coordinates;
+
+ // create tooltip overlay
+ const tooltipElement = document.createElement('div');
+ const tooltipId = `coordinates-map-maker-${latitude},${longitude}`;
+ const tooltipOverlay = new Overlay({
+ id: tooltipId,
+ element: tooltipElement,
+ offset: [0, -40],
+ positioning: 'bottom-center',
+ stopEvent: false,
+ });
+
+ // transform polar projections coordinates
+ let coordinatesPosition;
+ if (proj === 'geographic') {
+ coordinatesPosition = [longitude, latitude];
+ } else {
+ const transformedCoordinates = polarCoordinatesTransform([longitude, latitude], map.proj);
+ coordinatesPosition = transformedCoordinates;
+ }
+
+ // add tooltip overlay to map and position based on marker coordinates
+ map.addOverlay(tooltipOverlay);
+ tooltipOverlay.setPosition(coordinatesPosition);
+
+ // helper function to remove tooltip overlay
+ const removeTooltip = () => {
+ map.removeOverlay(tooltipOverlay);
+ };
+
+ ReactDOM.render((
+ <CoordinatesDialog
+ coordinatesMetadata={coordinatesMetadata}
+ toggleWithClose={removeTooltip}
+ />
+ ), tooltipOverlay.getElement());
+}
+
+/**
+ * Get coordinate dialog feature at clicked map pixel
+ *
+ * @param {Array} pixels
+ * @param {Object} map
+ *
+ * @returns {Void}
+ */
+export default function getCoordinatesDialogAtMapPixel(pixels, map) {
+ // 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');
+ });
+ if (coordinatesTooltipOverlay.length > 0) {
+ return;
+ }
+
+ map.forEachFeatureAtPixel(pixels, (feature) => {
+ const featureId = feature.getId();
+ if (featureId === 'coordinates-map-maker') {
+ const featureProperties = feature.getProperties();
+
+ const { latitude, longitude, reverseGeocodeResults } = featureProperties;
+ const { address, error } = reverseGeocodeResults;
+
+ const parsedLatitude = getCoordinateDisplayPrecision(latitude);
+ const parsedLongitude = getCoordinateDisplayPrecision(longitude);
+
+ // build title and metadata based on available parameters
+ let title;
+ if (error) {
+ title = `${parsedLatitude}, ${parsedLongitude}`;
+ } else if (address) {
+ /* eslint-disable camelcase */
+ const {
+ Addr_type,
+ Match_addr,
+ ShortLabel,
+ City,
+ Region,
+ } = address;
+ if (Addr_type === 'PointAddress') {
+ title = `${ShortLabel}, ${City}, ${Region}`;
+ } else if (City && Region) {
+ title = `${City}, ${Region}`;
+ } else {
+ title = `${Match_addr}`;
+ }
+ }
+ const coordinatesMetadata = {
+ features: {
+ latitude: parsedLatitude,
+ longitude: parsedLongitude,
+ },
+ title,
+ };
+
+ // create tooltip overlay React DOM element
+ renderTooltip(map, [latitude, longitude], coordinatesMetadata);
+ }
+ });
+}
diff --git a/web/js/components/geosearch/ol-coordinates-marker.js b/web/js/components/geosearch/ol-coordinates-marker.js
new file mode 100644
index 000000000..a5e5361bc
--- /dev/null
+++ b/web/js/components/geosearch/ol-coordinates-marker.js
@@ -0,0 +1,102 @@
+import { connect } from 'react-redux';
+import {
+ debounce as lodashDebounce,
+} from 'lodash';
+import React from 'react';
+import PropTypes from 'prop-types';
+import { transform } from 'ol/proj';
+import { changeCursor as changeCursorActionCreator } from '../../modules/map/actions';
+import getCoordinatesDialogAtMapPixel from './ol-coordinates-marker-util';
+
+export class CoordinatesInteractions extends React.Component {
+ constructor(props) {
+ super(props);
+ this.mouseMove = lodashDebounce(this.mouseMove.bind(this), 8);
+ this.singleClick = this.singleClick.bind(this);
+ this.registerMouseListeners();
+ }
+
+ registerMouseListeners() {
+ const { mouseEvents } = this.props;
+ mouseEvents.on('mousemove', this.mouseMove);
+ mouseEvents.on('singleclick', this.singleClick);
+ }
+
+ mouseMove(event, map, crs) {
+ const pixels = map.getEventPixel(event);
+ const coord = map.getCoordinateFromPixel(pixels);
+
+ const {
+ isShowingClick,
+ changeCursor,
+ measureIsActive,
+ } = this.props;
+ const [lon, lat] = transform(coord, crs, 'EPSG:4326');
+ if (lon < -250 || lon > 250 || lat < -90 || lat > 90) {
+ return;
+ }
+ 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-maker';
+ if (isMarker) {
+ isActiveLayer = true;
+ }
+ });
+ if (isActiveLayer) {
+ changeCursor(true);
+ }
+ } else if (!hasFeatures && isShowingClick) {
+ changeCursor(false);
+ }
+ }
+
+ singleClick(e, map) {
+ e.stopPropagation();
+ const {
+ getCoordinatesDialog, measureIsActive,
+ } = this.props;
+
+ if (measureIsActive) return;
+ const pixels = e.pixel;
+ getCoordinatesDialog(pixels, map);
+ }
+
+ render() {
+ return null;
+ }
+}
+
+function mapStateToProps(state) {
+ const {
+ map,
+ measure,
+ geosearch,
+ } = state;
+ const { coordinates } = geosearch;
+
+ return {
+ map,
+ coordinates,
+ isShowingClick: map.isClickable,
+ getCoordinatesDialog: (pixels, olMap) => getCoordinatesDialogAtMapPixel(pixels, olMap),
+ measureIsActive: measure.isActive,
+ };
+} const mapDispatchToProps = (dispatch) => ({
+ changeCursor: (bool) => {
+ dispatch(changeCursorActionCreator(bool));
+ },
+});
+CoordinatesInteractions.propTypes = {
+ changeCursor: PropTypes.func.isRequired,
+ getCoordinatesDialog: PropTypes.func.isRequired,
+ isShowingClick: PropTypes.bool.isRequired,
+ measureIsActive: PropTypes.bool.isRequired,
+ mouseEvents: PropTypes.object.isRequired,
+};
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps,
+)(CoordinatesInteractions);
diff --git a/web/js/components/map/ol-coordinates.js b/web/js/components/map/ol-coordinates.js
index 5abb2bedb..46fd7eb49 100644
--- a/web/js/components/map/ol-coordinates.js
+++ b/web/js/components/map/ol-coordinates.js
@@ -24,7 +24,7 @@ export default class OlCoordinates extends React.Component {
componentWillUnmount() {
const { mouseEvents } = this.props;
- mouseEvents.on('click', this.mouseClick);
+ mouseEvents.off('click', this.mouseClick);
mouseEvents.off('mousemove', this.mouseMove);
mouseEvents.off('mouseout', this.mouseOut);
}
diff --git a/web/js/components/measure-tool/measure-tooltip.js b/web/js/components/measure-tool/measure-tooltip.js
index 00a119ff6..2cbc1f18b 100644
--- a/web/js/components/measure-tool/measure-tooltip.js
+++ b/web/js/components/measure-tool/measure-tooltip.js
@@ -102,10 +102,10 @@ export default function MeasureTooltip(props) {
};
return (
- <div className={`tooltip-measure ${activeStaticClass}`}>
+ <div className={`tooltip-custom-black ${activeStaticClass}`}>
<span dangerouslySetInnerHTML={{ __html: getMeasurementValue() }} />
{!active && (
- <span className="remove-measurement" onClick={onRemove}>
+ <span className="close-tooltip" onClick={onRemove}>
<FontAwesomeIcon icon="times" fixedWidth />
</span>
)}
diff --git a/web/js/containers/coordinates-dialog.js b/web/js/containers/coordinates-dialog.js
deleted file mode 100644
index daa596a53..000000000
--- a/web/js/containers/coordinates-dialog.js
+++ /dev/null
@@ -1,98 +0,0 @@
-/* eslint-disable no-restricted-syntax */
-import React from 'react';
-import { connect } from 'react-redux';
-import PropTypes from 'prop-types';
-import {
- ModalBody, ModalHeader, Nav, NavItem, NavLink,
-} from 'reactstrap';
-// import Scrollbars from '../components/util/scrollbar';
-import VectorMetaTable from '../components/vector-metadata/table';
-
-class CoordinatesDialog extends React.Component {
- constructor(props) {
- super(props);
- this.state = { activeIndex: 0 };
- this.updateIndex = this.updateIndex.bind(this);
- }
-
- updateIndex(activeIndex) {
- // eslint-disable-next-line react/destructuring-assignment
- if (activeIndex === this.state.activeIndex) return;
- this.setState({ activeIndex });
- }
-
- render() {
- const {
- toggleWithClose, vectorMetaObject, modalHeight, dialogKey,
- } = this.props;
- const { activeIndex } = this.state;
- // const navArray = [];
- const keyArray = [];
- let i = 0;
- console.log(vectorMetaObject);
- for (const [key, value] of Object.entries(vectorMetaObject)) {
- const stringLength = 20;
- const title = value[0].title || key;
- const { subTitle } = value[0];
- const titleText = title.length > stringLength ? `${title.substring(0, stringLength)}...` : title;
- const combinedTitles = subTitle ? `${title} - ${subTitle}` : title;
- const index = i;
- keyArray.push(key);
- // navArray.push(
- // <NavItem
- // key={key}
- // className="vector-meta-nav-item"
- // active={activeIndex === i}
- // >
- // <NavLink onClick={() => this.updateIndex(index)} title={combinedTitles}>
- // {`${titleText} [${value.length}]`}
- // </NavLink>
- // </NavItem>,
- // );
- i += 1;
- }
- const activeMetaArray = vectorMetaObject[keyArray[activeIndex]];
- console.log(activeMetaArray);
- return (
- <div className="draggable-modal-content">
- <ModalHeader toggle={toggleWithClose}>
- {/* TEST TITLE MODAL HEADER */}
- </ModalHeader>
-
- <ModalBody>
- <VectorMetaTable id={dialogKey} metaArray={activeMetaArray} title={keyArray[activeIndex]} />
- </ModalBody>
- </div>
- );
-
- // return (
- // <div className="draggable-modal-content">
- // <ModalHeader toggle={toggleWithClose}>
- // <Nav tabs id="vector-meta-nav" className="vector-meta-nav">
- // {navArray}
- // </Nav>
- // </ModalHeader>
-
- // <ModalBody>
- // <Scrollbars style={{ maxHeight: `${modalHeight - 70}px` }}>
- // <VectorMetaTable id={dialogKey} metaArray={activeMetaArray} title={keyArray[activeIndex]} />;
- // </Scrollbars>
- // </ModalBody>
- // </div>
- // );
- }
-}
-
-function mapStateToProps(state) {
- return {};
-}
-export default connect(
- mapStateToProps,
- null,
-)(CoordinatesDialog);
-CoordinatesDialog.propTypes = {
- dialogKey: PropTypes.number,
- modalHeight: PropTypes.number,
- toggleWithClose: PropTypes.func,
- vectorMetaObject: PropTypes.object,
-};
diff --git a/web/js/containers/map-interactions/map-interactions.js b/web/js/containers/map-interactions/map-interactions.js
index 86fcbfad0..dc8f5ee78 100644
--- a/web/js/containers/map-interactions/map-interactions.js
+++ b/web/js/containers/map-interactions/map-interactions.js
@@ -4,30 +4,32 @@ import PropTypes from 'prop-types';
import OlCoordinates from '../../components/map/ol-coordinates';
import OlVectorInteractions from './ol-vector-interactions';
import OlMeasureTool from '../../components/map/ol-measure-tool';
+import OlCoordinatesMarker from '../../components/geosearch/ol-coordinates-marker';
import { selectCoordinatesToFly } from '../../modules/geosearch/actions';
class MapInteractions extends React.PureComponent {
+ getMapClasses = () => {
+ const { isShowingClick, isDistractionFreeModeActive, isCoordinateSearchActive } = this.props;
+ let mapClasses = 'wv-map';
+ mapClasses += isShowingClick && !isCoordinateSearchActive ? ' cursor-pointer' : '';
+ mapClasses += isCoordinateSearchActive ? ' cursor-crosshair' : '';
+ mapClasses += isDistractionFreeModeActive ? ' distraction-free-active' : '';
+ return mapClasses;
+ };
+
render() {
const {
selectCoordinatesToFly,
isDistractionFreeModeActive,
isCoordinateSearchActive,
- isShowingClick,
mouseEvents,
} = this.props;
- let mapClasses = isShowingClick
- ? 'wv-map cursor-pointer'
- : 'wv-map';
- mapClasses = isDistractionFreeModeActive
- ? `${mapClasses} distraction-free-active`
- : mapClasses;
-
+ const mapClasses = this.getMapClasses();
return (
<>
<div
id="wv-map"
className={mapClasses}
- style={{ cursor: isCoordinateSearchActive ? 'crosshair' : 'default' }}
/>
{!isDistractionFreeModeActive && (
<>
@@ -37,23 +39,26 @@ class MapInteractions extends React.PureComponent {
isCoordinateSearchActive={isCoordinateSearchActive}
/>
</>
-
)}
<OlVectorInteractions
mouseEvents={mouseEvents}
/>
<OlMeasureTool />
+ <OlCoordinatesMarker
+ mouseEvents={mouseEvents}
+ />
</>
);
}
}
function mapStateToProps(state) {
const { geosearch, map, ui } = state;
+ const { isDistractionFreeModeActive } = ui;
const { isCoordinateSearchActive } = geosearch;
return {
isShowingClick: map.isClickable,
- isDistractionFreeModeActive: ui.isDistractionFreeModeActive,
- isCoordinateSearchActive,
+ isDistractionFreeModeActive,
+ isCoordinateSearchActive: !isDistractionFreeModeActive && isCoordinateSearchActive,
};
}
diff --git a/web/js/containers/map-interactions/ol-vector-interactions.js b/web/js/containers/map-interactions/ol-vector-interactions.js
index c9c686241..db919d761 100644
--- a/web/js/containers/map-interactions/ol-vector-interactions.js
+++ b/web/js/containers/map-interactions/ol-vector-interactions.js
@@ -1,5 +1,4 @@
import { connect } from 'react-redux';
-
import {
debounce as lodashDebounce,
get as lodashGet,
@@ -12,7 +11,6 @@ import { transform } from 'ol/proj';
import { isFromActiveCompareRegion } from '../../modules/compare/util';
import { hasNonClickableVectorLayer } from '../../modules/layers/util';
import vectorDialog from '../vector-dialog';
-import coordinatesDialog from '../coordinates-dialog';
import { onMapClickGetVectorFeatures } from '../../modules/vector-styles/util';
import { openCustomContent, onClose } from '../../modules/modal/actions';
import { selectVectorFeatures as selectVectorFeaturesActionCreator } from '../../modules/vector-styles/actions';
@@ -52,7 +50,7 @@ export class VectorInteractions extends React.Component {
if (!def || lodashIncludes(def.clickDisabledFeatures, feature.getType())) return;
const isWrapped = proj.id === 'geographic' && (def.wrapadjacentdays || def.wrapX);
const isRenderedFeature = isWrapped ? lon > -250 || lon < 250 || lat > -90 || lat < 90 : true;
- if (isRenderedFeature && isFromActiveCompareRegion(map, pixels, layer.wv, compareState, swipeOffset)) {
+ if (isRenderedFeature && isFromActiveCompareRegion(pixels, layer.wv, compareState, swipeOffset)) {
isActiveLayer = true;
}
});
@@ -64,16 +62,15 @@ export class VectorInteractions extends React.Component {
singleClick(e, map) {
const {
- lastSelected, openVectorDiaglog, onCloseModal, selectVectorFeatures,
+ lastSelected, openVectorDialog, onCloseModal, selectVectorFeatures,
modalState, getDialogObject, measureIsActive, isMobile, activeLayers,
- activateVectorAlert, proj, openCoordinatesDialog,
+ activateVectorAlert, proj,
} = this.props;
if (measureIsActive) return;
const isVectorModalOpen = modalState.id.includes('vector_dialog') && modalState.isOpen;
const pixels = e.pixel;
const clickObj = getDialogObject(pixels, map);
- console.log(clickObj);
const metaArray = clickObj.metaArray || [];
const selected = clickObj.selected || {};
const offsetLeft = clickObj.offsetLeft || 10;
@@ -82,25 +79,25 @@ export class VectorInteractions extends React.Component {
const dialogId = isVectorModalOpen ? modalState.id : `vector_dialog${pixels[0]}${pixels[1]}`;
if (isCoordinatesMarker) {
- openCoordinatesDialog(dialogId, metaArray, offsetLeft, offsetTop, isMobile);
+ return;
+ }
+
+ if (metaArray.length) {
+ openVectorDialog(dialogId, metaArray, offsetLeft, offsetTop, isMobile);
} else {
- if (metaArray.length) {
- openVectorDiaglog(dialogId, metaArray, offsetLeft, offsetTop, isMobile);
- } else {
- const mapRes = map.getView().getResolution();
- const hasNonClickableVectorLayerType = hasNonClickableVectorLayer(activeLayers, mapRes, proj.id);
+ const mapRes = map.getView().getResolution();
+ const hasNonClickableVectorLayerType = hasNonClickableVectorLayer(activeLayers, mapRes, proj.id);
- if (hasNonClickableVectorLayerType) {
- activateVectorAlert();
- }
- }
- if (Object.entries(selected).length || (Object.entries(lastSelected).length && !isVectorModalOpen)) {
- selectVectorFeatures(selected);
- } else if (isVectorModalOpen && !Object.entries(selected).length) {
- onCloseModal();
- selectVectorFeatures({});
+ if (hasNonClickableVectorLayerType) {
+ activateVectorAlert();
}
}
+ if (Object.entries(selected).length || (Object.entries(lastSelected).length && !isVectorModalOpen)) {
+ selectVectorFeatures(selected);
+ } else if (isVectorModalOpen && !Object.entries(selected).length) {
+ onCloseModal();
+ selectVectorFeatures({});
+ }
}
render() {
@@ -108,24 +105,6 @@ export class VectorInteractions extends React.Component {
}
}
-VectorInteractions.propTypes = {
- changeCursor: PropTypes.func.isRequired,
- getDialogObject: PropTypes.func.isRequired,
- isShowingClick: PropTypes.bool.isRequired,
- measureIsActive: PropTypes.bool.isRequired,
- modalState: PropTypes.object.isRequired,
- mouseEvents: PropTypes.object.isRequired,
- onCloseModal: PropTypes.func.isRequired,
- openVectorDiaglog: PropTypes.func.isRequired,
- selectVectorFeatures: PropTypes.func.isRequired,
- compareState: PropTypes.object,
- isMobile: PropTypes.bool,
- lastSelected: PropTypes.object,
- proj: PropTypes.object,
- swipeOffset: PropTypes.number,
- activeLayers: PropTypes.array,
- activateVectorAlert: PropTypes.func,
-};
function mapStateToProps(state) {
const {
modal, map, measure, vectorStyles, browser, compare, proj, ui, layers,
@@ -166,7 +145,7 @@ function mapStateToProps(state) {
dispatch(onClose());
},
activateVectorAlert: () => dispatch({ type: ACTIVATE_VECTOR_ALERT }),
- openVectorDiaglog: (dialogId, metaArray, offsetLeft, offsetTop, isMobile) => {
+ openVectorDialog: (dialogId, metaArray, offsetLeft, offsetTop, isMobile) => {
const dialogKey = new Date().getUTCMilliseconds();
dispatch(openCustomContent(dialogId,
{
@@ -194,35 +173,6 @@ function mapStateToProps(state) {
},
}));
},
- openCoordinatesDialog: (dialogId, metaArray, offsetLeft, offsetTop, isMobile) => {
- const dialogKey = Date.now();
- dispatch(openCustomContent(dialogId,
- {
- backdrop: false,
- clickableBehindModal: true,
- desktopOnly: true,
- isDraggable: true,
- wrapClassName: 'vector-modal-wrap',
- modalClassName: 'vector-modal light',
- CompletelyCustomModal: coordinatesDialog,
- isResizable: false,
- dragHandle: '.modal-header',
- dialogKey,
- key: dialogKey,
- vectorMetaObject: lodashGroupBy(metaArray, 'id'),
- width: isMobile ? 250 : 445,
- height: 300,
- offsetLeft,
- offsetTop,
- timeout: 0,
- isOpen: true,
- onClose: () => {
- setTimeout(() => {
- dispatch(selectVectorFeaturesActionCreator({}));
- }, 1);
- },
- }));
- },
});
VectorInteractions.propTypes = {
changeCursor: PropTypes.func.isRequired,
@@ -232,13 +182,12 @@ VectorInteractions.propTypes = {
modalState: PropTypes.object.isRequired,
mouseEvents: PropTypes.object.isRequired,
onCloseModal: PropTypes.func.isRequired,
- openVectorDiaglog: PropTypes.func.isRequired,
+ openVectorDialog: PropTypes.func.isRequired,
selectVectorFeatures: PropTypes.func.isRequired,
compareState: PropTypes.object,
isMobile: PropTypes.bool,
lastSelected: PropTypes.object,
proj: PropTypes.object,
- openCoordinatesDialog: PropTypes.func,
swipeOffset: PropTypes.number,
activeLayers: PropTypes.array,
activateVectorAlert: PropTypes.func,
diff --git a/web/js/containers/map-interactions/ol-vector-interactions.test.js b/web/js/containers/map-interactions/ol-vector-interactions.test.js
index 43e8f82b5..becb8079d 100644
--- a/web/js/containers/map-interactions/ol-vector-interactions.test.js
+++ b/web/js/containers/map-interactions/ol-vector-interactions.test.js
@@ -10,12 +10,12 @@ let map;
let changeCursor;
let selectVectorFeatures;
let getDialogObject;
-let openVectorDiaglog;
+let openVectorDialog;
beforeEach(() => {
registerProjections();
events = util.events();
changeCursor = jest.fn();
- openVectorDiaglog = jest.fn();
+ openVectorDialog = jest.fn();
selectVectorFeatures = jest.fn();
getDialogObject = () => ({
metaArray: [0], selected: [1], offsetLeft: 100, offsetTop: 100,
@@ -26,7 +26,7 @@ beforeEach(() => {
isShowingClick={false}
changeCursor={changeCursor}
getDialogObject={getDialogObject}
- openVectorDiaglog={openVectorDiaglog}
+ openVectorDialog={openVectorDialog}
selectVectorFeatures={selectVectorFeatures}
lastSelected={{}}
measureIsActive={false}
@@ -51,7 +51,7 @@ test('if there is a feature at pixel on click get dialog', () => {
events.trigger('singleclick', { pixel: [0, 0] }, map, 'EPSG:4326');
expect(changeCursor.mock.calls.length).toBe(0);
expect(selectVectorFeatures.mock.calls.length).toBe(1);
- expect(openVectorDiaglog.mock.calls.length).toBe(1);
+ expect(openVectorDialog.mock.calls.length).toBe(1);
});
test('if there is not a feature at pixel do not dispatch changeCursor action', () => {
map.hasFeatureAtPixel = () => false;
diff --git a/web/js/map/runningdata.js b/web/js/map/runningdata.js
index 66284993a..3497b8299 100644
--- a/web/js/map/runningdata.js
+++ b/web/js/map/runningdata.js
@@ -53,7 +53,7 @@ export default function MapRunningData(models, compareUi, store) {
if (!def) return;
const isWrapped = proj.id === 'geographic' && (def.wrapadjacentdays || def.wrapX);
const isRenderedFeature = isWrapped ? lon > -250 || lon < 250 || lat > -90 || lat < 90 : true;
- if (!isRenderedFeature || !isFromActiveCompareRegion(map, pixels, layer.wv, state.compare, swipeOffset)) return;
+ if (!isRenderedFeature || !isFromActiveCompareRegion(pixels, layer.wv, state.compare, swipeOffset)) return;
let color;
const identifier = def.palette.styleProperty;
const layerId = def.id;
@@ -80,7 +80,7 @@ export default function MapRunningData(models, compareUi, store) {
map.forEachLayerAtPixel(pixels, (layer, data) => {
if (!layer.wv) return;
const { def } = layer.wv;
- if (!isFromActiveCompareRegion(map, pixels, layer.wv, state.compare, swipeOffset)) return;
+ if (!isFromActiveCompareRegion(pixels, layer.wv, state.compare, swipeOffset)) return;
if (def.palette && !lodashGet(layer, 'wv.def.disableHoverValue')) {
activeLayerObj[def.id] = {
paletteLegends: getPalette(def.id, undefined, undefined, state),
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 6648c30df..27168aa9a 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -198,19 +198,42 @@ export default function mapui(models, config, store, ui) {
updateProjection(true);
};
- // add map coordinate marker
- const addMapMarker = () => {
+ /*
+ * Handle reverse geocode and add map marker with results
+ *
+ * @method handleActiveMapMarker
+ * @static
+ *
+ * @returns {void}
+ */
+ const handleActiveMapMarker = () => {
const state = store.getState();
const { geosearch } = state;
const { activeMarker, coordinates } = geosearch;
if (coordinates && coordinates.length > 0) {
reverseGeocode(coordinates).then((results) => {
- const marker = addCoordinatesMarker(activeMarker, config, { ui: self }, coordinates, results);
- store.dispatch({ type: UPDATE_ACTIVE_MARKER, value: marker });
+ addMarkerAndUpdateStore(activeMarker, coordinates, results);
});
}
};
+ /*
+ * Add map coordinate marker and update store
+ *
+ * @method addMarkerAndUpdateStore
+ * @static
+ *
+ * @param {Object} activeMarker
+ * @param {Array} coordinates
+ * @param {Object} results
+ *
+ * @returns {void}
+ */
+ const addMarkerAndUpdateStore = (activeMarker, coordinates, results) => {
+ const marker = addCoordinatesMarker(activeMarker, config, { ui: self }, coordinates, results);
+ store.dispatch({ type: UPDATE_ACTIVE_MARKER, value: marker, reverseGeocodeResults: results });
+ };
+
const flyToNewExtent = function(extent, rotation) {
const coordinateX = extent[0] + (extent[2] - extent[0]) / 2;
const coordinateY = extent[1] + (extent[3] - extent[1]) / 2;
@@ -303,7 +326,7 @@ export default function mapui(models, config, store, ui) {
}
updateExtent();
onResize();
- addMapMarker();
+ handleActiveMapMarker();
}
/*
* When page is resised set for mobile or desktop
@@ -389,12 +412,14 @@ export default function mapui(models, config, store, ui) {
const reloadLayers = self.reloadLayers = function(map) {
map = map || self.selected;
const state = store.getState();
- const { layers, proj } = state;
+ const { geosearch, 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) {
- if (!compareState.active && compareMapUi.active) {
+ const compareMapDestroyed = !compareState.active && compareMapUi.active;
+ if (compareMapDestroyed) {
compareMapUi.destroy();
}
clearLayers(map);
@@ -408,6 +433,10 @@ export default function mapui(models, config, store, ui) {
lodashEach(defs, (def) => {
map.addLayer(createLayer(def));
});
+ // add active map marker back after destroying compare mode post createLayer
+ if (compareMapDestroyed && activeMarker) {
+ addMarkerAndUpdateStore(activeMarker, coordinates, reverseGeocodeResults);
+ }
} else {
const stateArray = [['active', 'selected'], ['activeB', 'selectedB']];
clearLayers(map);
@@ -422,6 +451,10 @@ export default function mapui(models, config, store, ui) {
map.addLayer(getCompareLayerGroup(arr, layers, proj.id, state));
});
compareMapUi.create(map, compareState.mode);
+ // add active map marker back in compare mode post createLayer
+ if (activeMarker) {
+ addMarkerAndUpdateStore(activeMarker, coordinates, reverseGeocodeResults);
+ }
}
updateLayerVisibilities();
};
diff --git a/web/js/modules/compare/util.js b/web/js/modules/compare/util.js
index b191a1cfa..346fab8d4 100644
--- a/web/js/modules/compare/util.js
+++ b/web/js/modules/compare/util.js
@@ -24,11 +24,10 @@ export function mapLocationToCompareState(parameters, stateFromLocation) {
/**
* Is layer on active side of Map while in swipe mode -
* No other modes will allow for running-data or vector interactions
- * @param {Object} map | OL map object
* @param {Array} coords | Coordinates of hover point
* @param {Object} layerAttributes | Layer Properties
*/
-export function isFromActiveCompareRegion(map, coords, layerAttributes, compareModel, swipeOffset) {
+export function isFromActiveCompareRegion(coords, layerAttributes, compareModel, swipeOffset) {
if (compareModel && compareModel.active) {
if (compareModel.mode !== 'swipe') {
return false;
diff --git a/web/js/modules/geosearch/actions.js b/web/js/modules/geosearch/actions.js
index b8727c2c7..d784a9b43 100644
--- a/web/js/modules/geosearch/actions.js
+++ b/web/js/modules/geosearch/actions.js
@@ -73,6 +73,7 @@ export function selectCoordinatesToFly(coordinates, reverseGeocodeResults) {
dispatch({
type: SELECT_COORDINATES_TO_FLY,
value: false,
+ reverseGeocodeResults,
coordinates,
activeMarker: marker,
});
diff --git a/web/js/modules/geosearch/reducers.js b/web/js/modules/geosearch/reducers.js
index 520b2678f..d6c2bddb8 100644
--- a/web/js/modules/geosearch/reducers.js
+++ b/web/js/modules/geosearch/reducers.js
@@ -14,6 +14,7 @@ const geosearchState = {
isExpanded: !localStorageCollapseState,
coordinates: [],
activeMarker: null,
+ reverseGeocodeResults: null,
};
export default function geosearchReducer(state = geosearchState, action) {
@@ -21,6 +22,7 @@ export default function geosearchReducer(state = geosearchState, action) {
case UPDATE_ACTIVE_MARKER:
return lodashAssign({}, state, {
activeMarker: action.value,
+ reverseGeocodeResults: action.reverseGeocodeResults,
});
case TOGGLE_SHOW_GEOSEARCH:
return lodashAssign({}, state, {
@@ -31,11 +33,13 @@ export default function geosearchReducer(state = geosearchState, action) {
isCoordinateSearchActive: action.value,
coordinates: action.coordinates,
activeMarker: action.activeMarker,
+ reverseGeocodeResults: action.reverseGeocodeResults,
});
case CLEAR_COORDINATES:
return lodashAssign({}, state, {
coordinates: [],
activeMarker: null,
+ reverseGeocodeResults: null,
});
case TOGGLE_REVERSE_GEOCODE_ACTIVE:
return lodashAssign({}, state, {
diff --git a/web/js/modules/geosearch/selectors.js b/web/js/modules/geosearch/selectors.js
index ea6400303..35c75777f 100644
--- a/web/js/modules/geosearch/selectors.js
+++ b/web/js/modules/geosearch/selectors.js
@@ -1,8 +1,11 @@
import OlPoint from 'ol/geom/Point';
-import { Icon, Style } from 'ol/style';
import OlFeature from 'ol/Feature';
import OlLayerVector from 'ol/layer/Vector';
import OlSourceVector from 'ol/source/Vector';
+import {
+ Style as OlStyle,
+ Icon as OlIcon,
+} from 'ol/style';
import * as olProj from 'ol/proj';
import { containsXY } from 'ol/extent';
@@ -16,7 +19,7 @@ export function animateCoordinates(map, coordinates, zoom) {
ui.animate.fly(targetCoordinates, zoom);
}
-function polarCoordinatesTransform(coordinates, proj) {
+export function polarCoordinatesTransform(coordinates, proj) {
const projObj = {
arctic: 'EPSG:3413',
antarctic: 'EPSG:3031',
@@ -53,61 +56,62 @@ export function addCoordinatesMarker(activeMarker, config, map, coordinates, rev
return false;
}
- const marker = createPin(coordinates, transformedCoordinates, reverseGeocodeResults, 'testerMarker', true);
+ const marker = createPin(coordinates, transformedCoordinates, reverseGeocodeResults);
selected.addLayer(marker);
selected.renderSync();
return marker;
}
export function removeCoordinatesMarker(activeMarker, map) {
- const { selected } = map.ui;
+ const { selected, proj } = map.ui;
+ // remove marker
if (activeMarker) {
activeMarker.setMap(null);
selected.removeLayer(activeMarker);
}
+ // remove tooltip
+ const removeOverlayFromAllProjections = () => {
+ 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.contains('coordinates-map-maker');
+ });
+ if (coordinatesTooltipOverlay.length > 0) {
+ proj[mapProjection].removeOverlay(coordinatesTooltipOverlay[0]);
+ }
+ });
+ };
+ removeOverlayFromAllProjections();
}
-const createPin = function(coordinates, transformedCoordinates = false, reverseGeocodeResults = {}, id, isSelected, category = { slug: 'test', title: 'cat' }, title) {
- const overlayEl = document.createElement('div');
- const icon = document.createElement('i');
- overlayEl.className = 'marker';
- if (isSelected) overlayEl.classList.add('marker-selected');
- icon.className = `event-icon event-icon-${category.slug}`;
- icon.title = title || category.title;
- overlayEl.appendChild(icon);
-
+const createPin = function(coordinates, transformedCoordinates = false, reverseGeocodeResults = {}) {
const [longitude, latitude] = coordinates;
const iconFeature = new OlFeature({
geometry: new OlPoint(transformedCoordinates || coordinates),
reverseGeocodeResults,
latitude,
longitude,
- population: 4000,
- rainfall: 500,
});
- // TODO: test pin colors
- // o, o2, o3, b, map-pin (default)
- const src = localStorage.mapPin || 'map-pin';
-
-
- const iconStyle = new Style({
- image: new Icon({
+ const iconStyle = new OlStyle({
+ image: new OlIcon({
anchorOrigin: 'bottom-left',
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
scale: 0.5,
- src: `images/${src}.png`,
+ src: 'images/map-pin.png',
}),
});
iconFeature.setStyle(iconStyle);
iconFeature.setId('coordinates-map-maker');
+
const vectorSource = new OlSourceVector({
wrapX: false,
features: [iconFeature],
});
-
const vectorLayer = new OlLayerVector({
source: vectorSource,
});
@@ -115,6 +119,8 @@ 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: {
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index bc23933b1..618fa1e91 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -5,7 +5,6 @@ import {
get as lodashGet,
includes as lodashIncludes,
} from 'lodash';
-
import {
Stroke, Style, Fill, Circle,
} from 'ol/style';
@@ -222,66 +221,8 @@ function getModalContentsAtPixel(mapProps, config, compareState) {
map.forEachFeatureAtPixel(pixels, (feature, layer) => {
const featureId = feature.getId();
if (featureId === 'coordinates-map-maker') {
- const featureProperties = feature.getProperties();
- selected.COORDS = ['COORDS TEST1'];
-
- const { latitude, longitude, reverseGeocodeResults } = featureProperties;
- const { address, error } = reverseGeocodeResults;
-
- let title;
- if (error) {
- title = `${latitude}, ${longitude}`;
- } else if (address) {
- const { Match_addr } = address;
- title = Match_addr;
- }
-
- const obj = {
- legend: [
- // {
- // DataType: 'string',
- // Description: 'Name of Nuclear Plant',
- // Function: 'Identify',
- // Identifier: 'Plant',
- // IsLabel: true,
- // IsOptional: false,
- // Title: 'Plant Site Name',
- // },
- {
- DataType: 'float',
- Description: 'Latitude in Decimal Degrees',
- Function: 'Describe',
- Identifier: 'Latitude',
- IsLabel: false,
- IsOptional: false,
- Title: 'Latitude',
- Units: '°',
- },
- {
- DataType: 'float',
- Description: 'Longitude in Decimal Degrees',
- Function: 'Describe',
- Identifier: 'Longitude',
- IsLabel: false,
- IsOptional: false,
- Title: 'Longitude',
- Units: '°',
- },
- ],
- features: {
- // Plant: 'TEST FEATURES Plant',
- Latitude: latitude,
- Longitude: longitude,
- },
- id: 'TEST coords id',
- title,
- subTitle: 'TEST SUBTITLE',
- featureTitle: title,
-
- };
- metaArray.push(obj);
isCoordinatesMarker = true;
- return { selected, metaArray, isCoordinatesMarker };
+ return;
}
const def = lodashGet(layer, 'wv.def');
@@ -291,7 +232,7 @@ function getModalContentsAtPixel(mapProps, config, compareState) {
const type = feature.getType();
if (lodashIncludes(def.clickDisabledFeatures, type)
- || !isFromActiveCompareRegion(map, pixels, layer.wv, compareState, swipeOffset)) {
+ || !isFromActiveCompareRegion(pixels, layer.wv, compareState, swipeOffset)) {
return;
}
if (def.vectorData && def.vectorData.id && def.title) {
@@ -322,7 +263,6 @@ function getModalContentsAtPixel(mapProps, config, compareState) {
selected[layerId].push(uniqueIdentifier);
}
});
- console.log(selected, metaArray);
return { selected, metaArray, isCoordinatesMarker };
}
/**