Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/essence/Ancillary/Description.js
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,34 @@ const Description = {
})
}
}

// check if this is actually a STAC feature
if (activeLayer.feature.stac_version) {
// extract links from feature assets
// https://github.com/radiantearth/stac-spec/blob/master/commons/assets.md#assets--
if (activeLayer.feature.assets) {
const assetKeys = Object.keys(
activeLayer.feature.assets
)
for (let i = 0; i < assetKeys.length; i++) {
const asset =
activeLayer.feature.assets[assetKeys[i]]
const link = asset?.href
const title = asset?.title
const roles = asset?.roles
if (
link !== null &&
link !== '' &&
(!roles || roles.indexOf('data') !== -1)
)
links.push({
name: `<span style='display: flex; justify-content: space-between;'>${title}<i class='mdi mdi-open-in-new mdi-14px' style='margin-left: 4px; margin-top: 1px;'></i></span>`,
link: link,
target: F_.cleanString(title),
})
}
}
}
}

let key = activeLayer.useKeyAsName || 'name'
Expand Down
162 changes: 154 additions & 8 deletions src/essence/Basics/Layers_/Layers_.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const L_ = {
_layersBeingMade: {},
_onLoadCallbacks: [],
_loaded: false,
init: function (configData, missionsList, urlOnLayers) {
parseConfig(configData, urlOnLayers)
init: async function (configData, missionsList, urlOnLayers) {
await parseConfig(configData, urlOnLayers)
L_.missionsList = missionsList
},
onceLoaded(cb) {
Expand Down Expand Up @@ -2998,7 +2998,7 @@ const L_ = {
},
parseConfig: parseConfig,

resetConfig: function (data) {
resetConfig: async function (data) {
// Save so we can make sure we reproduce the same layer settings after parsing the config
const toggledArray = { ...L_.layers.on }

Expand All @@ -3010,7 +3010,7 @@ const L_ = {
L_.layers.dataFlat = []
L_._layersLoaded = []

L_.parseConfig(data)
await L_.parseConfig(data)

// Set back
L_.layers.on = { ...L_.layers.on, ...toggledArray }
Expand Down Expand Up @@ -3141,7 +3141,7 @@ const L_ = {
// If we have a few changes waiting in the queue, we only need to parse the config once
// as the last item in the queue should have the latest data
const lastLayer = layerQueueList[layerQueueList.length - 1]
L_.resetConfig(lastLayer.data)
await L_.resetConfig(lastLayer.data)

while (layerQueueList.length > 0) {
const firstLayer = layerQueueList.shift()
Expand Down Expand Up @@ -3555,7 +3555,7 @@ const L_ = {

//Takes in a configData object and does a depth-first search through its
// layers and sets L_ variables
function parseConfig(configData, urlOnLayers) {
async function parseConfig(configData, urlOnLayers) {
//Create parsed configData
L_.configData = configData

Expand Down Expand Up @@ -3624,11 +3624,19 @@ function parseConfig(configData, urlOnLayers) {
const layers = L_.configData.layers

//Begin recursively going through those layers
expandLayers(layers, 0, null)
await expandLayers(layers, 0, null)

async function expandLayers(d, level, prevName) {
const stacRegex = /^stac(-((item)|(catalog)|(collection)))?:/i

function expandLayers(d, level, prevName) {
//Iterate over each layer
for (let i = 0; i < d.length; i++) {
// check if this is a vector STAC catalog or collection
// if so, prefetch the data and replace this entry
if (d[i].type === 'vector' && stacRegex.test(d[i].url)) {
d[i] = await getSTACLayers(d[i])
}

// Quick hack to use uuid instead of name as main id
d[i].uuid = d[i].uuid || d[i].name
if (L_.layers.nameToUUID[d[i].name] == null)
Expand Down Expand Up @@ -3808,6 +3816,144 @@ function parseConfig(configData, urlOnLayers) {
//Otherwise return 0
return 0
}

// recurse through a STAC layer building sublayers
function getSTACLayers(d) {
return new Promise(async (resolve, reject) => {
let stac_data
const stacRegex =
/^(?<prefix>stac(-((item)|(catalog)|(collection)))?:)?(?<url>.*)/i
const urlMatch = d.url.match(stacRegex)
if (!urlMatch) {
console.warn('Could not process STAC URL')
resolve(d)
}
const { prefix, url } = urlMatch.groups
d.url = url // replace the current URL so we no longer need to worry about the special prefix
if (prefix !== 'stac-item:') {
$.ajax({
url: L_.getUrl('stac', d.url, d),
success: async (resp) => {
stac_data = resp
const path = d.url.split('/').slice(0, -1).join('/')
const basename = F_.fileNameFromPath(d.url)
const stac_type = stac_data.type.toLowerCase()
if (stac_type === 'catalog') {
let sublayers = []
const children = stac_data.links.filter((l) =>
/^child/i.test(l.rel)
)
const promArr = []
for (let i = 0; i < children.length; i++) {
const uuid = `${d.uuid}-${i}`
promArr.push(
getSTACLayers(
Object.assign({}, d, {
url: children[i].href.replace(
'./',
`${path}/`
),
display_name:
children[i].title ||
F_.fileNameFromPath(
children[i].href
),
uuid: uuid,
name: uuid,
})
)
)
}

try {
const subls = await Promise.all(promArr)
sublayers = sublayers.concat(subls)
} catch (err) {
console.warn(err)
resolve(d)
}

resolve(
Object.assign(
{
type: 'header',
sublayers,
description: '',
display_name: '',
name: '',
uuid: '',
},
{
description: d.description,
display_name:
d.display_name || basename,
name: d.name,
uuid: d.uuid,
}
)
)
} else if (stac_type === 'collection') {
const sublayers = []
const items = stac_data.links.filter((l) =>
/^item/i.test(l.rel)
)
for (let i = 0; i < items.length; i++) {
const uuid = `${d.uuid}-${i}`
sublayers.push(
// we shouldn't need to pre-fetch item data
Object.assign({}, d, {
url: items[i].href.replace(
'./',
`${path}/`
),
display_name:
items[i].title ||
F_.fileNameFromPath(items[i].href),
uuid: uuid,
name: uuid,
})
)
}
resolve(
Object.assign(
{
type: 'header',
sublayers,
description: '',
display_name: '',
name: '',
uuid: '',
},
{
description: d.description,
display_name:
d.display_name || basename,
name: d.name,
uuid: d.uuid,
}
)
)
} else if (/^feature(collection)?$/i.test(stac_type)) {
resolve(
Object.assign({}, d, {
display_name: d.display_name || basename,
})
)
} else {
console.warn('Could not process STAC layer')
resolve(d)
}
},
error: (resp) => {
console.warn(resp)
resolve(d)
}
})
} else {
resolve(d)
}
})
}
}

window.L_ = L_
Expand Down
12 changes: 6 additions & 6 deletions src/essence/essence.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ var essence = {
UserInterface_.updateLayerUpdateButton('DISCONNECTED')
}
},
init: function (config, missionsList, swapping) {
init: async function (config, missionsList, swapping) {
//Save the config data
essence.configData = config

Expand Down Expand Up @@ -335,7 +335,7 @@ var essence = {
if (!swapping) urlOnLayers = QueryURL.queryURL()

//Parse all the configData
L_.init(essence.configData, missionsList, urlOnLayers)
await L_.init(essence.configData, missionsList, urlOnLayers)

if (swapping) {
ToolController_.clear()
Expand Down Expand Up @@ -440,8 +440,8 @@ var essence = {
'config.json' +
'?nocache=' +
new Date().getTime(),
function (data) {
essence.makeMission(data)
async function (data) {
await essence.makeMission(data)
}
).fail(function () {
console.log(
Expand All @@ -455,7 +455,7 @@ var essence = {
})
}
},
makeMission: function (data) {
makeMission: async function (data) {
//Remove swap tool from data.tools
for (var i = data.tools.length - 1; i > 0; i--) {
if (data.tools[i].name === 'Swap') {
Expand All @@ -479,7 +479,7 @@ var essence = {
}
}

essence.init(data, L_.missionsList, true)
await essence.init(data, L_.missionsList, true)
},
fina: function () {
if (!essence.finalized) {
Expand Down
Loading