Skip to content

Commit

Permalink
create COG layer on the fly if none is provided (geosolutions-it#9527)
Browse files Browse the repository at this point in the history
  • Loading branch information
landryb committed Mar 25, 2024
1 parent 1efac53 commit 0260ac7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion web/client/api/catalog/COG.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const searchAndPaginate = (layers, startPosition, maxRecords, text) => {
let capabilitiesCache = {};
export const getRecords = (_url, startPosition, maxRecords, text, info = {}) => {
const service = get(info, 'options.service');
const controller = get(info, 'options.controller');
let layers = [];
if (service.records) {
// each record/url corresponds to a layer
Expand All @@ -46,7 +47,6 @@ export const getRecords = (_url, startPosition, maxRecords, text, info = {}) =>
sources: record.sources ?? [{url}],
options: record.options ?? (service.options || {})
};
const controller = get(info, 'options.controller');
const isSave = get(info, 'options.save', false);
const cached = capabilitiesCache[url];
if (cached && new Date().getTime() < cached.timestamp + (ConfigUtils.getConfigProp('cacheExpire') || 60) * 1000) {
Expand All @@ -68,6 +68,25 @@ export const getRecords = (_url, startPosition, maxRecords, text, info = {}) =>
});
}
return Promise.all([...layers]).then((_layers) => {
if (!_layers.length) {
let layer = {
...service,
title: text,
identifier: _url,
type: COG_LAYER_TYPE,
sources: [{url: _url}],
options: service.options || {}
};
return LayerUtils.getLayerConfig({_url, layer, controller})
.then(lyr => {
const records = [lyr];
return {
numberOfRecordsMatched: 1,
numberOfRecordsReturned: 1,
records
};
});
}
return searchAndPaginate(_layers, startPosition, maxRecords, text);
});
};
Expand Down

0 comments on commit 0260ac7

Please sign in to comment.