Skip to content

Commit

Permalink
Merge pull request #56 from mejackreed/tileSize-bug
Browse files Browse the repository at this point in the history
fixes a bug where an explicit tileSize was not being honored
  • Loading branch information
mejackreed authored Dec 5, 2016
2 parents 6f817b5 + c52bf75 commit 378355f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
4 changes: 3 additions & 1 deletion leaflet-iiif.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ L.TileLayer.Iiif = L.TileLayer.extend({
_this._setQuality();

// Unless an explicit tileSize is set, use a preferred tileSize
if (!_this.explicitTileSize) {
if (!_this._explicitTileSize) {
// Set the default first
_this.options.tileSize = 256;
if (data.tiles) {
// Image API 2.0 Case
_this.options.tileSize = data.tiles[0].width;
Expand Down
48 changes: 48 additions & 0 deletions spec/LTileLayerIiifSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,52 @@ describe('L.TileLayer.Iiif', function() {
});
});
});

describe('tileSize', function() {
var iiifLayer;

afterEach(function() {
iiifLayer.off('load');
});

describe('when not specified', function() {
it('uses the tileSize from info.json v2', function(done) {
iiifLayer = L.tileLayer.iiif('http://localhost:9876/base/fixtures/mlk/info.json');
map.addLayer(iiifLayer);
iiifLayer.on('load', function() {
expect(iiifLayer.options.tileSize).toBe(1024);
done();
});
});
it('uses the tileSize from info.json v1', function(done) {
iiifLayer = L.tileLayer.iiif('http://localhost:9876/base/fixtures/statue_info.json');
map.addLayer(iiifLayer);
iiifLayer.on('load', function() {
expect(iiifLayer.options.tileSize).toBe(1024);
done();
});
});
it('uses default tileSize (not specified in info.json)', function(done) {
iiifLayer = L.tileLayer.iiif('http://localhost:9876/base/fixtures/edge_case/info.json');
map.addLayer(iiifLayer);
iiifLayer.on('load', function() {
expect(iiifLayer.options.tileSize).toBe(256);
done();
});
});
});
describe('when specified', function() {
it('uses the explicitly defined one', function(done) {
iiifLayer = L.tileLayer.iiif('http://localhost:9876/base/fixtures/mlk/info.json', {
tileSize: 512
});
map.addLayer(iiifLayer);
iiifLayer.on('load', function() {
expect(iiifLayer.options.tileSize).toBe(512);
done();
});
});
});

});
});
21 changes: 21 additions & 0 deletions spec/fixtures/edge_case/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"@context": "http://library.stanford.edu/iiif/image-api/1.1/context.json",
"@id": "http://ids.lib.harvard.edu/ids/iiif/25286610",
"width": 4132,
"height": 8176,
"scale_factors": [
1,
2,
4,
8,
16,
32
],
"formats": [
"jpg"
],
"qualities": [
"native"
],
"profile": "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1"
}

0 comments on commit 378355f

Please sign in to comment.