Skip to content

Commit

Permalink
Check if an image resource is a preferred Choice option; change displ…
Browse files Browse the repository at this point in the history
…ay order
  • Loading branch information
lutzhelm committed Dec 5, 2024
1 parent cac3ae2 commit ea0fc77
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
3 changes: 3 additions & 0 deletions __tests__/integration/mirador/layers.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
{ manifestId: "https://prtd.app/aom/manifest.json" },
{ manifestId: "https://prtd.app/fv/manifest.json" },
{ manifestId: "https://manifests.britishart.yale.edu/Osbornfa1" },
{ manifestId: "https://dvp.prtd.app/hamilton/manifest.json" },
{ manifestId: "https://iiif.io/api/cookbook/recipe/0036-composition-from-multiple-images/manifest.json" },
{ manifestId: "https://iiif.io/api/cookbook/recipe/0033-choice/manifest.json" },
]
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/components/CanvasLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Layer({

const layer = {
opacity: 1,
visibility: true,
visibility: !!resource.preferred,
...(layerMetadata || {}),
};

Expand Down
9 changes: 5 additions & 4 deletions src/lib/CanvasWorld.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export default class CanvasWorld {

/** @private */
getLayerMetadata(contentResource) {
if (!this.layers) return undefined;
const miradorCanvas = this.canvases.find(c => (
c.imageResources.find(r => r.id === contentResource.id)
));
Expand All @@ -156,15 +155,17 @@ export default class CanvasWorld {

const resourceIndex = miradorCanvas.imageResources
.findIndex(r => r.id === contentResource.id);
const resource = miradorCanvas.imageResources
.find(r => r.id === contentResource.id);

const layer = this.layers[miradorCanvas.canvas.id];
const imageResourceLayer = layer && layer[contentResource.id];
const layer = this.layers && this.layers[miradorCanvas.canvas.id];
const imageResourceLayer = (layer && layer[contentResource.id]) || {};

return {
index: resourceIndex,
opacity: 1,
total: miradorCanvas.imageResources.length,
visibility: true,
visibility: !!resource.preferred,
...imageResourceLayer,
};
}
Expand Down
37 changes: 30 additions & 7 deletions src/lib/MiradorCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,42 @@ export default class MiradorCanvas {

/** */
get imageResources() {
// FIXME this is in no way production ready; current changes are only for demo purposes
const resources = flattenDeep([
this.canvas.getImages().map(i => i.getResource()),
this.canvas.getContent().map(i => i.getBody()),
this.canvas.getContent().map(i => (i.__jsonld.body.type === 'Choice' ? i.__jsonld.body : i.getBody())),
]);

return flatten(resources.map((resource) => {
switch (resource.getProperty('type')) {
case 'oa:Choice':
return new Canvas({ images: flatten([resource.getProperty('default'), resource.getProperty('item')]).map(r => ({ resource: r })) }, this.canvas.options).getImages().map(i => i.getResource());
default:
return resource;
const type = resource.type || resource.getProperty('type');
switch (type) {
case 'Choice': {
return new Canvas({ images: resource.items.map(r => ({ resource: r })) }, this.canvas.options)
.getImages().map((img, index) => {
const r = img.getResource();
if (r) {
r.preferred = !index;
}
return r;
});
}
case 'oa:Choice': {
return new Canvas({ images: flattenDeep([resource.getProperty('default'), resource.getProperty('item')]).map(r => ({ resource: r })) }, this.canvas.options).getImages()
.map((img, index) => {
const r = img.getResource();
if (r) {
r.preferred = !index;
}
return r;
});
}
default: {
const r = resource;
r.preferred = true;
return r;
}
}
}));
})).reverse();
}

/** */
Expand Down

0 comments on commit ea0fc77

Please sign in to comment.