Skip to content

Commit

Permalink
Merge pull request #80 from mejackreed/v3
Browse files Browse the repository at this point in the history
Generates a v3 canonical image uri
  • Loading branch information
mejackreed authored Nov 14, 2019
2 parents d9bd6ec + 747dc26 commit d192b59
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
10 changes: 9 additions & 1 deletion leaflet-iiif.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ L.TileLayer.Iiif = L.TileLayer.extend({
var xDiff = (maxx - minx);
var yDiff = (maxy - miny);

// Canonical URI Syntax for v2
var size = Math.ceil(xDiff / scale) + ',';
if (_this.type === 'ImageService3') {
// Cannonical URI Syntax for v3
size = size + Math.ceil(yDiff / scale);
}

return L.Util.template(this._baseUrl, L.extend({
format: _this.options.tileFormat,
quality: _this.quality,
region: [minx, miny, xDiff, yDiff].join(','),
rotation: 0,
size: Math.ceil(xDiff / scale) + ','
size: size
}, this.options));
},
onAdd: function(map) {
Expand Down Expand Up @@ -187,6 +194,7 @@ L.TileLayer.Iiif = L.TileLayer.extend({
}else {
_this.profile = data.profile;
}
_this.type = data.type;

_this._setQuality();

Expand Down
16 changes: 15 additions & 1 deletion spec/LTileLayerIiifSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,21 @@ describe('L.TileLayer.Iiif', function() {
});
done();
})
})
});

it('generates a v3 canonical url', function(done) {
var v3Image = L.tileLayer.iiif('http://localhost:9876/base/fixtures/v3/info.json');
map.addLayer(v3Image);
v3Image.on('load', function() {
var i = 0;
eachImg(v3Image, function (img) {
expect(img.src).toBe('http://localhost:9876/base/fixtures/v3/0,0,2000,1271/500,318/0/default.jpg')
i++;
});
done();
})
});

});

describe('fitBounds', function() {
Expand Down
28 changes: 28 additions & 0 deletions spec/fixtures/v3/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"@context": "http://iiif.io/api/image/3/context.json",
"extraFormats": [
"jpg",
"png"
],
"extraQualities": [
"default",
"color",
"gray"
],
"height": 1271,
"id": "http://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-xray",
"profile": "level1",
"protocol": "http://iiif.io/api/image",
"tiles": [
{
"height": 512,
"scaleFactors": [
1,
2
],
"width": 512
}
],
"type": "ImageService3",
"width": 2000
}

0 comments on commit d192b59

Please sign in to comment.