Skip to content

Commit

Permalink
look for image service on annotation bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Aug 11, 2018
1 parent 86a7a99 commit de96b28
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 40 deletions.
1 change: 1 addition & 0 deletions dist/@iiif/manifold.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ declare namespace Manifold {
tokenService: Manifesto.IService | null;
width: number;
constructor(canvas: Manifesto.ICanvas, options: Manifesto.IExternalResourceOptions);
private _getImageServiceDescriptor(services);
private _getDataUri(canvas);
private _parseAuthServices(resource);
private _parseDimensions(canvas);
Expand Down
39 changes: 28 additions & 11 deletions dist/@iiif/manifold.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,34 +241,51 @@ var Manifold;
// get the height and width of the image resource if available
this._parseDimensions(canvas);
}
ExternalResource.prototype._getImageServiceDescriptor = function (services) {
var infoUri = null;
for (var i = 0; i < services.length; i++) {
var service = services[i];
var id = service.id;
if (!id.endsWith('/')) {
id += '/';
}
if (manifesto.Utils.isImageProfile(service.getProfile())) {
infoUri = id + 'info.json';
}
}
return infoUri;
};
ExternalResource.prototype._getDataUri = function (canvas) {
var content = canvas.getContent();
var images = canvas.getImages();
var infoUri = null;
// presentation 3
if (content && content.length) {
var annotation = content[0];
var annotationBody = annotation.getBody();
if (annotationBody.length) {
var body = annotationBody[0];
var services = body.getServices();
if (services.length) {
infoUri = this._getImageServiceDescriptor(services);
if (infoUri) {
return infoUri;
}
}
// no image services. return the image id
return annotationBody[0].id;
}
return null;
}
else if (images && images.length) {
var infoUri = null;
var firstImage = images[0];
var resource = firstImage.getResource();
var services = resource.getServices();
if (services.length) {
for (var i = 0; i < services.length; i++) {
var service = services[i];
var id = service.id;
if (!id.endsWith('/')) {
id += '/';
}
if (manifesto.Utils.isImageProfile(service.getProfile())) {
infoUri = id + 'info.json';
}
infoUri = this._getImageServiceDescriptor(services);
if (infoUri) {
return infoUri;
}
return infoUri;
}
// no image services. return the image id
return resource.id;
Expand Down
1 change: 1 addition & 0 deletions dist/manifold.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ declare namespace Manifold {
tokenService: Manifesto.IService | null;
width: number;
constructor(canvas: Manifesto.ICanvas, options: Manifesto.IExternalResourceOptions);
private _getImageServiceDescriptor(services);
private _getDataUri(canvas);
private _parseAuthServices(resource);
private _parseDimensions(canvas);
Expand Down
39 changes: 28 additions & 11 deletions dist/manifold.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,34 +242,51 @@ var Manifold;
// get the height and width of the image resource if available
this._parseDimensions(canvas);
}
ExternalResource.prototype._getImageServiceDescriptor = function (services) {
var infoUri = null;
for (var i = 0; i < services.length; i++) {
var service = services[i];
var id = service.id;
if (!id.endsWith('/')) {
id += '/';
}
if (manifesto.Utils.isImageProfile(service.getProfile())) {
infoUri = id + 'info.json';
}
}
return infoUri;
};
ExternalResource.prototype._getDataUri = function (canvas) {
var content = canvas.getContent();
var images = canvas.getImages();
var infoUri = null;
// presentation 3
if (content && content.length) {
var annotation = content[0];
var annotationBody = annotation.getBody();
if (annotationBody.length) {
var body = annotationBody[0];
var services = body.getServices();
if (services.length) {
infoUri = this._getImageServiceDescriptor(services);
if (infoUri) {
return infoUri;
}
}
// no image services. return the image id
return annotationBody[0].id;
}
return null;
}
else if (images && images.length) {
var infoUri = null;
var firstImage = images[0];
var resource = firstImage.getResource();
var services = resource.getServices();
if (services.length) {
for (var i = 0; i < services.length; i++) {
var service = services[i];
var id = service.id;
if (!id.endsWith('/')) {
id += '/';
}
if (manifesto.Utils.isImageProfile(service.getProfile())) {
infoUri = id + 'info.json';
}
infoUri = this._getImageServiceDescriptor(services);
if (infoUri) {
return infoUri;
}
return infoUri;
}
// no image services. return the image id
return resource.id;
Expand Down
4 changes: 2 additions & 2 deletions dist/manifold.min.js

Large diffs are not rendered by default.

52 changes: 36 additions & 16 deletions src/ExternalResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,65 @@ namespace Manifold {
this._parseDimensions(canvas);
}

private _getImageServiceDescriptor(services: Manifesto.IService[]): string | null {
let infoUri: string | null = null;

for (let i = 0; i < services.length; i++) {
const service: Manifesto.IService = services[i];
let id: string = service.id;

if (!id.endsWith('/')) {
id += '/';
}

if (manifesto.Utils.isImageProfile(service.getProfile())) {
infoUri = id + 'info.json';
}
}

return infoUri;
}

private _getDataUri(canvas: Manifesto.ICanvas): string | null {

const content: Manifesto.IAnnotation[] = canvas.getContent();
const images: Manifesto.IAnnotation[] = canvas.getImages();
let infoUri: string | null = null;

// presentation 3
if (content && content.length) {

const annotation: Manifesto.IAnnotation = content[0];
const annotationBody: Manifesto.IAnnotationBody[] = annotation.getBody();

if (annotationBody.length) {
const body: Manifesto.IAnnotationBody = annotationBody[0];
const services: Manifesto.IService[] = body.getServices();

if (services.length) {
infoUri = this._getImageServiceDescriptor(services);
if (infoUri) {
return infoUri;
}
}

// no image services. return the image id
return annotationBody[0].id;
}

return null;

} else if (images && images.length) {

let infoUri: string | null = null;
} else if (images && images.length) { // presentation 2

const firstImage: Manifesto.IAnnotation = images[0];
const resource: Manifesto.IResource = firstImage.getResource();
const services: Manifesto.IService[] = resource.getServices();

if (services.length) {
for (let i = 0; i < services.length; i++) {
const service: Manifesto.IService = services[i];
let id: string = service.id;

if (!id.endsWith('/')) {
id += '/';
}

if (manifesto.Utils.isImageProfile(service.getProfile())) {
infoUri = id + 'info.json';
}
infoUri = this._getImageServiceDescriptor(services);
if (infoUri) {
return infoUri;
}

return infoUri;
}

// no image services. return the image id
Expand Down

0 comments on commit de96b28

Please sign in to comment.