Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

show measurement metadata in layer info modal

Jason Kent5acfb063a28d
diff --git a/web/js/components/layer/info/info-modal.js b/web/js/components/layer/info/info-modal.js
index afc46bbb2..142df29da 100644
--- a/web/js/components/layer/info/info-modal.js
+++ b/web/js/components/layer/info/info-modal.js
@@ -1,22 +1,38 @@
-import React from 'react';
+import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import LayerInfo from './info';
-import Scrollbars from '../../util/scrollbar';
+import util from '../../../util/util';
export default function LayerInfoModal(props) {
- const { screenHeight, layer } = props;
+ const { layer, measurementDescriptionPath } = props;
+ const [metadata, setMetadata] = useState();
+
+ const initMetadata = async () => {
+ if (!metadata && measurementDescriptionPath) {
+ const url = `config/metadata/layers/${measurementDescriptionPath}.html`;
+ const data = await util.get(url);
+ setMetadata(data || 'No metadata found.');
+ }
+ };
+
+ useEffect(() => {
+ initMetadata();
+ }, [layer]);
return (
- <Scrollbars style={{ maxHeight: `${screenHeight - 200}px` }}>
+ <div id="layer-description" className="layer-description">
<LayerInfo layer={layer} />
- {/*
- Put the source specific metadata here as well
- */}
- </Scrollbars>
+ {metadata && (
+ <div
+ className="layer-metadata"
+ dangerouslySetInnerHTML={{ __html: metadata }}
+ />
+ )}
+ </div>
);
}
LayerInfoModal.propTypes = {
- screenHeight: PropTypes.number,
layer: PropTypes.object,
+ measurementDescriptionPath: PropTypes.string,
};
diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.js
index 5d412162d..6c1143331 100644
--- a/web/js/modules/layers/selectors.js
+++ b/web/js/modules/layers/selectors.js
@@ -146,6 +146,17 @@ export function hasMeasurementSource(current, config, projId) {
return hasSource;
}
+export const makeGetDescription = () => createSelector(
+ [getConfig, getLayerId],
+ (config, layerId) => {
+ const measurements = Object.values(config.measurements);
+ const [setting] = measurements
+ .flatMap(({ sources }) => Object.values(sources))
+ .filter(({ settings }) => settings.find((id) => id === layerId));
+ return (setting || {}).description;
+ },
+);
+
/**
* Look up the measurement description path for a given layer
* so that metadata can be shown in the layer info modal. Ignore