Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

python to node conversion wip

zachtricec1708f493af4
diff --git a/tasks/build/extractConfigFromWMTS.js b/tasks/build/extractConfigFromWMTS.js
index 0eb003fb5..a00e4367b 100644
--- a/tasks/build/extractConfigFromWMTS.js
+++ b/tasks/build/extractConfigFromWMTS.js
@@ -76,7 +76,7 @@ async function main () {
`)
if (totalErrorCount > 0) {
- throw new Error(`${prog}: Error: ${totalErrorCount.length} errors occured`)
+ throw new Error(`${prog}: Error: ${totalErrorCount} errors occured`)
}
}
diff --git a/tasks/build/fetchPreviewSnapshots.js b/tasks/build/fetchPreviewSnapshots.js
new file mode 100644
index 000000000..ae1291534
--- /dev/null
+++ b/tasks/build/fetchPreviewSnapshots.js
@@ -0,0 +1,280 @@
+const yargs = require('yargs')
+const axios = require('axios')
+const { promisify } = require('util')
+const fs = require('fs')
+const readFileAsync = promisify(fs.readFile)
+
+const prog = require('path').basename(__filename)
+
+const options = yargs
+ .usage('Usage: $0 <wv.json> <overrides_file>')
+ .option('wvJsonFile', {
+ demandOption: true,
+ alias: 'w',
+ type: 'string',
+ description: 'wv.json file'
+ })
+ .option('overridesFile', {
+ demandOption: true,
+ alias: 'o',
+ type: 'string',
+ description: 'overrides file'
+ })
+ .option('featuresFile', {
+ demandOption: true,
+ alias: 'f',
+ type: 'string',
+ description: 'features file'
+ })
+ .epilog('Fetch preview images from WV Snapshots for any layers which they are missing.')
+
+const { argv } = options
+if (!argv.wvJsonFile && !argv.overridesFile && !argv.featuresFile) {
+ throw new Error('Invalid number of arguments')
+}
+
+const wvJsonFile = argv.wvJsonFile
+const overridesFile = argv.overridesFile
+const featuresFile = argv.featuresFile
+
+const badSnapshots = []
+let overrideDatesDict = {}
+let totalSuccessCount = 0
+let totalFailureCount = 0
+// const timeFormat = '%Y-%m-%dT%H:%M:%SZ'
+let snapshotsUrl = ''
+const paramDict = {
+ base: {
+ REQUEST: 'GetSnapshot',
+ FORMAT: 'image/jpeg'
+ },
+ geographic: {
+ BBOX: '-90,-180,90,180',
+ CRS: 'EPSG:4326',
+ WIDTH: '768',
+ HEIGHT: '384'
+ },
+ arctic: {
+ BBOX: '-4195000,-4195000,4195000,4195000',
+ CRS: 'EPSG:3413',
+ WIDTH: '512',
+ HEIGHT: '512'
+ },
+ antarctic: {
+ BBOX: '-4195000,-4195000,4195000,4195000',
+ CRS: 'EPSG:3031',
+ WIDTH: '512',
+ HEIGHT: '512'
+ }
+}
+
+// These layers should not be combined with the reference layer
+const standaloneLayers = [
+ 'Graticule_15m',
+ 'Coastlines_15m',
+ 'Reference_Features_15m',
+ 'Reference_Labels_15m'
+]
+
+const destImgDir = './web/images/layers/previews/'
+
+const referenceLayers = {
+ geographic: 'OSM_Land_Water_Map',
+ arctic: 'OSM_Land_Water_Map',
+ antarctic: 'SCAR_Land_Water_Map'
+}
+
+const current = new Date()
+
+async function main () {
+ // Check to see if this feature is enabled in features.json before continuing
+ const featuresFileContent = await readFileAsync(featuresFile, { encoding: 'utf-8' })
+ const featuresDict = JSON.parse(featuresFileContent)
+ if (featuresDict.features.previewSnapshots === false) {
+ throw new Error('previewSnapshots note enabled in features.json')
+ }
+
+ // Allow manual configuration of layer ID to specific date to generate desired preview
+ const overridesFileContent = await readFileAsync(overridesFile, { encoding: 'utf-8' })
+ overrideDatesDict = JSON.parse(overridesFileContent)
+
+ const wvJsonFileContent = await readFileAsync(wvJsonFile, { encoding: 'utf-8' })
+ const wvJsonDict = JSON.parse(wvJsonFileContent)
+ const layers = wvJsonDict.layers
+ snapshotsUrl = wvJsonDict.features.imageDownload.url
+ const fetchSnapshots = featuresDict.features.previewSnapshots
+ if (!fetchSnapshots) {
+ throw new Error(`${prog}: Layer preview fetching disabled. Exiting.`)
+ }
+
+ const promises = []
+ for (const layer of Object.values(layers)) {
+ promises.push(getSnapshots(layer))
+ }
+
+ try {
+ await Promise.all(promises)
+ } catch (error) {
+ console.error(`${error}`)
+ }
+
+ if (badSnapshots.length > 0) {
+ console.warn(`\n${prog}: WARNING: ${badSnapshots.length} snapshots returned no content. See below for details: `)
+ for (const badLayer of badSnapshots) {
+ console.warn(`\n\t Layer: ${badLayer.id}`)
+ console.warn(`\t URL: ${badLayer.url}`)
+ }
+ }
+
+ if (totalSuccessCount > 0) {
+ console.warn(`\n${prog}: Successfully retrieved ${totalSuccessCount} snapshots!`)
+ }
+ if (totalFailureCount > 0) {
+ console.warn(`\n${prog}: WARNING: Failed to retrieve ${totalFailureCount} snapshots!`)
+ }
+ if (totalFailureCount === 0 && totalSuccessCount === 0) {
+ console.warn(`\n${prog}: No snapshots were retrieved. All layers found in wv.json have existing preview images!`)
+ }
+}
+
+function trackBadSnapshots (layerId, projection, request, imgPath) {
+ const arcticBadSize = 9949
+ const antarcticBadSize = 4060
+ const geographicBadSize = 12088
+
+ fs.stat(imgPath, (error, stats) => {
+ if (error) {
+ console.error(error)
+ return
+ }
+
+ const size = stats.size
+ if ([arcticBadSize, antarcticBadSize, geographicBadSize].includes(size)) {
+ badSnapshots.push({
+ id: layerId,
+ projection,
+ url: request.url
+ })
+ }
+ })
+}
+
+function getBestDate (projection, period, dateRanges) {
+ const lastRange = dateRanges[dateRanges.length - 1]
+ const startDate = lastRange.startDate
+ const endDate = lastRange.endDate
+ const parsedStartDate = new Date(startDate)
+ const parsedEndDate = new Date(endDate)
+ const pYear = parsedEndDate.getFullYear()
+ const pMonth = parsedEndDate.getMonth() + 1 // months are 0-indexed in JavaScript
+ let interval = parseInt(lastRange.dateInterval, 10)
+ let alteredDate = null
+
+ // Handle daily layers
+ if (period === 'daily') {
+ // Go back a few more days for single day layers since something
+ // too recent may not be processed yet
+ if (interval === 1) {
+ interval = 3
+ }
+ alteredDate = new Date(parsedEndDate - interval * 24 * 60 * 60 * 1000)
+ }
+
+ // Choose a good daylight month for arctic
+ if (projection === 'arctic' && ![4, 5, 6, 7, 8, 9].includes(pMonth)) {
+ if (pYear === current.getFullYear() && current.getMonth() + 1 < 6) {
+ alteredDate = new Date(pYear - 1, 5, 1)
+ } else {
+ alteredDate = new Date(pYear, 5, 1)
+ }
+ }
+
+ // Choose a good daylight month for antarctic
+ if (projection === 'antarctic' && ![10, 11, 12, 1, 2].includes(pMonth)) {
+ // TODO handle "bad" months for antarctic
+ alteredDate = new Date(pYear, 11, 1)
+ }
+
+ // Make sure modified date isn't out of layer date range
+ if (alteredDate && alteredDate >= parsedStartDate) {
+ return alteredDate.toISOString().slice(0, -5) + 'Z'
+ }
+ return endDate
+}
+
+function getTimeParam (projection, layerId, layer, params) {
+ // Only include TIME param for temporal layers
+ const dateRanges = layer.dateRanges
+ const startDate = layer.startDate
+ const period = layer.period
+
+ if (dateRanges) {
+ params.TIME = getBestDate(projection, period, dateRanges)
+ } else if (startDate) {
+ params.TIME = startDate
+ }
+
+ // Use any configured override dates
+ if (overrideDatesDict[layerId]) {
+ params.TIME = overrideDatesDict[layerId]
+ }
+}
+
+async function getSnapshots (layer) {
+ for (const projection of Object.keys(layer.projections)) {
+ const projDict = layer.projections[projection]
+ const referenceLayer = referenceLayers[projection]
+
+ // Sometimes a layer id is provided per projection (e.g. Land Mask layers)
+ // We need to use this layer id to request the layer from WVS/GIBS
+ // But, we need to use the WV id as the file name (since that's how we will look up the image in WV)
+ let gibsLayerId, wvLayerId
+ if (projDict.layer) {
+ gibsLayerId = projDict.layer
+ wvLayerId = layer.id
+ } else {
+ gibsLayerId = wvLayerId = layer.id
+ }
+
+ const params = { ...paramDict.base, ...paramDict[projection] }
+ getTimeParam(projection, wvLayerId, layer, params)
+
+ if (gibsLayerId !== referenceLayer && !standaloneLayers.includes(gibsLayerId)) {
+ params.LAYERS = `${referenceLayer},${gibsLayerId}`
+ params.OPACITIES = '0.50,1'
+ } else {
+ params.LAYERS = gibsLayerId
+ }
+
+ const destFileName = path.join(destImgDir, projection, `${wvLayerId}.jpg`)
+
+ // Only get images that we don't have already
+ const fileExists = await fs.promises.stat(destFileName)
+ .then(() => true)
+ .catch(() => false)
+ if (fileExists) continue
+
+ try {
+ const imageReq = await axios.get(snapshotsUrl, { params })
+ let statusText = 'ERROR'
+ if (imageReq.status === 200) {
+ statusText = 'SUCCESS'
+ totalSuccessCount += 1
+ await fs.promises.writeFile(destFileName, imageReq.data, { flag: 'wx' })
+ if (gibsLayerId === referenceLayers[projection]) continue
+ trackBadSnapshots(wvLayerId, projection, imageReq, imageReq.data)
+ } else {
+ totalFailureCount += 1
+ }
+ console.warn(`\n${prog}: Result: ${statusText} - ${imageReq.status}`)
+ console.warn(`${prog}: Layer: ${wvLayerId}`)
+ console.warn(`${prog}: URL: ${imageReq.config.url}`)
+ } catch (e) {
+ console.error(`${prog} ERROR: ${e}`)
+ }
+ }
+}
+
+main().catch((err) => {
+ console.error(err.stack)
+})
diff --git a/tasks/build/mergeConfig.js b/tasks/build/mergeConfig.js
new file mode 100644
index 000000000..b8ebe4048
--- /dev/null
+++ b/tasks/build/mergeConfig.js
@@ -0,0 +1,58 @@
+const { dictMerge } = require('./util')
+const fs = require('fs')
+const path = require('path')
+const yargs = require('yargs')
+const prog = path.basename(__filename)
+
+const options = yargs
+ .usage('Usage: $0 [inputDir] [outputDir]')
+ .option('inputDir', {
+ demandOption: true,
+ alias: 'i',
+ type: 'string',
+ description: 'getcapabilities input directory'
+ })
+ .option('outputFile', {
+ demandOption: true,
+ alias: 'o',
+ type: 'string',
+ description: 'wmts output directory'
+ })
+ .epilog('Concatenates all configuration items a directory into one configuration file.')
+
+const { argv } = options
+if (!argv.inputDir && !argv.outputFile) {
+ throw new Error('Invalid number of arguments')
+}
+
+const inputDir = argv.inputDir
+const outputFile = argv.outputFile
+
+const conf = {}
+let fileCount = 0
+
+async function main () {
+ fs.readdirSync(inputDir).forEach(file => {
+ try {
+ if (!file.endsWith('.json')) return
+ fileCount += 1
+ const data = JSON.parse(fs.readFileSync(path.join(inputDir, file), 'utf-8'))
+ dictMerge(conf, data)
+ } catch (error) {
+ throw new Error(`ERROR: ${path.join(inputDir, file)}: ${error.message}`)
+ }
+ })
+
+ const jsonOptions = {
+ indent: 2,
+ separators: [',', ': ']
+ }
+
+ fs.writeFileSync(outputFile, JSON.stringify(conf, null, jsonOptions.indent), 'utf-8')
+
+ console.log(`${prog}: ${fileCount} file(s) merged into ${path.basename(outputFile)}`)
+}
+
+main().catch((err) => {
+ console.error(err.stack)
+})
diff --git a/tasks/build/mergeConfigWithWMTS.js b/tasks/build/mergeConfigWithWMTS.js
index e69de29bb..4bb5f8fd5 100644
--- a/tasks/build/mergeConfigWithWMTS.js
+++ b/tasks/build/mergeConfigWithWMTS.js
@@ -0,0 +1,96 @@
+const fs = require('fs')
+const path = require('path')
+const yargs = require('yargs')
+const { dictMerge } = require('./util')
+const prog = path.basename(__filename)
+
+const options = yargs
+ .usage('Usage: $0 [inputDir] [outputDir]')
+ .option('inputDir', {
+ demandOption: true,
+ alias: 'i',
+ type: 'string',
+ description: 'getcapabilities input directory'
+ })
+ .option('outputFile', {
+ demandOption: true,
+ alias: 'o',
+ type: 'string',
+ description: 'wmts output directory'
+ })
+ .epilog('Concatenates all configuration items a directory into one configuration file.')
+
+const { argv } = options
+if (!argv.inputDir && !argv.outputFile) {
+ throw new Error('Invalid number of arguments')
+}
+
+const inputDir = argv.inputDir
+const outputFile = argv.outputFile
+
+let newConf = {}
+newConf.layers = {}
+newConf.sources = {}
+
+const outputData = JSON.parse(fs.readFileSync(outputFile, 'utf-8'))
+let fileCount = 0
+
+async function main () {
+ fs.readdirSync(inputDir).forEach(file => {
+ try {
+ if (!file.endsWith('.json')) return
+ fileCount += 1
+ const data = JSON.parse(fs.readFileSync(path.join(inputDir, file), 'utf-8'))
+ newConf.layers = wmtsDictMerge(newConf.layers, data, outputData)
+ newConf.sources = dictMerge(newConf.sources, data.sources, outputData.sources)
+ } catch (e) {
+ throw new Error(`ERROR: ${path.join(inputDir, file)}: ${e.message}`)
+ }
+ })
+
+ newConf = dictMerge(newConf, outputData)
+
+ const jsonOptions = {}
+ jsonOptions.indent = 2
+ jsonOptions.separators = [',', ': ']
+
+ fs.writeFileSync(outputFile, JSON.stringify(newConf, jsonOptions))
+
+ console.log(`${prog}: ${fileCount} file(s) merged into ${path.basename(outputFile)}`)
+}
+
+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
+
+ for (const [k, v] of Object.entries(obj.layers)) {
+ if (Object.prototype.hasOwnProperty.call(conf.layer, k) && typeof conf.layers[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
+ 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 (source !== confProjections[projectionKey].source) {
+ foundSourceMisMatch = true
+ continue
+ }
+ }
+ }
+ }
+ }
+ if (foundSourceMisMatch) continue
+ if (Object.prototype.hasOwnProperty.call(target, k) && typeof target[k] === 'object') {
+ dictMerge(target[k], v, conf.layers[k])
+ } else {
+ target[k] = dictMerge(v, conf.layers[k])
+ }
+ }
+ }
+ return target
+}
+
+main().catch((err) => {
+ console.error(err.stack)
+})
diff --git a/tasks/build/processColormap.js b/tasks/build/processColormap.js
index 91bf86bab..fef5d3bbd 100644
--- a/tasks/build/processColormap.js
+++ b/tasks/build/processColormap.js
@@ -242,7 +242,7 @@ async function main () {
console.log(`${prog}: ${errorCount} error(s), ${fileCount} file(s)`)
if (errorCount > 0) {
- throw new Error(`${prog}: Error: ${errorCount.length} errors occured`)
+ throw new Error(`${prog}: Error: ${errorCount} errors occured`)
}
}
diff --git a/tasks/build/processVectorData.js b/tasks/build/processVectorData.js
index 22fd6b085..e977cc46a 100644
--- a/tasks/build/processVectorData.js
+++ b/tasks/build/processVectorData.js
@@ -52,7 +52,7 @@ async function main () {
console.error(`${prog}: ${errorCount} error(s), ${fileCount} file(s)`)
if (errorCount > 0) {
- throw new Error(`${prog}: Error: ${errorCount.length} errors occured`)
+ throw new Error(`${prog}: Error: ${errorCount} errors occured`)
}
}
diff --git a/tasks/build/processVectorStyles.js b/tasks/build/processVectorStyles.js
index fa5f01327..53e26895e 100644
--- a/tasks/build/processVectorStyles.js
+++ b/tasks/build/processVectorStyles.js
@@ -52,7 +52,7 @@ async function main () {
console.error(`${prog}: ${errorCount} error(s), ${fileCount} file(s)`)
if (errorCount > 0) {
- throw new Error(`${prog}: Error: ${errorCount.length} errors occured`)
+ throw new Error(`${prog}: Error: ${errorCount} errors occured`)
}
}
diff --git a/tasks/build/util.js b/tasks/build/util.js
new file mode 100644
index 000000000..f5d4b1b2c
--- /dev/null
+++ b/tasks/build/util.js
@@ -0,0 +1,21 @@
+function dictMerge (target, ...objs) {
+ objs.forEach(obj => {
+ if (!_.isPlainObject(obj)) return obj
+
+ _.forOwn(obj, (v, k) => {
+ if (_.has(target, k) && _.isPlainObject(target[k])) {
+ if (_.has(v, 'type') && _.has(target[k], 'type')) {
+ if (v.type !== target[k].type) return target
+ }
+ Object.assign(target[k], v)
+ } else {
+ target[k] = _.cloneDeep(v)
+ }
+ })
+ })
+ return target
+}
+
+module.exports = {
+ dictMerge
+}
diff --git a/tasks/build/validateOptions.js b/tasks/build/validateOptions.js
index e69de29bb..ef9270eb3 100644
--- a/tasks/build/validateOptions.js
+++ b/tasks/build/validateOptions.js
@@ -0,0 +1,224 @@
+const fs = require('fs')
+const path = require('path')
+const yargs = require('yargs')
+const prog = path.basename(__filename)
+
+const options = yargs
+ .usage('Usage: $0 [optionsFile] [configDir]')
+ .option('optionsFile', {
+ demandOption: true,
+ alias: 'o',
+ type: 'string',
+ description: 'options file'
+ })
+ .option('configDir', {
+ demandOption: true,
+ alias: 'c',
+ type: 'string',
+ description: 'config directory'
+ })
+ .epilog('Validates and corrects the configuration files.')
+
+const { argv } = options
+if (!argv.optionsFile && !argv.configDir) {
+ throw new Error('Invalid number of arguments')
+}
+
+const optionsFile = argv.optionsFile
+const configDir = argv.configDir
+
+let errorCount = 0
+let warningCount = 0
+const removedLayers = []
+
+const mainConfigFile = path.join(configDir, 'wv.json')
+const wv = JSON.parse(fs.readFileSync(mainConfigFile, 'utf8'))
+const opt = JSON.parse(fs.readFileSync(optionsFile, 'utf8'))
+
+const tolerant = opt.tolerant || false
+
+function fail (message) {
+ console.error(`${prog}: ERROR: ${message}`)
+ errorCount += 1
+}
+
+function error (message) {
+ tolerant ? warn(message) : fail(message)
+}
+
+function warn (message) {
+ console.error(`${prog}: WARN: ${message}`)
+ warningCount += 1
+}
+
+function removeLayer (wv, layerId) {
+ removedLayers.push(layerId)
+ delete wv.layers[layerId]
+ if (wv.layerOrder.includes(layerId)) wv.layerOrder.splice(wv.layerOrder.indexOf(layerId), 1)
+}
+
+function isDateTimeFormat (input) {
+ try {
+ Date.parse(input)
+ return true
+ } catch (e) {
+ return false
+ }
+}
+
+if (tolerant) console.warn('Validation enforcement disabled')
+
+let startDate = new Date(Number.MAX_SAFE_INTEGER)
+
+async function main () {
+ for (const layerId of Object.keys(wv.layers)) {
+ let layer = wv.layers[layerId]
+
+ if (layerId !== layer.get('id')) {
+ error(`[${layerId}] layer id does not match id of ${layer.get('id')}`)
+ }
+ if (!wv.layerOrder.includes(layerId)) {
+ if (opt.get('layerOrderExceptions', []).includes(layerId)) {
+ removeLayer(wv, layerId)
+ continue
+ } else if (tolerant || opt.get('ignoreLayerOrder', false)) {
+ wv.layerOrder.push(layerId)
+ } else {
+ removeLayer(wv, layerId)
+ continue
+ }
+ }
+ if (!layer.projections || layer.projections.length === 0) {
+ error(`[${layerId}] No projections defined or not found in GC documents`)
+ removeLayer(wv, layerId)
+ continue
+ }
+ if (!Object.prototype.hasOwnProperty.call(layer, 'type')) {
+ error(
+ `[${layerId}] No type defined. Possible to be expecting configuration via GC document but was not found`
+ )
+ removeLayer(wv, layerId)
+ continue
+ }
+ if (Object.prototype.hasOwnProperty.call(layer, 'palette') && !Object.prototype.hasOwnProperty.call(layer.palette, 'id')) {
+ error(`[${layerId}] No palette definition`)
+ } else if (Object.prototype.hasOwnProperty.call(layer, 'palette')) {
+ const paletteId = layer.palette.id
+ if (!fs.existsSync(path.join(configDir, 'palettes', `${paletteId}.json`))) {
+ error(`[${layerId}] Unknown palette: ${paletteId}`)
+ delete layer.palette
+ }
+ }
+ if (Object.prototype.hasOwnProperty.call(layer, 'vectorStyle') && !Object.prototype.hasOwnProperty.call(layer.vectorStyle, 'id')) {
+ error(`[${layerId}] No vectorStyle definition`)
+ }
+ if (!Object.prototype.hasOwnProperty.call(layer, 'group') && opt.get('warnOnUnexpectedLayer')) {
+ error(`[${layerId}] Possible unexpected layer, no group defined`)
+ removeLayer(wv, layerId)
+ continue
+ } else if (!Object.prototype.hasOwnProperty.call(layer, 'group')) {
+ removeLayer(wv, layerId)
+ continue
+ }
+ for (const projId of Object.keys(layer.projections)) {
+ const projection = layer.projections[projId]
+ if (Object.prototype.hasOwnProperty.call(projection, 'matrixSet')) {
+ const source = projection.source
+ const matrixSet = projection.matrixSet
+ if (!Object.prototype.hasOwnProperty.call(wv.sources, source)) {
+ error(`[${layerId}:${projId}] Invalid source: ${source}`)
+ delete layer.projections[projId]
+ } else if (!Object.prototype.hasOwnProperty.call(wv.sources[source], 'matrixSets')) {
+ error(`[${layerId}:${projId}] No matrix sets for projection`)
+ delete layer.projections[projId]
+ } else if (!wv.sources[source].matrixSets.includes(matrixSet)) {
+ error(`[${layerId}:${projId}] Invalid matrix set: ${matrixSet}`)
+ delete layer.projections[projId]
+ }
+ }
+ }
+ if (Object.prototype.hasOwnProperty.call(layer, 'temporal')) {
+ console.warn(`[${layerId}] GC Layer temporal values overwritten by Options`)
+ layer = processTemporal(layer, layer.temporal)
+ }
+ if (layer.get('futureTime')) {
+ if (Object.prototype.hasOwnProperty.call(layer, 'endDate')) {
+ delete layer.endDate
+ }
+ }
+ if (layer.get('futureTime', false)) {
+ // do nothing
+ } else {
+ if (Object.prototype.hasOwnProperty.call(layer, 'endDate') && layer.get('ongoing', true)) {
+ delete layer.endDate
+ }
+ }
+ if (Object.prototype.hasOwnProperty.call(layer, 'startDate')) {
+ const startTime = layer.startDate.replace('T', ' ').replace('Z', '')
+ let d
+ if (isDateTimeFormat(startTime)) {
+ d = new Date(startTime)
+ } else {
+ d = new Date(layer.startDate)
+ }
+ startDate = Math.min(startDate, d)
+ }
+ }
+
+ if (startDate.getTime() !== Number.MAX_VALUE) {
+ wv.startDate = startDate.toISOString()
+ }
+
+ for (const layerId of wv.layerOrder) {
+ if (!Object.prototype.hasOwnProperty.call(wv.layers, layerId)) {
+ error(`[${layerId}] In layer order but no definition`)
+ }
+ }
+
+ const startingLayers = []
+ for (const startingLayer of wv.defaults.startingLayers) {
+ if (!Object.prototype.hasOwnProperty.call(wv.layers, startingLayer.id)) {
+ error(`Invalid starting layer: ${startingLayer.id}`)
+ } else {
+ startingLayers.push(startingLayer)
+ }
+ }
+ wv.defaults.startingLayers = startingLayers
+ wv.buildDate = Date.now()
+
+ for (const projection of Object.keys(wv.naturalEvents.layers)) {
+ for (const eventType of Object.keys(wv.naturalEvents.layers[projection])) {
+ for (const layerObject of wv.naturalEvents.layers[projection][eventType]) {
+ if (!Object.prototype.hasOwnProperty.call(wv.layers, layerObject[0])) {
+ error(
+ `The ${layerObject[0]} layer in the Natural events ${projection} ${eventType} config does not have a matching ID in the layer config`
+ )
+ }
+ }
+ }
+ }
+
+ for (const measurement of Object.values(wv.measurements)) {
+ if (!Object.prototype.hasOwnProperty.call(measurement, 'sources')) continue
+ for (const source of Object.values(measurement.sources)) {
+ if (!Object.prototype.hasOwnProperty.call(source, 'settings')) continue
+ for (const setting of source.settings) {
+ if (!Object.prototype.hasOwnProperty.call(wv.layers, setting)) {
+ error(
+ `In measurement ${measurement.id}, source ${source.id}, layer not found: ${setting}`
+ )
+ }
+ }
+ }
+ }
+
+ console.log(`${prog}: ${errorCount} error(s), ${warningCount} warning(s), ${removeCount} removed`)
+
+ if (errorCount > 0) {
+ throw new Error(`${prog}: Error: ${errorCount} errors occured`)
+ }
+}
+
+main().catch((err) => {
+ console.error(err.stack)
+})