Interactive interface for browsing global, full-resolution satellite imagery
Fix layers / sources output in wv.json _wmts merge
ZachTRice68701afb336a
diff --git a/tasks/build-options/mergeConfigWithWMTS.js b/tasks/build-options/mergeConfigWithWMTS.jsindex 5f1b28e66..0ce247d13 100644--- a/tasks/build-options/mergeConfigWithWMTS.js+++ b/tasks/build-options/mergeConfigWithWMTS.js@@ -29,6 +29,7 @@ const inputDir = argv.inputDirconst outputFile = argv.outputFilelet newConf = {}+let layers = {}newConf.layers = {}newConf.sources = {}@@ -36,8 +37,11 @@ const outputData = JSON.parse(fs.readFileSync(outputFile, 'utf-8'))let fileCount = 0async function main () {+ layers = newConf.layers+ delete layers.sources+ delete newConf.layers+ newConf = dictMerge(newConf, outputData)await processFiles()- newConf = await dictMerge(newConf, outputData)const jsonOptions = {}jsonOptions.indent = 2@@ -57,8 +61,8 @@ async function processFiles () {try {const data = fs.readFileSync(path.join(inputDir, file), 'utf-8')const jsonData = JSON.parse(data)- newConf.layers = await wmtsDictMerge(newConf.layers, jsonData, outputData)- newConf.sources = await dictMerge(newConf.sources, jsonData.sources, outputData.sources)+ newConf.layers = await wmtsDictMerge(layers, jsonData, outputData)+ newConf.sources = dictMerge(newConf.sources, jsonData.sources, outputData.sources)} catch (error) {throw new Error(`ERROR: ${path.join(inputDir, file)}: ${error.message}`)}@@ -68,30 +72,10 @@ async function processFiles () {}}-// function wmtsDictMerge (target, obj, conf) {-// // console.warn(conf.layers)--// if (typeof obj !== 'object') {-// return obj-// }--// target = conf.map(item => ({-// ...obj.find(({ layers }) => item.layers === layers),-// ...item-// }))-// console.warn(target)-// return target-// }-async function wmtsDictMerge (target, obj, conf) {- obj = obj.layers-- // conf = conf.layers-- if (typeof obj !== 'object') {+ if (!(obj instanceof Object)) {return obj}-for (const [k, v] of Object.entries(obj)) {if (k in conf && typeof conf[k] === 'object') {let foundSourceMisMatch = false@@ -113,13 +97,13 @@ async function wmtsDictMerge (target, obj, conf) {continue}if (k in target && typeof target[k] === 'object') {- target[k] = wmtsDictMerge(target[k], v, conf[k])+ target[k] = dictMerge(target[k], v, conf[k])} else {- target[k] = wmtsDictMerge(v, conf[k])+ target[k] = dictMerge(v, conf[k])}}}- return target+ return target.layers}main().catch((err) => {diff --git a/tasks/build-options/util.js b/tasks/build-options/util.jsindex fcc7c64d9..cef9acf25 100644--- a/tasks/build-options/util.js+++ b/tasks/build-options/util.js@@ -1,5 +1,5 @@-async function deepCopy (obj) {- if (typeof obj !== 'object') {+function deepCopy (obj) {+ if (!(obj instanceof Object)) {return obj}let copy@@ -10,36 +10,31 @@ async function deepCopy (obj) {}for (const key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {- copy[key] = await deepCopy(obj[key])+ copy[key] = deepCopy(obj[key])}}return copy}-async function dictMerge (target, ...args) {+function dictMerge (target, ...args) {// Merge multiple objectsif (args.length > 1) {for (const obj of args) {- await dictMerge(target, obj)+ dictMerge(target, obj)}return target}// Recursively merge objects and set non-object valuesconst obj = args[0]- if (typeof obj !== 'object' || obj === null) {+ if (!(obj instanceof Object)) {return obj}for (const [k, v] of Object.entries(obj)) {- if (k in target && typeof target[k] === 'object' && target[k] !== null) {- if ('type' in v && 'type' in target[k]) {- if (v.type !== target[k].type) {- return target- }- }- await dictMerge(target[k], v)+ if (k in target && (target[k] instanceof Object)) {+ target[k] = dictMerge(target[k], v)} else {- target[k] = await deepCopy(v)+ target[k] = deepCopy(v)}}return targetdiff --git a/tasks/buildOptions.sh b/tasks/buildOptions.shindex 8896f9b28..8635e01de 100755--- a/tasks/buildOptions.sh+++ b/tasks/buildOptions.sh@@ -47,9 +47,10 @@ fimkdir -p "$DEST_DIR/config"mkdir -p "$BUILD_DIR/colormaps"+# TODO: dataCenter merging is not working properly, check the wv.json file+# # 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/*"@@ -57,7 +58,6 @@ mkdir -p "$BUILD_DIR/colormaps"# --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"@@ -140,11 +140,6 @@ for config in $configs; doesacdone-# TODO: Missing the following variables in wv.json layers-# type, format, period, startDate, endDate, dateRanges, projections,-# palette, dataCenter,-# this means _wmts .json files are not getting merged into wv.json properly-# Run mergeConfigWithWMTS.js to merge layer metadata from WMTS GC with worldview layer configs into wv.json`node $SCRIPTS_DIR/mergeConfigWithWMTS.js \--inputDir "$BUILD_DIR/_wmts" \