Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2480: Highlight Event Tracks on Hover (#4617)

christof-wittreich3a9b349450e8
diff --git a/e2e/features/events/event-test.spec.js b/e2e/features/events/event-test.spec.js
index 6998ed5ca..9b9edf8aa 100644
--- a/e2e/features/events/event-test.spec.js
+++ b/e2e/features/events/event-test.spec.js
@@ -54,6 +54,8 @@ test('Selecting event shows track points and markers which are not visible when
await secondEvent.click()
await page.waitForTimeout(5000)
await expect(trackMarker).toHaveCount(5)
+ await layersTab.hover()
+ await page.waitForTimeout(1000)
await layersTab.click()
await expect(trackMarker).not.toBeVisible()
await expect(eventIcons).not.toBeVisible()
@@ -96,8 +98,9 @@ test('Verify Events message and clicking message opens dialog', async ({ browser
test('Clicking selected event deselects event', async ({ browserName }) => {
test.skip(browserName === 'firefox', 'firefox cant find iceberg event sometimes')
- const { selectedFirstEvent } = selectors
+ const { selectedFirstEvent, eventsTab } = selectors
await selectedFirstEvent.click()
+ await eventsTab.hover()
await page.waitForTimeout(5000)
await expect(selectedFirstEvent).not.toBeVisible()
})
diff --git a/web/js/components/sidebar/event.js b/web/js/components/sidebar/event.js
index f005eac8b..c8ff47969 100644
--- a/web/js/components/sidebar/event.js
+++ b/web/js/components/sidebar/event.js
@@ -15,7 +15,9 @@ function Event (props) {
deselectEvent,
event,
eventLayers,
+ highlightEvent,
isSelected,
+ isHighlighted,
layers,
removeGroup,
selectedDate,
@@ -23,9 +25,10 @@ function Event (props) {
sources,
toggleGroupVisibility,
toggleVisibility,
+ unHighlightEvent,
} = props;
const dateString = formatDisplayDate(event.geometry[0].date);
- const itemClass = isSelected
+ const itemClass = isSelected || isHighlighted
? 'item-selected event item'
: 'event item';
@@ -40,8 +43,6 @@ function Event (props) {
/**
*
* @param {String} date | Date of event clicked
- * @param {Boolean} isSelected | Is this event already selected
- * @param {Object} e | Event Object
*/
function onEventSelect(date) {
if (isSelected && (!date || date === selectedDate)) {
@@ -68,6 +69,19 @@ function Event (props) {
}
}
+ /**
+ *
+ * @param {Boolean} isHighlighting | Is the action to highlight
+ */
+ function onEventHighlight(isHighlighting) {
+ if (!isHighlighting) {
+ unHighlightEvent();
+ } else {
+ const selectedEventDate = getDefaultEventDate(event);
+ highlightEvent(event.id, selectedEventDate);
+ }
+ }
+
/**
*
* @param {Object} geometry | Geometry object containing magnitude data
@@ -174,6 +188,12 @@ function Event (props) {
e.stopPropagation();
onEventSelect();
}}
+ onMouseEnter={(e) => {
+ onEventHighlight(true);
+ }}
+ onMouseLeave={(e) => {
+ onEventHighlight(false);
+ }}
>
<EventIcon id={`${event.id}-list`} category={event.categories[0].title} />
<h4
@@ -198,7 +218,9 @@ Event.propTypes = {
deselectEvent: PropTypes.func,
event: PropTypes.object,
eventLayers: PropTypes.array,
+ highlightEvent: PropTypes.func,
isSelected: PropTypes.bool,
+ isHighlighted: PropTypes.bool,
layers: PropTypes.array,
removeGroup: PropTypes.func,
selectedDate: PropTypes.string,
@@ -206,6 +228,7 @@ Event.propTypes = {
sources: PropTypes.array,
toggleGroupVisibility: PropTypes.func,
toggleVisibility: PropTypes.func,
+ unHighlightEvent: PropTypes.func,
};
export default Event;
diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.js
index ed7141c2c..2f7ff4905 100644
--- a/web/js/containers/sidebar/events.js
+++ b/web/js/containers/sidebar/events.js
@@ -13,6 +13,8 @@ import Scrollbars from '../../components/util/scrollbar';
import {
selectEvent as selectEventActionCreator,
deselectEvent as deselectEventActionCreator,
+ highlightEvent as highlightEventActionCreator,
+ unHighlightEvent as unHighlightEventActionCreator,
} from '../../modules/natural-events/actions';
import { collapseSidebar } from '../../modules/sidebar/actions';
import { getSelectedDate } from '../../modules/date/selectors';
@@ -29,28 +31,31 @@ import { formatDisplayDate } from '../../modules/date/util';
function Events(props) {
const {
defaultEventLayer,
- eventsData,
- sources,
- isLoading,
- layers,
- selectEvent,
- selected,
- openFilterModal,
- height,
deselectEvent,
+ eventLayers,
+ eventsData,
hasRequestError,
+ height,
+ highlighted,
+ highlightEvent,
+ isLoading,
isMobile,
isEmbedModeActive,
- showAlert,
+ layers,
+ openFilterModal,
+ removeGroup,
selectedDate,
- showDates,
+ selected,
+ selectEvent,
selectedStartDate,
selectedEndDate,
selectedCategories,
- removeGroup,
- eventLayers,
+ showAlert,
+ showDates,
+ sources,
toggleVisibility,
toggleGroupVisibility,
+ unHighlightEvent,
} = props;
const filterControlHeight = 115;
@@ -108,11 +113,14 @@ function Events(props) {
event={event}
selectEvent={(id, date) => selectEvent(id, date, isMobile)}
deselectEvent={deselectEvent}
+ highlightEvent={(id, date) => highlightEvent(id, date)}
+ unHighlightEvent={unHighlightEvent}
removeGroup={removeGroup}
eventLayers={eventLayers}
toggleVisibility={toggleVisibility}
toggleGroupVisibility={toggleGroupVisibility}
isSelected={selected.id === event.id}
+ isHighlighted={highlighted.id === event.id}
selectedDate={selectedDate}
sources={sources}
defaultEventLayer={defaultEventLayer}
@@ -157,6 +165,12 @@ const mapDispatchToProps = (dispatch) => ({
deselectEvent: () => {
dispatch(deselectEventActionCreator());
},
+ highlightEvent: (id, dateStr) => {
+ dispatch(highlightEventActionCreator(id, dateStr));
+ },
+ unHighlightEvent: () => {
+ dispatch(unHighlightEventActionCreator());
+ },
openFilterModal: () => {
dispatch(toggleCustomContent('events-filter', {
headerText: 'Filter Events',
@@ -192,7 +206,7 @@ const mapStateToProps = (state) => {
} = state;
const {
- selected, showAll, selectedDates, selectedCategories,
+ selected, highlighted, showAll, selectedDates, selectedCategories,
} = events;
const { isEmbedModeActive } = embed;
@@ -207,6 +221,7 @@ const mapStateToProps = (state) => {
showAll,
showDates: !!(selectedDates.start && selectedDates.end),
selected,
+ highlighted,
selectedCategories,
selectedStartDate: selectedDates.start,
selectedEndDate: selectedDates.end,
@@ -221,10 +236,12 @@ export default connect(
Events.propTypes = {
defaultEventLayer: PropTypes.string,
deselectEvent: PropTypes.func,
- eventLayers: PropTypes.array,
eventsData: PropTypes.array,
+ eventLayers: PropTypes.array,
hasRequestError: PropTypes.bool,
height: PropTypes.number,
+ highlighted: PropTypes.object,
+ highlightEvent: PropTypes.func,
isLoading: PropTypes.bool,
isMobile: PropTypes.bool,
isEmbedModeActive: PropTypes.bool,
@@ -233,13 +250,14 @@ Events.propTypes = {
removeGroup: PropTypes.func,
selected: PropTypes.object,
selectedDate: PropTypes.string,
- showDates: PropTypes.bool,
selectedStartDate: PropTypes.string,
selectedEndDate: PropTypes.string,
selectedCategories: PropTypes.array,
selectEvent: PropTypes.func,
showAlert: PropTypes.bool,
+ showDates: PropTypes.bool,
sources: PropTypes.array,
toggleGroupVisibility: PropTypes.func,
toggleVisibility: PropTypes.func,
+ unHighlightEvent: PropTypes.func,
};
diff --git a/web/js/map/natural-events/event-markers.js b/web/js/map/natural-events/event-markers.js
index 49da21caf..ed52c121a 100644
--- a/web/js/map/natural-events/event-markers.js
+++ b/web/js/map/natural-events/event-markers.js
@@ -14,7 +14,11 @@ import OlGeomPolygon from 'ol/geom/Polygon';
import * as olProj from 'ol/proj';
import googleTagManager from 'googleTagManager';
import EventIcon from '../../components/sidebar/event-icon';
-import { selectEvent as selectEventAction } from '../../modules/natural-events/actions';
+import {
+ selectEvent as selectEventAction,
+ highlightEvent as highlightEventAction,
+ unHighlightEvent as unHighlightEventAction,
+} from '../../modules/natural-events/actions';
import { getDefaultEventDate } from '../../modules/natural-events/util';
import { getFilteredEvents } from '../../modules/natural-events/selectors';
import { CRS } from '../../modules/map/constants';
@@ -101,7 +105,7 @@ class EventMarkers extends React.Component {
}
}
- componentDidUpdate(prevProps, prevState) {
+ componentDidUpdate(prevProps) {
const {
proj, eventsDataIsLoading, isAnimatingToEvent, selectedEvent,
} = this.props;
@@ -193,7 +197,9 @@ class EventMarkers extends React.Component {
}
addInteractions(marker, event, date, isSelected) {
- const { selectEvent, mapUi } = this.props;
+ const {
+ selectEvent, highlightEvent, unHighlightEvent, mapUi,
+ } = this.props;
const category = event.categories[0];
let willSelect = true;
let moveCount = 0;
@@ -222,6 +228,12 @@ class EventMarkers extends React.Component {
});
}
};
+ const onMouseEnter = () => {
+ highlightEvent(event.id, date);
+ };
+ const onMouseLeave = () => {
+ unHighlightEvent();
+ };
['pointerdown', 'mousedown', 'touchstart'].forEach((type) => {
pinEl.addEventListener(type, onMouseDownTouchStart, options);
@@ -232,6 +244,8 @@ class EventMarkers extends React.Component {
['pointermove', 'mousemove'].forEach((type) => {
pinEl.addEventListener(type, onMouseMove, options);
});
+ pinEl.addEventListener('mouseenter', onMouseEnter, options);
+ pinEl.addEventListener('mouseleave', onMouseLeave, options);
}
remove() {
@@ -283,11 +297,18 @@ const mapDispatchToProps = (dispatch) => ({
selectEvent: (id, date) => {
dispatch(selectEventAction(id, date));
},
+ highlightEvent: (id, date) => {
+ dispatch(highlightEventAction(id, date));
+ },
+ unHighlightEvent: () => {
+ dispatch(unHighlightEventAction());
+ },
});
EventMarkers.propTypes = {
eventsData: PropTypes.array,
eventsDataIsLoading: PropTypes.bool,
+ highlightEvent: PropTypes.func,
isAnimatingToEvent: PropTypes.bool,
isMobile: PropTypes.bool,
map: PropTypes.object,
@@ -295,6 +316,7 @@ EventMarkers.propTypes = {
proj: PropTypes.object,
selectEvent: PropTypes.func,
selectedEvent: PropTypes.object,
+ unHighlightEvent: PropTypes.func,
};
export default connect(
diff --git a/web/js/map/natural-events/event-track.js b/web/js/map/natural-events/event-track.js
index 8bc1614d6..c22878f5d 100644
--- a/web/js/map/natural-events/event-track.js
+++ b/web/js/map/natural-events/event-track.js
@@ -9,8 +9,13 @@ import { useSelector, useDispatch, shallowEqual } from 'react-redux';
import {
getClusters,
} from './cluster';
-import { selectEvent as selectEventAction } from '../../modules/natural-events/actions';
+import {
+ selectEvent as selectEventAction,
+ highlightEvent as highlightEventAction,
+ unHighlightEvent as unHighlightEventAction,
+} from '../../modules/natural-events/actions';
import { getFilteredEvents } from '../../modules/natural-events/selectors';
+import { getDefaultEventDate } from '../../modules/natural-events/util';
import { CRS } from '../../modules/map/constants';
import usePrevious from '../../util/customHooks';
@@ -66,12 +71,14 @@ const updateSelection = function(newDate) {
* @param {String} selectedDate
* @param {Function} callback
* @param {Function} showAllTracks
+ * @param {Object} highlightOptions
* @return {Object} Object Containing track info and elements
*/
-const getTracksAndPoints = function (eventObj, proj, map, selectedDate, callback, showAllTracks) {
+const getTracksAndPoints = function (eventObj, proj, map, selectedDate, callback, showAllTracks, highlightOptions) {
const pointsAndArrows = [];
const trackSegments = [];
const { clusters, firstClusterObj, secondClusterObj } = getClusters(eventObj, proj, selectedDate, map, showAllTracks);
+ const { isHighlighted } = highlightOptions;
clusters.forEach((clusterPoint, index) => {
const date = clusterPoint.properties.date || clusterPoint.properties.startDate;
@@ -89,17 +96,17 @@ const getTracksAndPoints = function (eventObj, proj, map, selectedDate, callback
nextCoordinates = olProj.transform(nextCoordinates, CRS.GEOGRAPHIC, crs);
}
const lineSegmentArray = [prevCoordinates, nextCoordinates];
- const arrowOverlay = getArrows(lineSegmentArray, map);
+ const arrowOverlay = getArrows(lineSegmentArray, map, isHighlighted);
pointsAndArrows.push(arrowOverlay);
trackSegments.push(lineSegmentArray);
}
const point = clusterPoint.properties.cluster
? getClusterPointEl(proj, clusterPoint, map, pointClusterObj, callback)
- : getTrackPoint(proj, clusterPoint, isSelected, callback);
+ : getTrackPoint(proj, clusterPoint, isSelected, callback, highlightOptions);
pointsAndArrows.push(point);
});
return {
- track: getTrackLines(map, trackSegments),
+ track: getTrackLines(map, trackSegments, eventObj.id, getDefaultEventDate(eventObj), callback, highlightOptions),
pointsAndArrows,
};
};
@@ -107,9 +114,11 @@ const getTracksAndPoints = function (eventObj, proj, map, selectedDate, callback
function EventTrack () {
const dispatch = useDispatch();
const selectEvent = (id, date) => dispatch(selectEventAction(id, date));
+ const highlightEvent = (id, date) => dispatch(highlightEventAction(id, date));
+ const unHighlightEvent = () => dispatch(unHighlightEventAction());
const eventsData = useSelector((state) => getFilteredEvents(state), shallowEqual);
- const isAnimatingToEvent = useSelector((state) => state.animation.isAnimatingToEvent);
+ const isAnimatingToEvent = useSelector((state) => state.events.isAnimatingToEvent);
const isPlaying = useSelector((state) => state.animation.isPlaying);
const map = useSelector((state) => state.map.ui.selected, shallowEqual);
const extent = useSelector((state) => state.map.extent, shallowEqual);
@@ -117,6 +126,7 @@ function EventTrack () {
const selectedDate = useSelector((state) => state.date.selected, shallowEqual);
const selectedEvent = useSelector((state) => state.events.selected, shallowEqual);
const showAllTracks = useSelector((state) => state.events.showAllTracks);
+ const highlightedEvent = useSelector((state) => state.events.highlighted, shallowEqual);
const [trackDetails, setTrackDetails] = useState({});
const [allTrackDetails, setAllTrackDetails] = useState([]);
@@ -178,7 +188,7 @@ function EventTrack () {
const {
track,
pointsAndArrows,
- } = getTracksAndPoints(singleEvent, proj, mapRef.current, eventDate, selectEvent, showAllTracksRef.current);
+ } = getTracksAndPoints(singleEvent, proj, mapRef.current, eventDate, selectEvent, showAllTracksRef.current, { callbackHighlight: highlightEvent, callbackUnhighlight: unHighlightEvent, isHighlighted: showAllTracks && (singleEvent.id === selectedEvent.id || singleEvent.id === highlightedEvent.id) });
newTrackDetails = {
id: eventID,
@@ -198,7 +208,7 @@ function EventTrack () {
eventsData.forEach((event) => {
const eventID = event.id;
const eventDate = event.geometry[0].date.slice(0, 10);
- if (event.geometry.length > 1 && eventID !== trackDetailsRef.current.id) {
+ if (event.geometry.length > 1) {
createAndAddTrack(event, eventID, eventDate);
}
});
@@ -215,7 +225,7 @@ function EventTrack () {
const {
track,
pointsAndArrows,
- } = getTracksAndPoints(event, proj, mapRef.current, date, selectEvent);
+ } = getTracksAndPoints(event, proj, mapRef.current, date, selectEvent, null, { callbackHighlight: highlightEvent, callbackUnhighlight: unHighlightEvent, isHighlighted: showAllTracks && (event.id === selectedEvent.id || event.id === highlightedEvent.id) });
newTrackDetails = {
id: event.id,
@@ -276,10 +286,6 @@ function EventTrack () {
const initialize = () => {
if (!mapRef.current) return;
mapRef.current.getView().on('propertychange', debouncedOnPropertyChange);
- mapRef.current.once('postrender', () => { debouncedTrackUpdate(); });
- if (showAllTracksRef.current) {
- mapRef.current.once('postrender', () => { debouncedUpdateAllTracks(); });
- }
};
useEffect(
@@ -300,10 +306,10 @@ function EventTrack () {
const prevSelectedDate = usePrevious(selectedDate);
const prevSelectedEvent = usePrevious(selectedEvent);
const prevIsAnimatingToEvent = usePrevious(isAnimatingToEvent);
- const prevEventsData = usePrevious(eventsData);
const prevMap = usePrevious(mapRef.current);
const prevExtent = usePrevious(extent);
const prevShowAllTracks = usePrevious(showAllTracks);
+ const prevHighlightedEvent = usePrevious(highlightedEvent);
useEffect(
() => {
@@ -311,10 +317,12 @@ function EventTrack () {
!== (prevSelectedDate && prevSelectedDate?.valueOf());
const eventDeselect = (selectedEvent !== prevSelectedEvent?.id) && !selectedEvent?.id;
const finishedAnimating = !isAnimatingToEvent && (isAnimatingToEvent !== prevIsAnimatingToEvent);
- const eventsLoaded = eventsData && eventsData.length && (eventsData !== prevEventsData);
+ const eventsLoaded = eventsData && eventsData.length;
const extentChange = prevExtent && (extent[0] !== prevExtent[0] || extent[1] !== prevExtent[1]);
+ const highlightedEventChange = highlightedEvent?.id !== prevHighlightedEvent?.id;
+ const allTracksChange = showAllTracks !== prevShowAllTracks;
- if (mapRef.current !== prevMap) {
+ if (mapRef.current !== prevMap || allTracksChange) {
if (prevMap) {
update(null);
removeTrack(prevMap);
@@ -327,17 +335,17 @@ function EventTrack () {
}
// remove all tracks when deselecting option
- if (!showAllTracksRef.current && prevShowAllTracks !== showAllTracks) {
+ if (!showAllTracksRef.current && allTracksChange) {
removeAllTracks(mapRef.current);
}
// show all tracks when selecting as option
- if (showAllTracksRef.current && !isPlaying && (prevShowAllTracks !== showAllTracksRef.current || selectedDateChange || finishedAnimating || eventsLoaded || extentChange)) {
+ if (showAllTracksRef.current && !isPlaying && (prevShowAllTracks !== showAllTracksRef.current || selectedDateChange || finishedAnimating || eventsLoaded || extentChange || highlightedEventChange)) {
debouncedUpdateAllTracks();
}
// show only selected track if show all tracks is not selected
- if (!isPlaying && !showAllTracksRef.current && (selectedDateChange || finishedAnimating || eventsLoaded || extentChange)) {
+ if (!showAllTracks && !isPlaying && (!showAllTracksRef.current || allTracksChange) && (selectedDateChange || finishedAnimating || eventsLoaded || extentChange)) {
debouncedTrackUpdate();
}
@@ -346,7 +354,7 @@ function EventTrack () {
removeTrack(mapRef.current);
}
},
- [map, isPlaying, extent, selectedDate, isAnimatingToEvent, eventsData, selectedEvent, showAllTracksRef.current],
+ [map, isPlaying, extent, selectedDate, isAnimatingToEvent, eventsData, selectedEvent, showAllTracksRef.current, highlightedEvent, showAllTracks],
);
return null;
diff --git a/web/js/map/natural-events/natural-events.js b/web/js/map/natural-events/natural-events.js
index 715caf933..e4464679d 100644
--- a/web/js/map/natural-events/natural-events.js
+++ b/web/js/map/natural-events/natural-events.js
@@ -77,7 +77,7 @@ class NaturalEvents extends React.Component {
}
}
- componentDidUpdate(prevProps, prevState) {
+ componentDidUpdate(prevProps) {
const {
map,
eventsDataIsLoading,
diff --git a/web/js/map/natural-events/util.js b/web/js/map/natural-events/util.js
index 315ea09c3..89180ee98 100644
--- a/web/js/map/natural-events/util.js
+++ b/web/js/map/natural-events/util.js
@@ -7,12 +7,15 @@ import { CRS } from '../../modules/map/constants';
/**
* Create event point
*
+* @param {Object} proj
* @param {Object} clusterPoint
* @param {Boolean} isSelected
* @param {Function} callback
+* @param {Object} highlightOptions
* @return {Object} Openlayers overlay object
*/
-export const getTrackPoint = function(proj, clusterPoint, isSelected, callback) {
+export const getTrackPoint = function(proj, clusterPoint, isSelected, callback, highlightOptions) {
+ const { callbackHighlight, callbackUnhighlight, isHighlighted } = highlightOptions;
const overlayEl = document.createElement('div');
const circleEl = document.createElement('div');
const textEl = document.createElement('span');
@@ -45,19 +48,28 @@ export const getTrackPoint = function(proj, clusterPoint, isSelected, callback)
overlayEl.onclick = function() {
callback(eventID, date);
};
+ overlayEl.onmouseenter = function() {
+ callbackHighlight(eventID, date);
+ };
+ overlayEl.onmouseleave = function() {
+ callbackUnhighlight();
+ };
textEl.appendChild(content);
textEl.appendChild(magnitudeContent);
- if (isSelected) {
+ if (isHighlighted) {
textEl.className = 'track-marker-date track-marker-date-selected';
setTimeout(() => {
textEl.className = 'track-marker-date';
}, 5000);
} else {
textEl.className = 'track-marker-date';
- textEl.style.top = hasMagnitude ? '-40px' : '-28px';
}
+ textEl.style.top = hasMagnitude ? '-40px' : '-28px';
circleEl.className = `track-marker track-marker-${date}`;
circleEl.id = `track-marker-${date}`;
+ circleEl.style.height = isHighlighted ? '13px' : '';
+ circleEl.style.width = isHighlighted ? '13px' : '';
+ circleEl.style.borderRadius = isHighlighted ? '7px' : '';
overlayEl.appendChild(circleEl);
overlayEl.appendChild(textEl);
@@ -77,9 +89,10 @@ export const getTrackPoint = function(proj, clusterPoint, isSelected, callback)
*
* @param {Array} lineSegmentCoords Start and end points of line in Lat/long
* @param {Object} map OpenLayers map Object
+ * @param {Boolean} isHighlighted If the event is highlighted
* @return {Object} Openlayers overlay Object
*/
-export const getArrows = function(lineSegmentCoords, map) {
+export const getArrows = function(lineSegmentCoords, map, isHighlighted) {
const currentRotation = map.getView().getRotation();
const overlayEl = document.createElement('div');
const arrowEl = document.createElement('div');
@@ -103,6 +116,7 @@ export const getArrows = function(lineSegmentCoords, map) {
arrowEl.style.width = `${lengthOfArrowDiv}px`;
arrowEl.style.height = '16px';
arrowEl.style.transform = `translate(${-(lengthOfArrowDiv / 2)}px, -8px)`;
+ arrowEl.style.backgroundSize = isHighlighted ? '200px' : '';
overlayEl.appendChild(arrowEl);
overlayEl.style.width = '1px';
@@ -118,10 +132,20 @@ export const getArrows = function(lineSegmentCoords, map) {
});
};
-export const getTrackLines = function(map, trackCoords) {
+/**
+* Create event tracklines
+*
+* @param {Object} map
+* @param {Object} trackCoords
+* @param {String} eventID
+* @param {String} date
+* @param {Function} callback
+* @param {Object} highlightOptions
+* @return {Object} Openlayers overlay object
+*/
+export const getTrackLines = function(map, trackCoords, eventID, date, callback, highlightOptions) {
+ const { callbackHighlight, callbackUnhighlight, isHighlighted } = highlightOptions;
const svgEl = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
- const lineEl = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
- const outlineEl = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
let lineString = '';
const pixelCoords = trackCoords.map(([start, end]) => [
map.getPixelFromCoordinate(end),
@@ -149,27 +173,47 @@ export const getTrackLines = function(map, trackCoords) {
svgEl.style.width = `${width + 5}px`;
svgEl.setAttribute('height', height.toFixed(0));
svgEl.setAttribute('width', width.toFixed(0));
- svgEl.appendChild(outlineEl);
- svgEl.appendChild(lineEl);
pixelCoords.forEach(([[x1, y1], [x2, y2]], index) => {
const newEnd = `${(x1 - minX).toFixed(0)},${(y1 - minY).toFixed(0)}`;
const newStart = `${(x2 - minX).toFixed(0)},${(y2 - minY).toFixed(0)}`;
- lineString += `${newStart} ${newEnd} `;
- });
+ lineString = `${newStart} ${newEnd} `;
+
+ const lineEl = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
+ lineEl.style.fill = 'transparent';
+ lineEl.style.stroke = isHighlighted ? 'yellow' : 'white';
+ lineEl.style.strokeWidth = isHighlighted ? '2px' : '1px';
+ lineEl.setAttribute('points', lineString);
- lineEl.style.fill = 'transparent';
- lineEl.style.stroke = 'white';
- lineEl.style.strokeWidth = '1px';
- lineEl.setAttribute('points', lineString);
+ const outlineEl = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
+ outlineEl.style.fill = 'transparent';
+ outlineEl.style.stroke = 'rgba(0,0,0,0.5)';
+ outlineEl.style.strokeWidth = isHighlighted ? '5px' : '3px';
+ outlineEl.setAttribute('points', lineString);
- outlineEl.style.fill = 'transparent';
- outlineEl.style.stroke = 'rgba(0,0,0,0.5)';
- outlineEl.style.strokeWidth = '3px';
- outlineEl.setAttribute('points', lineString);
+ const clickEl = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
+ clickEl.style.fill = 'transparent';
+ clickEl.style.stroke = 'transparent';
+ clickEl.style.strokeWidth = '10px';
+ clickEl.setAttribute('points', lineString);
+ clickEl.classList.add('clickable-track-line');
+ clickEl.onclick = function() {
+ callback(eventID, date);
+ };
+ clickEl.onmouseover = function() {
+ callbackHighlight(eventID, date);
+ };
+ clickEl.onmouseleave = function() {
+ callbackUnhighlight();
+ };
+
+ svgEl.appendChild(outlineEl);
+ svgEl.appendChild(clickEl);
+ svgEl.appendChild(lineEl);
+ });
return new OlOverlay({
- className: 'event-track-line',
+ className: !isHighlighted ? 'event-track-line' : 'event-track-line highlighted-track-line',
position: map.getCoordinateFromPixel(topLeft),
positioning: 'top-left',
insertFirst: true,
@@ -182,10 +226,10 @@ export const getTrackLines = function(map, trackCoords) {
/**
* Create cluster point
*
- * @param {Object} clusterPoint
+ * @param {Object} proj
+ * @param {Object} cluster
* @param {Object} map Openlayers map object
* @param {Object} pointClusterObj supercluster object
- * @param {Function} callback
* @return {Object} Openlayers overlay object
*/
export const getClusterPointEl = function (proj, cluster, map, pointClusterObj) {
diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.js
index 9d2ce9c3d..1cee264ca 100644
--- a/web/js/modules/natural-events/actions.js
+++ b/web/js/modules/natural-events/actions.js
@@ -13,6 +13,8 @@ import {
DESELECT_EVENT,
SET_EVENTS_FILTER,
FINISHED_ANIMATING_TO_EVENT,
+ HIGHLIGHT_EVENT,
+ UNHIGHLIGHT_EVENT,
} from './constants';
import { requestAction } from '../core/actions';
@@ -93,6 +95,20 @@ export function setEventsFilter(categories, start, end, showAll, showAllTracks)
};
}
+export function highlightEvent(id, eventDate) {
+ return {
+ type: HIGHLIGHT_EVENT,
+ id,
+ date: eventDate,
+ };
+}
+
+export function unHighlightEvent(id, date) {
+ return {
+ type: UNHIGHLIGHT_EVENT,
+ };
+}
+
export function selected() {
return {
type: FINISHED_ANIMATING_TO_EVENT,
diff --git a/web/js/modules/natural-events/constants.js b/web/js/modules/natural-events/constants.js
index 36e4d8bfa..cae7ab057 100644
--- a/web/js/modules/natural-events/constants.js
+++ b/web/js/modules/natural-events/constants.js
@@ -14,5 +14,7 @@ export const SELECT_EVENT = 'EVENTS/SELECT_EVENT';
export const ADD_CATEGORY = 'EVENTS/ADD_CATEGORY';
export const REMOVE_CATEGORY = 'EVENTS/REMOVE_CATEGORY';
export const FINISHED_ANIMATING_TO_EVENT = 'EVENTS/FINISHED_ANIMATING_TO_EVENT';
+export const HIGHLIGHT_EVENT = 'EVENTS/HIGHLIGHT_EVENT';
+export const UNHIGHLIGHT_EVENT = 'EVENTS/UNHIGHLIGHT_EVENT';
export const LIMIT_EVENT_REQUEST_COUNT = 50;
diff --git a/web/js/modules/natural-events/reducers.js b/web/js/modules/natural-events/reducers.js
index adf03af89..db80ff96d 100644
--- a/web/js/modules/natural-events/reducers.js
+++ b/web/js/modules/natural-events/reducers.js
@@ -11,6 +11,8 @@ import {
DESELECT_EVENT,
SET_EVENTS_FILTER,
FINISHED_ANIMATING_TO_EVENT,
+ HIGHLIGHT_EVENT,
+ UNHIGHLIGHT_EVENT,
} from './constants';
import { CHANGE_TAB as CHANGE_SIDEBAR_TAB } from '../sidebar/constants';
@@ -43,6 +45,10 @@ const eventsReducerState = {
eventObject: null,
geometryForDate: null,
},
+ highlighted: {
+ id: '',
+ date: null,
+ },
active: false,
showAll: true,
showAllTracks: false,
@@ -113,6 +119,23 @@ export function eventsReducer(state = eventsReducerState, action) {
...state,
isAnimatingToEvent: false,
};
+ case HIGHLIGHT_EVENT: {
+ const {
+ id, date,
+ } = action;
+ return {
+ ...state,
+ highlighted: {
+ id,
+ date,
+ },
+ };
+ }
+ case UNHIGHLIGHT_EVENT:
+ return {
+ ...state,
+ highlighted: eventsReducerState.highlighted,
+ };
default:
return state;
}
diff --git a/web/scss/features/events.scss b/web/scss/features/events.scss
index b01ab2c74..e61e4438a 100644
--- a/web/scss/features/events.scss
+++ b/web/scss/features/events.scss
@@ -294,11 +294,22 @@
.event-track-line {
z-index: 0;
+ pointer-events: none !important;
+
+ polyline.clickable-track-line {
+ pointer-events: auto;
+ cursor: pointer;
+ z-index: 10;
+ }
+
+ &.highlighted-track-line {
+ z-index: 1;
+ }
}
.event-track-point,
.event-track-cluster-point {
- z-index: 1;
+ z-index: 2;
}
.event-track-arrows {