From d332b6a0f4ad664b670f14987eaa2011dc157ec1 Mon Sep 17 00:00:00 2001 From: Lutz Helm Date: Tue, 16 Apr 2019 08:48:17 +0200 Subject: [PATCH] Prepare IIIFInfo for JSON-LD context extensions IIIF Image API 3 allows context extensions that should be added to the info.json's @context property. Therefore, '@context' might be an array instead of a string. --- src/ol/format/IIIFInfo.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/ol/format/IIIFInfo.js b/src/ol/format/IIIFInfo.js index cfd15909e9..89a21ccd5f 100644 --- a/src/ol/format/IIIFInfo.js +++ b/src/ol/format/IIIFInfo.js @@ -242,22 +242,27 @@ class IIIFInfo { if (this.imageInfo === undefined) { return; } - const context = this.imageInfo['@context'] || undefined; - switch (context) { - case 'http://library.stanford.edu/iiif/image-api/1.1/context.json': - case 'http://iiif.io/api/image/1/context.json': - return Versions.VERSION1; - case 'http://iiif.io/api/image/2/context.json': - return Versions.VERSION2; - case 'http://iiif.io/api/image/3/context.json': - return Versions.VERSION3; - case undefined: - // Image API 1.0 has no '@context' - if (this.getComplianceLevelEntryFromProfile(Versions.VERSION1) && this.imageInfo.identifier) { + let context = this.imageInfo['@context'] || 'ol-no-context'; + if (typeof context == 'string') { + context = [context]; + } + for (let i = 0; i < context.length; i++) { + switch (context[i]) { + case 'http://library.stanford.edu/iiif/image-api/1.1/context.json': + case 'http://iiif.io/api/image/1/context.json': return Versions.VERSION1; - } - break; - default: + case 'http://iiif.io/api/image/2/context.json': + return Versions.VERSION2; + case 'http://iiif.io/api/image/3/context.json': + return Versions.VERSION3; + case 'ol-no-context': + // Image API 1.0 has no '@context' + if (this.getComplianceLevelEntryFromProfile(Versions.VERSION1) && this.imageInfo.identifier) { + return Versions.VERSION1; + } + break; + default: + } } assert(false, 61); }