Interactive interface for browsing global, full-resolution satellite imagery
Fast-reloading vectorstyle dev option added (#6987)
christof-wittreich62f977ab0bf2
diff --git a/doc/config/vectors.md b/doc/config/vectors.mdindex 7039c11ca..f783511ca 100644--- a/doc/config/vectors.md+++ b/doc/config/vectors.md@@ -110,3 +110,11 @@ For more information on how to configure a mapbox-gl-js style spec, please refer## Vector MetadataVector layers created from the Global Imagery Browse Services (GIBS) will have a metadata JSON file associated with the layer defined in the GIBS WMTS GetCapabilities document. This metadata document describes features contained within the MVT file. This data is available to give context to the features stored within a layer. This information can be seen when a user clicks on a vector data point. A modal will appear with labels, values and tooltips. The data from this document appears within the tooltip element.++## Vectorstyle Live-Reloading for Development++To have a live-reloading vectorstyle for a particular layer:+1. Create a copy of the vectorstyle json file from `config/default/common/vectorstyles` and place it in `web/config`.+2. Add the layer ID to the **liveFetchLayers** array in `vector-styles/selectors.js`.++The vectorstyle json file in `web/config` can now be modified as needed, and the style will update after the page refreshes. This process should only be used for faster development of the vector styling, and should not be used in deployment.diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.jsindex bb7b059c2..41729fd70 100644--- a/web/js/modules/layers/util.js+++ b/web/js/modules/layers/util.js@@ -701,6 +701,23 @@ export async function fetchSubdailyDateRanges(id) {}}+/**+ * Return the vectorstyles object of a given layer for live-reloading development purposes+ *+ * @method fetchVectorstyle+ * @param {String} def The layer id+ * @return {Promise<Object>} The vectorstyles object+ */+export async function fetchVectorstyle(id) {+ try {+ const response = await fetch(`config/${id}.json`);+ const result = await response.json();+ return result;+ } catch {+ return null;+ }+}+/*** Return an array of dates based on the dateRange the current date falls in.*diff --git a/web/js/modules/layers/util.test.js b/web/js/modules/layers/util.test.jsindex a1bf94f3a..74eca9c12 100644--- a/web/js/modules/layers/util.test.js+++ b/web/js/modules/layers/util.test.js@@ -2,6 +2,8 @@ import { assign } from 'lodash';import {adjustActiveDateRanges,datesInDateRanges,+ fetchSubdailyDateRanges,+ fetchVectorstyle,serializeLayers,layersParse12,mapLocationToLayerState,@@ -289,6 +291,14 @@ describe('Date range building', () => {expect(dateRanges.length).toBe(4);expect(dateRanges[3].endDate).toBe('2021-04-30T16:00:00Z');});+ test('test invalid layerid returns empty array [invalid-fetch-subdaily-dateranges]', async () => {+ const dateRanges = await fetchSubdailyDateRanges('non-valid-layer-id');+ expect(dateRanges.length).toBe(0);+ });+ test('test invalid layerid returns null [invalid-fetch-vectorstyle]', async () => {+ const vectorstyleObject = await fetchVectorstyle('non-valid-layer-id');+ expect(vectorstyleObject).toBe(null);+ });test('test limited date range returned for layer with single date range and interval [layers-limited-date-range]', async () => {const parameters = {products: 'terra-cr',diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.jsindex 2fbe198c0..45046b9db 100644--- a/web/js/modules/vector-styles/selectors.js+++ b/web/js/modules/vector-styles/selectors.js@@ -17,6 +17,11 @@ import {getLookup as getPaletteLookup,} from '../palettes/selectors';import util from '../../util/util';+import { fetchVectorstyle } from '../layers/util';++// Array of vector layer IDs to have their vectorstyle live fetched from `web/config`+// * For use in local dev environment only *+const liveFetchLayers = [];/*** Get OpenLayers layers from state that were created from WV vector@@ -169,6 +174,7 @@ export function setStyleFunction(opts) {state,vectorStyleSource,styleSelection = false,+ manualStyle,} = opts;const map = lodashGet(state, 'map.ui.selected');if (!map) return undefined;@@ -192,6 +198,10 @@ export function setStyleFunction(opts) {}}+ if (manualStyle) {+ glStyle = manualStyle;+ }+// De-reference the glState object prior to applying the palette to the layerglStyle = lodashCloneDeep(glStyle);@@ -356,7 +366,7 @@ export function clearStyleFunction(def, vectorStyleId, vectorStyles, layerObj, s* @param {Object} state* @param {Object} options*/-export const applyStyle = (def, olVectorLayer, state, options, resolutions) => {+export const applyStyle = async (def, olVectorLayer, state, options, resolutions) => {const { config } = state;const { vectorStyles } = config;const vectorStyleId = def.vectorStyle.id;@@ -377,5 +387,13 @@ export const applyStyle = (def, olVectorLayer, state, options, resolutions) => {...resolutions && { resolutions },};+ // Fetch live vectorstyle if layer is in liveFetchLayers+ if (liveFetchLayers.includes(def.id)) {+ const fetchedStyle = await fetchVectorstyle(def.id);+ if (fetchedStyle) {+ opts.manualStyle = fetchedStyle;+ }+ }+setStyleFunction(opts);};