Skip to content

Commit

Permalink
Merge pull request #59 from mejackreed/add-profile-object-support
Browse files Browse the repository at this point in the history
Add profile object support
  • Loading branch information
mejackreed authored Feb 6, 2017
2 parents 0013875 + 6a1e7cd commit 05a4c65
Show file tree
Hide file tree
Showing 5 changed files with 1,854 additions and 6 deletions.
7 changes: 5 additions & 2 deletions examples/iiif-example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var map, stanfordMlk, apostle, princetonMap, bnf, iiifLayers;
var map, stanfordMlk, apostle, princetonMap, bnf, iiifLayers, scottlandBagpipe;

map = L.map('map', {
center: [0, 0],
Expand Down Expand Up @@ -29,6 +29,8 @@ acrobata = L.tileLayer.iiif('http://libimages.princeton.edu/loris2/pudl0033/2007
quality: 'gray'
});

scottlandBagpipe = L.tileLayer.iiif('http://images.is.ed.ac.uk/luna/servlet/iiif/UoEwmm~2~2~77099~164515/info.json');

staticTiles = L.tileLayer.iiif('http://evil-manifests.davidnewbury.com/iiif/images/garden-1/info.json');

iiifLayers = {
Expand All @@ -37,7 +39,8 @@ iiifLayers = {
'Apostle: Anonymous sculptor of Fl...': apostle,
'ManuscritKalîla et Dimna, avec de...': bnf,
'Acrobata Marroquí': acrobata,
'A static tile source': staticTiles
'A static tile source': staticTiles,
'A Compleat Theory of the Scots Highland Bagpipe': scottlandBagpipe
};

L.control.layers(iiifLayers).addTo(map);
19 changes: 15 additions & 4 deletions leaflet-iiif.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ L.TileLayer.Iiif = L.TileLayer.extend({
this._explicitTileSize = true;
}

// Check for an explicit quality
if (options.quality) {
this._explicitQuality = true;
}

options = L.setOptions(this, options);
this._infoDeferred = new $.Deferred();
this._infoUrl = url;
Expand Down Expand Up @@ -172,18 +177,24 @@ L.TileLayer.Iiif = L.TileLayer.extend({

_setQuality: function() {
var _this = this;
var profileToCheck = _this.profile;

// Quality already specified by consumer
if (_this.options.quality) {
if (_this._explicitQuality) {
return;
}

// If profile is an object
if (typeof(profileToCheck) === 'object') {
profileToCheck = profileToCheck['@id'];
}

// Set the quality based on the IIIF compliance level
switch (true) {
case /^http:\/\/library.stanford.edu\/iiif\/image-api\/1.1\/compliance.html.*$/.test(_this.profile):
case /^http:\/\/library.stanford.edu\/iiif\/image-api\/1.1\/compliance.html.*$/.test(profileToCheck):
_this.options.quality = 'native';
break;
case /^http:\/\/iiif.io\/api\/image\/2.*$/.test(_this.profile):
// Assume later profiles and set to default
default:
_this.options.quality = 'default';
break;
}
Expand Down
9 changes: 9 additions & 0 deletions spec/LTileLayerIiifSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ describe('L.TileLayer.Iiif', function() {
done();
});
});

it('when a profile object is given', function(done) {
iiifLayer = L.tileLayer.iiif('http://localhost:9876/base/fixtures/profile_object/info.json');
map.addLayer(iiifLayer);
iiifLayer.on('load', function() {
expect(iiifLayer.options.quality).toBe('default');
done();
});
});
});

describe('tileSize', function() {
Expand Down
86 changes: 86 additions & 0 deletions spec/fixtures/profile_object/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"profile" : {
"formats" : [ "jpg" ],
"qualities" : [ "default" ],
"supports" : [ "regionByPx", "rotationBy90s", "sizeByH", "sizeByW", "sizeByWh" ],
"@context" : "http://iiif.io/api/image/2/context.json",
"@id" : "http://iiif.io/api/image/2/level2.json"
},
"height" : 4692,
"width" : 7384,
"protocol" : "http://iiif.io/api/image",
"tiles" : [ {
"width" : 750,
"height" : 750,
"scaleFactors" : [ 1, 2, 4, 8, 16 ]
} ],
"metadata" : [ {
"label" : "Work Record ID",
"value" : "<span>0057514</span>"
}, {
"label" : "Licence",
"value" : "<span><a href = \"https://creativecommons.org/licenses/by/3.0/\" target=\"_blank\"><img src = \"http://lac-luna-live4.is.ed.ac.uk:8181/graphics/by.jpg\"/></a></span>"
}, {
"label" : "Shelfmark",
"value" : "<span>La.III.804</span>"
}, {
"label" : "Holding Institution",
"value" : "<span>University of Edinburgh</span>"
}, {
"label" : "Title",
"value" : "<span>A Compleat Theory of the Scots Highland Bagpipe</span>"
}, {
"label" : "Subset Index",
"value" : "<span>f.1r</span>"
}, {
"label" : "Creator",
"value" : "<span>MacDonald, Joseph</span>"
}, {
"label" : "Date",
"value" : "<span>1760</span>"
}, {
"label" : "Description",
"value" : "<span>Coming from a musical family, Joseph MacDonald followed in the footsteps of his mother and father. Becoming frustrated with his music at an early age, MacDonald joined the East India Company and was off to sea, where he still wrote of the music of his home. While in the cabin, he wrote his manuscript for the Compleat Theory of the Scots Highland Bagpipes. Unfortunately, this manuscript was lost at sea on his journey and not long after MacDonald himself died from a contracted fever. It wasn't until 20 years after his year, in 1784, did a portion of the manuscript reappear in India. This manuscript was then passed along to Joseph’s brother, Patrick, who brought his brother's last work to be published.</span>"
}, {
"label" : "Subject Category",
"value" : "<span>Music</span>"
}, {
"label" : "Related Work Title",
"value" : "<span>A Compleat Theory of the Scots Highland Bagpipe</span>"
}, {
"label" : "Related Work Page No",
"value" : "<span>f.1r</span>"
}, {
"label" : "Rights Statement",
"value" : "<span>Copyright unknown, orphan work.</span>"
}, {
"label" : "Provenance Notes",
"value" : "<span>Believed to have belonged to Lord Eldin</span>"
}, {
"label" : "Tag",
"value" : "<span>Scotland</span>"
}, {
"label" : "Tag",
"value" : "<span>Bagpipes</span>"
}, {
"label" : "Tag",
"value" : "<span>East India Company</span>"
}, {
"label" : "Tag",
"value" : "<span>Music</span>"
}, {
"label" : "Repro File Type",
"value" : "<span>Cropped TIFF</span>"
}, {
"label" : "Repro Title",
"value" : "<span>A Compleat Theory of the Scots Highland Bagpipe, f.1r</span>"
}, {
"label" : "Repro Rights Statement",
"value" : "<span>Copyright The University of Edinburgh.</span>"
}, {
"label" : "Repro Publication Status",
"value" : "<span>Full Public Access</span>"
} ],
"@context" : "http://iiif.io/api/image/2/context.json",
"@id" : "http://images.is.ed.ac.uk/luna/servlet/iiif/UoEwmm~2~2~77099~164515"
}
Loading

0 comments on commit 05a4c65

Please sign in to comment.