Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2296

Jason Kent9f037da5a208
diff --git a/web/js/combine-ui.js b/web/js/combine-ui.js
index 43f921aa7..6c1f98db6 100644
--- a/web/js/combine-ui.js
+++ b/web/js/combine-ui.js
@@ -49,15 +49,13 @@ export default function combineUi(models, config, store) {
function registerMapMouseHandlers(maps) {
Object.values(maps).forEach((map) => {
const element = map.getTargetElement();
- const crs = map
- .getView()
- .getProjection()
- .getCode();
- element.addEventListener('mousemove', (event) => {
- events.trigger('map:mousemove', event, map, crs);
+ const crs = map.getView().getProjection().getCode();
+
+ element.addEventListener('mouseleave', (event) => {
+ events.trigger('map:mouseout', event);
});
- element.addEventListener('mouseout', (event) => {
- events.trigger('map:mouseout', event, map, crs);
+ map.on('pointermove', (event) => {
+ events.trigger('map:mousemove', event, map, crs);
});
map.on('singleclick', (event) => {
events.trigger('map:singleclick', event, map, crs);
@@ -65,8 +63,5 @@ function registerMapMouseHandlers(maps) {
map.on('contextmenu', (event) => {
events.trigger('map:contextmenu', event, map, crs);
});
- element.addEventListener('click', (event) => {
- events.trigger('map:click', event, map, crs);
- });
});
}
diff --git a/web/js/components/map/ol-coordinates.js b/web/js/components/map/ol-coordinates.js
index f3bbe29a0..bc46755c2 100644
--- a/web/js/components/map/ol-coordinates.js
+++ b/web/js/components/map/ol-coordinates.js
@@ -29,8 +29,9 @@ export default class OlCoordinates extends React.Component {
format: null,
width: null,
};
- this.mouseMove = lodashThrottle(this.mouseMove.bind(this), 8);
- this.mouseOut = lodashThrottle(this.mouseOut.bind(this), 8);
+ const options = { leading: true, trailing: true };
+ this.mouseMove = lodashThrottle(this.mouseMove.bind(this), 200, options);
+ this.mouseOut = lodashThrottle(this.mouseOut.bind(this), 200, options);
this.changeFormat = this.changeFormat.bind(this);
this.setInitFormat = this.setInitFormat.bind(this);
}
@@ -46,9 +47,8 @@ export default class OlCoordinates extends React.Component {
events.off('map:mouseout', this.mouseOut);
}
- mouseMove(event, map, crs) {
- const pixels = map.getEventPixel(event);
- const coord = map.getCoordinateFromPixel(pixels);
+ mouseMove({ pixel }, map, crs) {
+ const coord = map.getCoordinateFromPixel(pixel);
if (!coord) {
this.clearCoord();
return;
diff --git a/web/js/containers/map-interactions/ol-vector-interactions.js b/web/js/containers/map-interactions/ol-vector-interactions.js
index c105b5e19..c37a20cf5 100644
--- a/web/js/containers/map-interactions/ol-vector-interactions.js
+++ b/web/js/containers/map-interactions/ol-vector-interactions.js
@@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import {
- debounce as lodashDebounce,
+ throttle as lodashThrottle,
get as lodashGet,
includes as lodashIncludes,
groupBy as lodashGroupBy,
@@ -32,18 +32,23 @@ const { events } = util;
export class VectorInteractions extends React.Component {
constructor(props) {
super(props);
- this.mouseMove = lodashDebounce(this.mouseMove.bind(this), 8);
- this.mouseOut = lodashDebounce(this.mouseOut.bind(this), 8);
+ const options = { leading: true, trailing: true };
+ this.mouseMove = lodashThrottle(this.mouseMove.bind(this), 200, options);
+ this.mouseOut = lodashThrottle(this.mouseOut.bind(this), 200, options);
this.singleClick = this.singleClick.bind(this);
}
componentDidMount() {
events.on('map:mousemove', this.mouseMove);
+ // events.on('map:moveend', this.mouseMove);
+ events.on('map:mouseout', this.mouseOut);
events.on('map:singleclick', this.singleClick);
}
componentWillUnmount() {
events.off('map:mousemove', this.mouseMove);
+ // events.off('map:moveend', this.mouseMove);
+ events.off('map:mouseout', this.mouseOut);
events.off('map:singleclick', this.singleClick);
}
@@ -58,7 +63,7 @@ export class VectorInteractions extends React.Component {
*
* @return {Boolean} to indicate if valid for parent mouseMove function
*/
- handleGranuleHover = (crs, pixels, mouseCoords) => {
+ handleGranuleHover = (pixels, mouseCoords) => {
const {
compareState,
granulePlatform,
@@ -100,27 +105,24 @@ export class VectorInteractions extends React.Component {
return true;
}
- mouseOut() {
- const {
- granulePlatform,
- } = this.props;
- events.trigger('granule-hovered', granulePlatform);
+ mouseOut = () => {
+ this.mouseMove.cancel();
+ events.trigger('granule-hovered', null);
}
- mouseMove(event, map, crs) {
+ mouseMove({ pixel }, map, crs) {
const {
isShowingClick, changeCursor, isCoordinateSearchActive, measureIsActive, compareState, swipeOffset, proj, granuleFootprints,
} = this.props;
- if (measureIsActive || isCoordinateSearchActive) {
+ if (measureIsActive || isCoordinateSearchActive || !pixel) {
return;
}
- const pixels = map.getEventPixel(event);
- const coord = map.getCoordinateFromPixel(pixels);
+ const coord = map.getCoordinateFromPixel(pixel);
// handle granule footprint hover, will break out with false return if on wrong compare A/B side
if (granuleFootprints) {
- const isValidGranule = this.handleGranuleHover(crs, pixels, coord);
+ const isValidGranule = this.handleGranuleHover(pixel, coord);
if (!isValidGranule) {
return;
}
@@ -130,15 +132,15 @@ export class VectorInteractions extends React.Component {
if (lon < -250 || lon > 250 || lat < -90 || lat > 90) {
return;
}
- const hasFeatures = map.hasFeatureAtPixel(pixels);
+ const hasFeatures = map.hasFeatureAtPixel(pixel);
if (hasFeatures && !isShowingClick && !measureIsActive) {
let isActiveLayer = false;
- map.forEachFeatureAtPixel(pixels, (feature, layer) => {
+ map.forEachFeatureAtPixel(pixel, (feature, layer) => {
const def = lodashGet(layer, 'wv.def');
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(pixels, layer.wv.group, compareState, swipeOffset)) {
+ if (isRenderedFeature && isFromActiveCompareRegion(pixel, layer.wv.group, compareState, swipeOffset)) {
isActiveLayer = true;
}
});
diff --git a/web/js/map/granule/util.js b/web/js/map/granule/util.js
index c1990cee5..ed278be37 100644
--- a/web/js/map/granule/util.js
+++ b/web/js/map/granule/util.js
@@ -334,27 +334,30 @@ export const granuleFootprint = (map) => {
useSpatialIndex: false,
});
- const getVectorLayer = (text) => new OlVectorLayer({
- className: 'granule-map-footprint',
- source: vectorSource,
- style: [
- new OlStyle({
- fill: new OlStyleFill({ color: 'rgb(0, 123, 255, 0.25)' }),
- stroke: new OlStyleStroke({
- color: 'rgb(0, 123, 255, 0.65)',
- width: 3,
+ const getVectorLayer = (text, showFill) => {
+ const fill = showFill ? new OlStyleFill({ color: 'rgb(0, 123, 255, 0.25)' }) : null;
+ return new OlVectorLayer({
+ className: 'granule-map-footprint',
+ source: vectorSource,
+ style: [
+ new OlStyle({
+ fill,
+ stroke: new OlStyleStroke({
+ color: 'rgb(0, 123, 255, 0.65)',
+ width: 3,
+ }),
+ text: new OlText({
+ textAlign: 'center',
+ text,
+ font: '18px monospace',
+ fill: new OlStyleFill({ color: 'white' }),
+ stroke: new OlStyleStroke({ color: 'black', width: 2 }),
+ overflow: true,
+ }),
}),
- text: new OlText({
- textAlign: 'center',
- text,
- font: '18px monospace',
- fill: new OlStyleFill({ color: 'white' }),
- stroke: new OlStyleStroke({ color: 'black', width: 2 }),
- overflow: true,
- }),
- }),
- ],
- });
+ ],
+ });
+ };
const drawFootprint = (granuleGeometry, date) => {
if (currentGranule[date]) {
@@ -376,7 +379,8 @@ export const granuleFootprint = (map) => {
const geometry = new OlGeomPolygon([granuleGeometry]);
const featureFootprint = new OlFeature({ geometry });
vectorSource.addFeature(featureFootprint);
- const newVectorLayer = getVectorLayer(date);
+ const showFill = map.getView().getZoom() < 3;
+ const newVectorLayer = getVectorLayer(date, showFill);
vectorLayer = newVectorLayer;
map.addLayer(vectorLayer);
};
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 8a252a31b..4d7ec5595 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -1223,7 +1223,6 @@ export default function mapui(models, config, store) {
}
});
map.on('moveend', (e) => {
- events.trigger('map:moveend');
setTimeout(() => {
self.mapIsbeingDragged = false;
self.mapIsbeingZoomed = false;
@@ -1261,28 +1260,27 @@ export default function mapui(models, config, store) {
* @todo move this component to another Location
*/
function createMousePosSel(map) {
- const throttledOnMouseMove = lodashThrottle((e) => {
+ const throttledOnMouseMove = lodashThrottle(({ pixel }) => {
const state = store.getState();
- const { browser, locationSearch, sidebar } = state;
+ const {
+ events, browser, locationSearch, sidebar, animation, measure,
+ } = state;
const { isCoordinateSearchActive } = locationSearch;
const isMobile = browser.lessThan.medium;
+ const coords = map.getCoordinateFromPixel(pixel);
+ const isEventsTabActive = typeof events !== 'undefined' && events.active;
+ const isMapAnimating = animation.isPlaying;
+
if (self.mapIsbeingZoomed) return;
+ if (self.mapIsbeingDragged) return;
if (compareMapUi && compareMapUi.dragging) return;
if (isMobile) return;
- if (state.measure.isActive) return;
+ if (measure.isActive) return;
if (isCoordinateSearchActive) return;
-
- const pixels = map.getEventPixel(e);
- const coords = map.getCoordinateFromPixel(pixels);
if (!coords) return;
-
- if (self.mapIsbeingDragged) return;
- // Don't add data runners if we're on the events or smart handoffs tabs, or if map is animating
- const isEventsTabActive = typeof state.events !== 'undefined' && state.events.active;
- const isMapAnimating = state.animation.isPlaying;
if (isEventsTabActive || isMapAnimating || sidebar.activeTab === 'download') return;
- runningdata.newPoint(pixels, map);
+ runningdata.newPoint(pixel, map);
}, 300);
events.on('map:mousemove', throttledOnMouseMove);