Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Fix processColormap error and add better logging

ZachTRiceaa9a51b4c1b6
diff --git a/tasks/build/getCapabilities.js b/tasks/build/getCapabilities.js
index e23c81244..5771aaa42 100644
--- a/tasks/build/getCapabilities.js
+++ b/tasks/build/getCapabilities.js
@@ -50,13 +50,13 @@ async function main () {
await getCapabilities()
if (colormaps) {
- await gatherProcess(colormaps, 'colormaps', colormapsDir, '.xml')
+ await gatherProcess(colormaps, 'colormap files', colormapsDir, '.xml')
}
if (vectorstyles) {
- await gatherProcess(vectorstyles, 'vectorstyles', vectorstylesDir, '.json')
+ await gatherProcess(vectorstyles, 'vectorstyle files', vectorstylesDir, '.json')
}
if (vectordata) {
- await gatherProcess(vectordata, 'vectordatas', vectordataDir, '.json')
+ await gatherProcess(vectordata, 'vectordata files', vectordataDir, '.json')
}
}
diff --git a/tasks/build/getVisMetadata.js b/tasks/build/getVisMetadata.js
index 07bbc1163..c635fcf3a 100644
--- a/tasks/build/getVisMetadata.js
+++ b/tasks/build/getVisMetadata.js
@@ -26,7 +26,7 @@ const options = yargs
type: 'string',
description: 'layer-metadata/all.json file'
})
- .epilog('Creates a layer metadata file containing all layers')
+ .epilog('Creates a layer-metadata file containing all layers')
const { argv } = options
if (!argv.features && !argv.layerOrder && !argv.layerMetadata) {
@@ -67,7 +67,7 @@ skipLayers = [
'World_Database_on_Protected_Areas'
]
-// NOTE: Only using these properties at this time
+// NOTE: Only using these properties at this time
useKeys = [
'conceptIds',
'dataCenter',
@@ -84,7 +84,7 @@ async function main (url) {
layerOrder = layerOrder.layerOrder
layerOrder = layerOrder.filter(x => !skipLayers.includes(x))
- console.warn(`${prog}: Pulling vis metadata for ${layerOrder.length} layers... `)
+ console.warn(`${prog}: Fetching ${layerOrder.length} layer-metadata files`)
for (layerId of layerOrder) {
await getMetadata(layerId, url)
}
@@ -98,6 +98,7 @@ async function main (url) {
)
await fs.writeFileSync(outputFile, JSON.stringify({ layers }))
+ console.warn(`${prog}: Created ${path.parse(outputFile).base} combined layer-metadata file`)
}
async function getDAAC (metadata) {
diff --git a/tasks/build/mergeConfigWithWMTS.js b/tasks/build/mergeConfigWithWMTS.js
index 935e53c66..5b3f6f2e2 100644
--- a/tasks/build/mergeConfigWithWMTS.js
+++ b/tasks/build/mergeConfigWithWMTS.js
@@ -50,7 +50,6 @@ async function main () {
async function processFiles () {
try {
- console.warn(inputDir)
const files = await fs.readdirSync(inputDir)
for (const file of files) {
if (!file.endsWith('.json')) continue
diff --git a/tasks/build/processColormap.js b/tasks/build/processColormap.js
index c8d6f8baa..8a4889472 100755
--- a/tasks/build/processColormap.js
+++ b/tasks/build/processColormap.js
@@ -245,41 +245,44 @@ async function readFileAsync (file) {
async function processFile (id, xml) {
let document
+ let colormaps
try {
document = JSON.parse(convert.xml2json(xml, { compact: true, spaces: 2 }))
- } catch (error) {
- console.warn(xml)
- }
- const colormaps = toList(document.ColorMaps.ColorMap)
- const maps = []
- for (const colormap of colormaps) {
- const result = await processEntries(colormap)
- if (result === 'transparent') {
- continue
- }
- result.title = colormap._attributes.title
- result.entries.title = colormap._attributes.title
- result.legend.title = colormap._attributes.title
- result.legend.id = `${id}_${maps.length}_legend`
- if ('minLabel' in colormap.Legend._attributes) {
- result.legend.minLabel = colormap.Legend._attributes.minLabel
+ if (document && document.ColorMaps && document.ColorMaps.ColorMap) {
+ colormaps = await toList(document.ColorMaps.ColorMap)
}
- if ('maxLabel' in colormap.Legend._attributes) {
- result.legend.maxLabel = colormap.Legend._attributes.maxLabel
+ const maps = []
+ for (const colormap of colormaps) {
+ const result = await processEntries(colormap)
+ if (result === 'transparent') {
+ continue
+ }
+ result.title = colormap._attributes.title
+ result.entries.title = colormap._attributes.title
+ result.legend.title = colormap._attributes.title
+ result.legend.id = `${id}_${maps.length}_legend`
+ if ('minLabel' in colormap.Legend._attributes) {
+ result.legend.minLabel = colormap.Legend._attributes.minLabel
+ }
+ if ('maxLabel' in colormap.Legend._attributes) {
+ result.legend.maxLabel = colormap.Legend._attributes.maxLabel
+ }
+ if ('units' in colormap._attributes) {
+ result.legend.units = colormap._attributes.units
+ }
+ maps.push(result)
}
- if ('units' in colormap._attributes) {
- result.legend.units = colormap._attributes.units
+
+ const data = {
+ id,
+ maps
}
- maps.push(result)
- }
- const data = {
- id,
- maps
+ const outputFile = path.join(outputDir, `${id}.json`)
+ await writeFile(outputFile, JSON.stringify(data, null, 2), { encoding: 'utf-8' })
+ } catch (error) {
+ console.error(error)
}
-
- const outputFile = path.join(outputDir, `${id}.json`)
- await writeFile(outputFile, JSON.stringify(data, null, 2), { encoding: 'utf-8' })
}
main().catch((err) => {
diff --git a/tasks/buildOptions.sh b/tasks/buildOptions.sh
index 25f271eec..ea3e0761f 100755
--- a/tasks/buildOptions.sh
+++ b/tasks/buildOptions.sh
@@ -48,24 +48,24 @@ mkdir -p "$DEST_DIR/config"
mkdir -p "$BUILD_DIR/colormaps"
# If $FETCH_GC is set, make various API requests
-# if [ "$FETCH_GC" ] ; then
-# # TODO: Fix axios fetch timeouts
-# # Fetch GC files and create colormaps, vectordata and vectorstyle files
-# rm -rf "$OPT_DIR/$OPT_SUBDIR/gc/*"
-# rm -rf "$OPT_DIR/$OPT_SUBDIR/colormaps/gc/*"
-# `node $SCRIPTS_DIR/getCapabilities.js \
-# --config "$OPT_DIR/$OPT_SUBDIR/config.json" \
-# --getcapabilities "$OPT_DIR/$OPT_SUBDIR/gc"`
-
-# # TODO: Optimize performance of this script
-# # Get metadata for files in layerOrder.json and combine this data into 1 file
-# rm -rf "$OPT_DIR/$OPT_SUBDIR/layer-metadata"
-# mkdir -p "$OPT_DIR/$OPT_SUBDIR/layer-metadata"
-# `node $SCRIPTS_DIR/getVisMetadata.js \
-# --features "$BUILD_DIR/features.json" \
-# --layerOrder "$BUILD_DIR/config/wv.json/layerOrder.json" \
-# --layerMetadata "$OPT_DIR/$OPT_SUBDIR/layer-metadata/all.json"`
-# fi
+if [ "$FETCH_GC" ] ; then
+ # TODO: Fix axios fetch timeouts
+ # Fetch GC files and create colormaps, vectordata and vectorstyle files
+ rm -rf "$OPT_DIR/$OPT_SUBDIR/gc/*"
+ rm -rf "$OPT_DIR/$OPT_SUBDIR/colormaps/gc/*"
+ `node $SCRIPTS_DIR/getCapabilities.js \
+ --config "$OPT_DIR/$OPT_SUBDIR/config.json" \
+ --getcapabilities "$OPT_DIR/$OPT_SUBDIR/gc"`
+
+ # TODO: Optimize performance of this script
+ # Get metadata for files in layerOrder.json and combine this data into 1 file
+ rm -rf "$OPT_DIR/$OPT_SUBDIR/layer-metadata"
+ mkdir -p "$OPT_DIR/$OPT_SUBDIR/layer-metadata"
+ `node $SCRIPTS_DIR/getVisMetadata.js \
+ --features "$BUILD_DIR/features.json" \
+ --layerOrder "$BUILD_DIR/config/wv.json/layerOrder.json" \
+ --layerMetadata "$OPT_DIR/$OPT_SUBDIR/layer-metadata/all.json"`
+fi
# Validate layers in wv.json with a JSON schema
`node $SCRIPTS_DIR/validateConfigs.js \