Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2296

Jason Kent9e7b26557600
diff --git a/web/js/combine-ui.js b/web/js/combine-ui.js
index 6c1f98db6..01f90ae87 100644
--- a/web/js/combine-ui.js
+++ b/web/js/combine-ui.js
@@ -54,6 +54,9 @@ function registerMapMouseHandlers(maps) {
element.addEventListener('mouseleave', (event) => {
events.trigger('map:mouseout', event);
});
+ map.on('moveend', (event) => {
+ events.trigger('map:moveend', event, map, crs);
+ });
map.on('pointermove', (event) => {
events.trigger('map:mousemove', event, map, crs);
});
diff --git a/web/js/containers/map-interactions/ol-vector-interactions.js b/web/js/containers/map-interactions/ol-vector-interactions.js
index c37a20cf5..423ac9fca 100644
--- a/web/js/containers/map-interactions/ol-vector-interactions.js
+++ b/web/js/containers/map-interactions/ol-vector-interactions.js
@@ -32,36 +32,41 @@ const { events } = util;
export class VectorInteractions extends React.Component {
constructor(props) {
super(props);
+ this.state = {
+ granuleDate: null,
+ granulePlatform: null,
+ };
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.moveEnd = this.moveEnd.bind(this);
this.singleClick = this.singleClick.bind(this);
}
componentDidMount() {
+ events.on('map:moveend', this.moveEnd);
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:moveend', this.moveEnd);
events.off('map:mousemove', this.mouseMove);
- // events.off('map:moveend', this.mouseMove);
events.off('map:mouseout', this.mouseOut);
events.off('map:singleclick', this.singleClick);
}
+ clearGranuleFootprint() {
+ this.setState({ granuleDate: null, granulePlatform: null });
+ events.trigger('granule-hovered', null);
+ }
+
/**
* Handle mouse over granule geometry and trigger action to show granule date footprint
*
- * @param {Object} granuleFootprints
- * @param {Object} map
- * @param {String} crs
* @param {Array} pixels
* @param {Array} coord
- *
- * @return {Boolean} to indicate if valid for parent mouseMove function
*/
handleGranuleHover = (pixels, mouseCoords) => {
const {
@@ -71,68 +76,40 @@ export class VectorInteractions extends React.Component {
swipeOffset,
visibleExtent,
} = this.props;
- const { active, activeString } = compareState;
+ const { active: compareActive, activeString } = compareState;
const polygon = new OlGeomPolygon([]);
let toggledGranuleFootprint;
// only allow hover footprints on selected side of A/B comparison
- if (active) {
- const isOnActiveCompareSide = isFromActiveCompareRegion(pixels, activeString, compareState, swipeOffset);
- if (!isOnActiveCompareSide) {
- events.trigger('granule-hovered', null);
- return false;
- }
+ if (compareActive && !isFromActiveCompareRegion(pixels, activeString, compareState, swipeOffset)) {
+ return;
}
// check if coordinates and polygon extent are within and not exceeding max extent
Object
.keys(granuleFootprints)
- .map((key) => ({ [key]: granuleFootprints[key] }))
- .forEach((footprint) => {
- const [date] = Object.keys(footprint);
- const [points] = Object.values(footprint);
+ .forEach((date) => {
+ const points = granuleFootprints[date];
polygon.setCoordinates([points]);
const isValidPolygon = areCoordinatesAndPolygonExtentValid(polygon, mouseCoords, visibleExtent);
if (isValidPolygon) {
toggledGranuleFootprint = true;
events.trigger('granule-hovered', granulePlatform, date);
+ this.setState({ granulePlatform, granuleDate: date });
}
});
if (!toggledGranuleFootprint) {
- events.trigger('granule-hovered', granulePlatform, null);
+ this.clearGranuleFootprint();
}
- return true;
}
- mouseOut = () => {
- this.mouseMove.cancel();
- events.trigger('granule-hovered', null);
- }
-
- mouseMove({ pixel }, map, crs) {
+ handleCursorChange(pixel, map, lon, lat) {
const {
- isShowingClick, changeCursor, isCoordinateSearchActive, measureIsActive, compareState, swipeOffset, proj, granuleFootprints,
+ isShowingClick, changeCursor, measureIsActive, compareState, swipeOffset, proj,
} = this.props;
-
- if (measureIsActive || isCoordinateSearchActive || !pixel) {
- return;
- }
- 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(pixel, coord);
- if (!isValidGranule) {
- return;
- }
- }
-
- const [lon, lat] = transform(coord, crs, 'EPSG:4326');
- if (lon < -250 || lon > 250 || lat < -90 || lat > 90) {
- return;
- }
const hasFeatures = map.hasFeatureAtPixel(pixel);
+
if (hasFeatures && !isShowingClick && !measureIsActive) {
let isActiveLayer = false;
map.forEachFeatureAtPixel(pixel, (feature, layer) => {
@@ -146,13 +123,43 @@ export class VectorInteractions extends React.Component {
});
if (isActiveLayer) {
changeCursor(true);
- return true;
}
} else if (!hasFeatures && isShowingClick) {
changeCursor(false);
}
}
+ moveEnd() {
+ const { granuleDate, granulePlatform } = this.state;
+ if (granuleDate && granulePlatform) {
+ events.trigger('granule-hover-update', granulePlatform, granuleDate);
+ }
+ }
+
+ mouseOut = () => {
+ this.mouseMove.cancel();
+ events.trigger('granule-hovered', null);
+ }
+
+ mouseMove({ pixel }, map, crs) {
+ const {
+ isCoordinateSearchActive, measureIsActive, granuleFootprints,
+ } = this.props;
+ const coord = map.getCoordinateFromPixel(pixel);
+ const [lon, lat] = transform(coord, crs, 'EPSG:4326');
+
+ if (measureIsActive || isCoordinateSearchActive) {
+ return;
+ }
+ if (lon < -250 || lon > 250 || lat < -90 || lat > 90) {
+ return;
+ }
+ if (granuleFootprints) {
+ this.handleGranuleHover(pixel, coord);
+ }
+ this.handleCursorChange(pixel, map, lon, lat);
+ }
+
singleClick(e, map) {
const {
browser, lastSelected, openVectorDialog, onCloseModal, selectVectorFeatures,
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 57f66c60f..a6389ebb2 100644
--- a/web/js/containers/map-interactions/ol-vector-interactions.test.js
+++ b/web/js/containers/map-interactions/ol-vector-interactions.test.js
@@ -48,6 +48,7 @@ beforeEach(() => {
test('if there is a feature at pixel dispatch changeCursor action', () => {
map.hasFeatureAtPixel = () => true;
+ map.forEachFeatureAtPixel = () => {};
events.trigger('map:mousemove', {}, map, 'EPSG:3413');
doAsync(() => expect(changeCursor.mock.calls.length).toBe(1));
});
diff --git a/web/js/map/granule/util.js b/web/js/map/granule/util.js
index ed278be37..0ac3c54b5 100644
--- a/web/js/map/granule/util.js
+++ b/web/js/map/granule/util.js
@@ -359,33 +359,44 @@ export const granuleFootprint = (map) => {
});
};
- const drawFootprint = (granuleGeometry, date) => {
+ const removeFootprint = () => {
+ currentGranule = {};
+ map.removeLayer(vectorLayer);
+ vectorSource.clear();
+ };
+
+ const drawFootprint = (points, date) => {
+ const geometry = new OlGeomPolygon([points]);
+ const featureFootprint = new OlFeature({ geometry });
+ const showFill = map.getView().getZoom() < 3;
+ const newVectorLayer = getVectorLayer(date, showFill);
+ vectorSource.addFeature(featureFootprint);
+ vectorLayer = newVectorLayer;
+ map.addLayer(vectorLayer);
+ };
+
+ const addFootprint = (points, date) => {
if (currentGranule[date]) {
return;
}
- const clearGranule = () => {
- currentGranule = {};
- map.removeLayer(vectorLayer);
- vectorSource.clear();
- };
- if (!currentGranule[date]) {
- clearGranule();
- }
- if (!granuleGeometry || !date) {
- clearGranule();
+ if (!points || !date) {
+ removeFootprint();
return;
}
+ if (!currentGranule[date]) {
+ removeFootprint();
+ }
currentGranule[date] = true;
- const geometry = new OlGeomPolygon([granuleGeometry]);
- const featureFootprint = new OlFeature({ geometry });
- vectorSource.addFeature(featureFootprint);
- const showFill = map.getView().getZoom() < 3;
- const newVectorLayer = getVectorLayer(date, showFill);
- vectorLayer = newVectorLayer;
- map.addLayer(vectorLayer);
+ drawFootprint(points, date);
+ };
+
+ const updateFootprint = (points, date) => {
+ removeFootprint();
+ drawFootprint(points, date);
};
return {
- drawFootprint,
+ addFootprint,
+ updateFootprint,
};
};
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 4d7ec5595..26430ad35 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -253,14 +253,24 @@ export default function mapui(models, config, store) {
}
};
- const onGranuleHover = (instrument, date) => {
+ const onGranuleHover = (platform, date, update) => {
const state = store.getState();
const proj = self.selected.getView().getProjection().getCode();
let geometry;
- if (instrument && date) {
+ if (platform && date) {
geometry = getActiveGranuleFootPrints(state)[date];
}
- return granuleFootprints[proj].drawFootprint(geometry, date);
+ granuleFootprints[proj].addFootprint(geometry, date);
+ };
+
+ const onGranuleHoverUpdate = (platform, date) => {
+ const state = store.getState();
+ const proj = self.selected.getView().getProjection().getCode();
+ let geometry;
+ if (platform && date) {
+ geometry = getActiveGranuleFootPrints(state)[date];
+ }
+ granuleFootprints[proj].updateFootprint(geometry, date);
};
/**
@@ -300,6 +310,7 @@ export default function mapui(models, config, store) {
});
events.on('redux:action-dispatched', subscribeToStore);
events.on('granule-hovered', onGranuleHover);
+ events.on('granule-hover-update', onGranuleHoverUpdate);
window.addEventListener('orientationchange', () => {
setTimeout(() => { updateProjection(true); }, 200);
});