diff --git a/examples/iiif-example.js b/examples/iiif-example.js index 46fd7cd..9ab5f40 100644 --- a/examples/iiif-example.js +++ b/examples/iiif-example.js @@ -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], @@ -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 = { @@ -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); diff --git a/leaflet-iiif.js b/leaflet-iiif.js index 8af0d6c..502516e 100644 --- a/leaflet-iiif.js +++ b/leaflet-iiif.js @@ -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; @@ -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; } diff --git a/spec/LTileLayerIiifSpec.js b/spec/LTileLayerIiifSpec.js index bc86fd6..24e04f9 100644 --- a/spec/LTileLayerIiifSpec.js +++ b/spec/LTileLayerIiifSpec.js @@ -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() { diff --git a/spec/fixtures/profile_object/info.json b/spec/fixtures/profile_object/info.json new file mode 100644 index 0000000..bbd874d --- /dev/null +++ b/spec/fixtures/profile_object/info.json @@ -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" : "0057514" + }, { + "label" : "Licence", + "value" : "" + }, { + "label" : "Shelfmark", + "value" : "La.III.804" + }, { + "label" : "Holding Institution", + "value" : "University of Edinburgh" + }, { + "label" : "Title", + "value" : "A Compleat Theory of the Scots Highland Bagpipe" + }, { + "label" : "Subset Index", + "value" : "f.1r" + }, { + "label" : "Creator", + "value" : "MacDonald, Joseph" + }, { + "label" : "Date", + "value" : "1760" + }, { + "label" : "Description", + "value" : "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." + }, { + "label" : "Subject Category", + "value" : "Music" + }, { + "label" : "Related Work Title", + "value" : "A Compleat Theory of the Scots Highland Bagpipe" + }, { + "label" : "Related Work Page No", + "value" : "f.1r" + }, { + "label" : "Rights Statement", + "value" : "Copyright unknown, orphan work." + }, { + "label" : "Provenance Notes", + "value" : "Believed to have belonged to Lord Eldin" + }, { + "label" : "Tag", + "value" : "Scotland" + }, { + "label" : "Tag", + "value" : "Bagpipes" + }, { + "label" : "Tag", + "value" : "East India Company" + }, { + "label" : "Tag", + "value" : "Music" + }, { + "label" : "Repro File Type", + "value" : "Cropped TIFF" + }, { + "label" : "Repro Title", + "value" : "A Compleat Theory of the Scots Highland Bagpipe, f.1r" + }, { + "label" : "Repro Rights Statement", + "value" : "Copyright The University of Edinburgh." + }, { + "label" : "Repro Publication Status", + "value" : "Full Public Access" + } ], + "@context" : "http://iiif.io/api/image/2/context.json", + "@id" : "http://images.is.ed.ac.uk/luna/servlet/iiif/UoEwmm~2~2~77099~164515" +}