Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

fix selectedlayer issue and fix a test

Jason Kent7708dade9d72
diff --git a/e2e/features/compare/compare-test.js b/e2e/features/compare/compare-test.js
index 7126bf645..45042a5b0 100644
--- a/e2e/features/compare/compare-test.js
+++ b/e2e/features/compare/compare-test.js
@@ -62,7 +62,7 @@ module.exports = {
// Clicking does not switch tabs
c.click(dataDownloadTabButton);
c.pause(100);
- c.expect.element('#wv-datacontent').to.not.be.visible;
+ c.expect.element('#smart-handoff-side-panel').to.not.be.present;
},
'Events disabled when compare mode active': (c) => {
diff --git a/web/js/containers/sidebar/smart-handoff.js b/web/js/containers/sidebar/smart-handoff.js
index 2b5dee70b..05ec43323 100644
--- a/web/js/containers/sidebar/smart-handoff.js
+++ b/web/js/containers/sidebar/smart-handoff.js
@@ -42,7 +42,7 @@ class SmartHandoff extends Component {
x2: screenWidth / 2 + 100,
y2: screenHeight / 2 + 100,
},
- selectedLayer: {},
+ selectedLayer: undefined,
showBoundingBox: false,
isSearchingForGranules: false,
selectedGranules: 0,
@@ -73,9 +73,10 @@ class SmartHandoff extends Component {
} = this.state;
// Determine if existing selected layer is active still and visibility toggle is 'ON'
- const isLayerStillActive = activeLayers.find(({ conceptId }) => selectedLayer.conceptId === conceptId);
+ const selectedConceptId = selectedLayer && selectedLayer.conceptId;
+ const isLayerStillActive = activeLayers.find(({ conceptId }) => selectedConceptId === conceptId);
- if (!isLayerStillActive) {
+ if (selectedConceptId && !isLayerStillActive) {
this.resetState();
}
@@ -109,63 +110,63 @@ class SmartHandoff extends Component {
const { proj, map } = this.props;
const { selectedLayer } = this.state;
- if (selectedLayer.id) {
- const {
- x,
- y,
- width,
- height,
- } = boundaries;
-
- const newBoundaries = {
- x,
- y,
- x2: x + width,
- y2: y + height,
- };
-
- const lonlats = imageUtilGetCoordsFromPixelValues(
- newBoundaries,
- map.ui.selected,
- );
- const { crs } = proj;
-
- // Retrieve the lat/lon coordinates based on the defining boundary and map projection
- const geolonlat1 = olProj.transform(lonlats[0], crs, 'EPSG:4326');
- const geolonlat2 = olProj.transform(lonlats[1], crs, 'EPSG:4326');
-
- // Determine longitude out of bounds areas and reset to limits
- if (geolonlat1[0] > 180) geolonlat1[0] = 180;
- else if (geolonlat1[0] < -180) geolonlat1[0] = -180;
- if (geolonlat2[0] > 180) geolonlat2[0] = 180;
- else if (geolonlat2[0] < -180) geolonlat2[0] = -180;
-
- // Determine latitude out of bounds areas and reset to limits
- if (geolonlat1[1] > 90) geolonlat1[1] = 90;
- else if (geolonlat1[1] < -90) geolonlat1[1] = -90;
- if (geolonlat2[1] > 90) geolonlat2[1] = 90;
- else if (geolonlat2[1] < -90) geolonlat2[1] = -90;
-
- const currentExtent = {
- southWest: `${geolonlat1[0]},${geolonlat1[1]}`,
- northEast: `${geolonlat2[0]},${geolonlat2[1]}`,
- };
-
- const coordinates = {
- bottomLeft: util.formatCoordinate([geolonlat1[0], geolonlat1[1]]),
- topRight: util.formatCoordinate([geolonlat2[0], geolonlat2[1]]),
- };
-
- this.setState({
- boundaries: newBoundaries,
- coordinates,
- currentExtent,
- }, () => {
- if (selectedLayer && currentExtent) {
- this.debouncedUpdateExtent();
- }
- });
- }
+ if (!selectedLayer) return;
+
+ const {
+ x,
+ y,
+ width,
+ height,
+ } = boundaries;
+
+ const newBoundaries = {
+ x,
+ y,
+ x2: x + width,
+ y2: y + height,
+ };
+
+ const lonlats = imageUtilGetCoordsFromPixelValues(
+ newBoundaries,
+ map.ui.selected,
+ );
+ const { crs } = proj;
+
+ // Retrieve the lat/lon coordinates based on the defining boundary and map projection
+ const geolonlat1 = olProj.transform(lonlats[0], crs, 'EPSG:4326');
+ const geolonlat2 = olProj.transform(lonlats[1], crs, 'EPSG:4326');
+
+ // Determine longitude out of bounds areas and reset to limits
+ if (geolonlat1[0] > 180) geolonlat1[0] = 180;
+ else if (geolonlat1[0] < -180) geolonlat1[0] = -180;
+ if (geolonlat2[0] > 180) geolonlat2[0] = 180;
+ else if (geolonlat2[0] < -180) geolonlat2[0] = -180;
+
+ // Determine latitude out of bounds areas and reset to limits
+ if (geolonlat1[1] > 90) geolonlat1[1] = 90;
+ else if (geolonlat1[1] < -90) geolonlat1[1] = -90;
+ if (geolonlat2[1] > 90) geolonlat2[1] = 90;
+ else if (geolonlat2[1] < -90) geolonlat2[1] = -90;
+
+ const currentExtent = {
+ southWest: `${geolonlat1[0]},${geolonlat1[1]}`,
+ northEast: `${geolonlat2[0]},${geolonlat2[1]}`,
+ };
+
+ const coordinates = {
+ bottomLeft: util.formatCoordinate([geolonlat1[0], geolonlat1[1]]),
+ topRight: util.formatCoordinate([geolonlat2[0], geolonlat2[1]]),
+ };
+
+ this.setState({
+ boundaries: newBoundaries,
+ coordinates,
+ currentExtent,
+ }, () => {
+ if (selectedLayer && currentExtent) {
+ this.debouncedUpdateExtent();
+ }
+ });
}
/**
@@ -185,12 +186,13 @@ class SmartHandoff extends Component {
*/
async updateGranuleCount(currentExtent) {
const { selectedDate } = this.props;
-
const {
selectedLayer,
showBoundingBox,
} = this.state;
+ if (!selectedLayer) return;
+
// Places the compoent state in a loading state; triggers {...} animation.
this.setState({ isSearchingForGranules: true });
@@ -270,7 +272,7 @@ class SmartHandoff extends Component {
const showModal = safeLocalStorage.getItem(HIDE_EDS_WARNING);
// Determine if the download button is enabled
- const isValidDownload = selectedLayer.id !== undefined;
+ const isValidDownload = selectedLayer && selectedLayer.id !== undefined;
const availableLayers = activeLayers.filter((layer) => layer.conceptId !== undefined).length;
const areThereLayersToDownload = availableLayers > 0;
@@ -303,7 +305,7 @@ class SmartHandoff extends Component {
type="radio"
value={layer.conceptId}
name="smart-handoff-layer-radio"
- checked={selectedLayer.id === layer.id}
+ checked={selectedLayer && selectedLayer.id === layer.id}
onChange={() => this.onLayerChange(layer, currentExtent)}
/>
<label htmlFor={layer.id}>{layer.title}</label>
@@ -326,7 +328,7 @@ class SmartHandoff extends Component {
checked={showBoundingBox}
onCheck={() => {
this.setState({ showBoundingBox: !showBoundingBox }, () => {
- if (selectedLayer.id) this.updateGranuleCount(currentExtent);
+ if (selectedLayer && selectedLayer.id) this.updateGranuleCount(currentExtent);
});
}}
/>