Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check layer format in layer decorator #1895

Merged
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
8 changes: 7 additions & 1 deletion lib/layer/decorate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ The layer decorator method create mapp-layer typedef object from a json-layer.
@returns {layer} Decorated Mapp Layer.
*/
export default async function decorate(layer) {
// Check layer format.
if (!Object.hasOwn(mapp.layer.formats, layer.format)) {
console.warn(`Layer: ${layer.key}; ${layer.format} format unavailable.`);
return;
}

// Decorate layer format methods.
await mapp.layer.formats[layer.format]?.(layer);
await mapp.layer.formats[layer.format](layer);

// If layer does not exist, return.
if (!layer.L) return;
Expand Down
6 changes: 0 additions & 6 deletions lib/mapview/addLayer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ export default async function addLayer(layers) {
// Assign default key if not explicit in layer JSON.
layer.key ??= `${layer.format}-${i}`;

// Check the layer format.
if (!mapp.layer.formats[layer.format]) {
console.error(`Layer: ${layer.key}; Format: ${layer.format} is unknown.`);
continue;
}

await mapp.layer.decorate(layer);

if (!layer.L) continue;
Expand Down
8 changes: 7 additions & 1 deletion lib/ui/locations/entries/layer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function layer(entry) {

entry.zIndex ??= entry.location.layer.zIndex++;

entry.show ?? decorateLayer(entry);
decorateLayer(entry);

entry.panel ??= mapp.utils.html.node`<div class="entry-layer">`;

Expand Down Expand Up @@ -123,8 +123,14 @@ The infoj layer entry provided as argument will be decorated to become a mapp la
@param {infoj-entry} entry type:layer entry.
*/
async function decorateLayer(entry) {
// The entry [layer] has already been decorated.
if (entry.L) return;

await mapp.layer.decorate(entry);

// The entry [layer] could not be decorated.
if (!entry.L) return;

entry.key += `-${ol.util.getUid(entry.L)}`;

entry.L.set('key', entry.key);
Expand Down