Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

fix wv.json merge errors wip

ZachTRice3782118c76d9
diff --git a/tasks/build-options/extractConfigFromWMTS.js b/tasks/build-options/extractConfigFromWMTS.js
index ffed4f810..ac0ea3882 100644
--- a/tasks/build-options/extractConfigFromWMTS.js
+++ b/tasks/build-options/extractConfigFromWMTS.js
@@ -309,18 +309,17 @@ function processMatrixSet (gcMatrixSet) {
for (const tileMatrix of tileMatrixArr) {
formattedTileMatrixArr.push({
- matrixWidth: parseInt(tileMatrix.MatrixWidth, 10),
- matrixHeight: parseInt(tileMatrix.MatrixHeight, 10)
+ matrixWidth: parseInt(tileMatrix.MatrixWidth._text, 10),
+ matrixHeight: parseInt(tileMatrix.MatrixHeight._text, 10)
})
}
-
wvMatrixSets[ident] = {
id: ident,
maxResolution,
resolutions,
tileSize: [
- parseInt(tileMatrixArr[0].TileWidth, 10),
- parseInt(tileMatrixArr[0].TileHeight, 10)
+ parseInt(tileMatrixArr[0].TileWidth._text, 10),
+ parseInt(tileMatrixArr[0].TileHeight._text, 10)
],
tileMatrices: formattedTileMatrixArr
}
diff --git a/tasks/build-options/mergeConfig.js b/tasks/build-options/mergeConfig.js
index 8ec596d76..6a36b8ac7 100644
--- a/tasks/build-options/mergeConfig.js
+++ b/tasks/build-options/mergeConfig.js
@@ -39,7 +39,7 @@ async function main () {
}
async function mergeFiles (inputDir) {
- const files = await fs.readdirSync(inputDir)
+ const files = fs.readdirSync(inputDir)
for (const file of files) {
try {
if (file.endsWith('.json')) {
diff --git a/tasks/build-options/mergeConfigWithWMTS.js b/tasks/build-options/mergeConfigWithWMTS.js
index 5b3f6f2e2..ef82ba5ac 100644
--- a/tasks/build-options/mergeConfigWithWMTS.js
+++ b/tasks/build-options/mergeConfigWithWMTS.js
@@ -50,12 +50,12 @@ async function main () {
async function processFiles () {
try {
- const files = await fs.readdirSync(inputDir)
+ const files = fs.readdirSync(inputDir)
for (const file of files) {
if (!file.endsWith('.json')) continue
fileCount += 1
try {
- const data = await fs.readFile(path.join(inputDir, file), 'utf-8')
+ const data = fs.readFileSync(path.join(inputDir, file), 'utf-8')
const jsonData = JSON.parse(data)
newConf.layers = wmtsDictMerge(newConf.layers, jsonData, outputData)
newConf.sources = dictMerge(newConf.sources, jsonData.sources, outputData.sources)
@@ -68,19 +68,38 @@ 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
+// }
+
function wmtsDictMerge (target, obj, conf) {
- if (typeof obj !== 'object' || !Object.prototype.hasOwnProperty.call(obj, 'layers')) return obj
- if (typeof conf !== 'object' || !Object.prototype.hasOwnProperty.call(conf, 'layers')) return obj
+ obj = obj.layers
+ // conf = conf.layers
- for (const [k, v] of Object.entries(obj.layers)) {
- if (Object.prototype.hasOwnProperty.call(conf.layer, k) && typeof conf.layers[k] === 'object') {
+ if (typeof obj !== 'object') {
+ return obj
+ }
+
+ for (const [k, v] of Object.entries(obj)) {
+ if (k in conf && typeof conf[k] === 'object') {
let foundSourceMisMatch = false
- if (Object.prototype.hasOwnProperty.call(v, 'projections') && Object.prototype.hasOwnProperty.call(conf.layers[k], 'projections')) {
- const confProjections = conf.layers[k].projections
+ if ('projections' in v && 'projections' in conf[k]) {
+ const confProjections = conf[k].projections
for (const [projectionKey, projection] of Object.entries(v.projections)) {
const source = projection.source
- if (Object.prototype.hasOwnProperty.call(confProjections, projectionKey)) {
- if (Object.prototype.hasOwnProperty.call(confProjections[projectionKey], 'source')) {
+ if (projectionKey in confProjections) {
+ if ('source' in confProjections[projectionKey]) {
if (source !== confProjections[projectionKey].source) {
foundSourceMisMatch = true
continue
@@ -89,11 +108,13 @@ function wmtsDictMerge (target, obj, conf) {
}
}
}
- if (foundSourceMisMatch) continue
- if (Object.prototype.hasOwnProperty.call(target, k) && typeof target[k] === 'object') {
- dictMerge(target[k], v, conf.layers[k])
+ if (foundSourceMisMatch) {
+ continue
+ }
+ if (k in target && typeof target[k] === 'object') {
+ target[k] = wmtsDictMerge(target[k], v, conf[k])
} else {
- target[k] = dictMerge(v, conf.layers[k])
+ target[k] = wmtsDictMerge(v, conf[k])
}
}
}
diff --git a/tasks/buildOptions.sh b/tasks/buildOptions.sh
index 3d5e2d7e4..43ce6a8ed 100755
--- a/tasks/buildOptions.sh
+++ b/tasks/buildOptions.sh
@@ -76,7 +76,6 @@ if [ -e "$BUILD_DIR/features.json" ] ; then
cp "$BUILD_DIR/features.json" "$BUILD_DIR/config/wv.json/_features.json"
fi
-# TODO: Fix _wmts wvMatrixSets entries
# Run extractConfigFromWMTS.js script with config.json
if [ -e "$BUILD_DIR/config.json" ] ; then
`node $SCRIPTS_DIR/extractConfigFromWMTS.js \
@@ -85,69 +84,69 @@ if [ -e "$BUILD_DIR/config.json" ] ; then
--outputDir "$BUILD_DIR/_wmts"`
fi
-# # Run processVectorStyles.js and move vectorstyles where we want them
-# if [ -e "$BUILD_DIR/gc/vectorstyles" ] ; then
-# mkdir -p "$BUILD_DIR/config/wv.json/vectorstyles"
-# `node $SCRIPTS_DIR/processVectorStyles.js \
-# --inputDir "$BUILD_DIR/gc/vectorstyles" \
-# --outputDir "$BUILD_DIR/config/wv.json/vectorstyles"`
-# fi
+# Run processVectorStyles.js and move vectorstyles where we want them
+if [ -e "$BUILD_DIR/gc/vectorstyles" ] ; then
+ mkdir -p "$BUILD_DIR/config/wv.json/vectorstyles"
+ `node $SCRIPTS_DIR/processVectorStyles.js \
+ --inputDir "$BUILD_DIR/gc/vectorstyles" \
+ --outputDir "$BUILD_DIR/config/wv.json/vectorstyles"`
+fi
-# # Run processVectorData.js and move vectordata where we want them
-# if [ -e "$BUILD_DIR/gc/vectordata" ] ; then
-# mkdir -p "$BUILD_DIR/config/wv.json/vectordata"
-# `node $SCRIPTS_DIR/processVectorData.js \
-# --inputDir "$BUILD_DIR/gc/vectordata" \
-# --outputDir "$BUILD_DIR/config/wv.json/vectordata"`
-# fi
+# Run processVectorData.js and move vectordata where we want them
+if [ -e "$BUILD_DIR/gc/vectordata" ] ; then
+ mkdir -p "$BUILD_DIR/config/wv.json/vectordata"
+ `node $SCRIPTS_DIR/processVectorData.js \
+ --inputDir "$BUILD_DIR/gc/vectordata" \
+ --outputDir "$BUILD_DIR/config/wv.json/vectordata"`
+fi
-# # TODO: fix erroneous data in files
-# # Run processColormap.js and move colormaps where we want them
-# if [ -e "$BUILD_DIR/colormaps" ] ; then
-# mkdir -p "$BUILD_DIR"/config/palettes
-# if [ -d "$BUILD_DIR"/gc/colormaps ] ; then
-# cp -r "$BUILD_DIR"/gc/colormaps "$BUILD_DIR"/colormaps/gc
-# fi
-# `node $SCRIPTS_DIR/processColormap.js \
-# --config "$OPT_DIR/$OPT_SUBDIR/config.json" \
-# --inputDir "$BUILD_DIR/colormaps" \
-# --outputDir "$BUILD_DIR/config/palettes"`
-# fi
+# TODO: fix erroneous data in files
+# Run processColormap.js and move colormaps where we want them
+if [ -e "$BUILD_DIR/colormaps" ] ; then
+ mkdir -p "$BUILD_DIR"/config/palettes
+ if [ -d "$BUILD_DIR"/gc/colormaps ] ; then
+ cp -r "$BUILD_DIR"/gc/colormaps "$BUILD_DIR"/colormaps/gc
+ fi
+ `node $SCRIPTS_DIR/processColormap.js \
+ --config "$OPT_DIR/$OPT_SUBDIR/config.json" \
+ --inputDir "$BUILD_DIR/colormaps" \
+ --outputDir "$BUILD_DIR/config/palettes"`
+fi
-# # Throw error if no categoryGroupOrder.json file present
-# if [ ! -e "$BUILD_DIR/config/wv.json/categoryGroupOrder.json" ] ; then
-# echo "categoryGroupOrder.json not found. Generating..."
-# `node $SCRIPTS_DIR/generateCategoryGroupOrder.js \
-# --inputDir "$SRC_DIR/common/config/wv.json/categories/" \
-# --outputDir "$SRC_DIR/common/config/wv.json/"`
-# fi
+# Throw error if no categoryGroupOrder.json file present
+if [ ! -e "$BUILD_DIR/config/wv.json/categoryGroupOrder.json" ] ; then
+ echo "categoryGroupOrder.json not found. Generating..."
+ `node $SCRIPTS_DIR/generateCategoryGroupOrder.js \
+ --inputDir "$SRC_DIR/common/config/wv.json/categories/" \
+ --outputDir "$SRC_DIR/common/config/wv.json/"`
+fi
-# if [ -e "$OPT_DIR/$OPT_SUBDIR/layer-metadata/all.json" ] ; then
-# cp "$OPT_DIR/$OPT_SUBDIR/layer-metadata/all.json" "$BUILD_DIR/config/wv.json/layer-metadata.json"
-# fi
+if [ -e "$OPT_DIR/$OPT_SUBDIR/layer-metadata/all.json" ] ; then
+ cp "$OPT_DIR/$OPT_SUBDIR/layer-metadata/all.json" "$BUILD_DIR/config/wv.json/layer-metadata.json"
+fi
-# # Run mergeConfig.js on each directory in /config containing .json files
-# # This creates on palettes-custom.json and wv.json
-# configs=$(ls "$BUILD_DIR/config")
-# for config in $configs; do
-# case $config in
-# *.json)
-# bash -c "node $SCRIPTS_DIR/mergeConfig.js \
-# --inputDir '$BUILD_DIR/config/$config' \
-# --outputFile '$DEST_DIR/config/$config'"
-# ;;
-# *)
-# cp -r "$BUILD_DIR/config/$config" "$DEST_DIR/config/$config"
-# ;;
-# esac
-# done
-
-# # # 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" \
-# --outputFile "$DEST_DIR/config/wv.json"`
-
-# # Copy brand files from build to dest
+# Run mergeConfig.js on each directory in /config containing .json files
+# This creates on palettes-custom.json and wv.json
+configs=$(ls "$BUILD_DIR/config")
+for config in $configs; do
+ case $config in
+ *.json)
+ bash -c "node $SCRIPTS_DIR/mergeConfig.js \
+ --inputDir '$BUILD_DIR/config/$config' \
+ --outputFile '$DEST_DIR/config/$config'"
+ ;;
+ *)
+ cp -r "$BUILD_DIR/config/$config" "$DEST_DIR/config/$config"
+ ;;
+ esac
+done
+
+# # 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" \
+ --outputFile "$DEST_DIR/config/wv.json"`
+
+# Copy brand files from build to dest
# cp -r "$BUILD_DIR/brand" "$DEST_DIR"
# cp "$BUILD_DIR/brand.json" "$DEST_DIR"