Skip to content

Commit

Permalink
update leaflet-iiif to 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Aug 27, 2015
1 parent 80f64d5 commit 1ea9b53
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions vendor/assets/javascripts/leaflet-iiif.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Leaflet-IIIF 0.0.5
* Leaflet-IIIF 0.0.7
* IIIF Viewer for Leaflet
* by Jack Reed, @mejackreed
*/
Expand All @@ -8,7 +8,8 @@ L.TileLayer.Iiif = L.TileLayer.extend({
options: {
continuousWorld: true,
tileSize: 256,
updateWhenIdle: true
updateWhenIdle: true,
tileFormat: 'jpg'
},

initialize: function(url, options) {
Expand All @@ -23,21 +24,38 @@ L.TileLayer.Iiif = L.TileLayer.extend({
x = coords.x,
y = (coords.y),
zoom = _this._map.getZoom(),
scale = Math.pow(2, _this.maxZoom - zoom),
scale = Math.pow(2, _this.maxNativeZoom - zoom),
tileBaseSize = _this.options.tileSize * scale,
minx = (x * tileBaseSize),
miny = (y * tileBaseSize),
maxx = Math.min(minx + tileBaseSize, _this.x),
maxy = Math.min(miny + tileBaseSize, _this.y);

var xDiff = (maxx - minx);
var yDiff = (maxy - miny);

return L.Util.template(this._baseUrl, L.extend({
format: 'jpg',
format: _this.options.tileFormat,
quality: _this.quality,
region: [minx, miny, (maxx - minx), (maxy - miny)].join(','),
region: [minx, miny, xDiff, yDiff].join(','),
rotation: 0,
size: 'pct:' + (100 / scale)
size: _this._iiifSizeParam(Math.ceil(xDiff / scale), Math.ceil(yDiff / scale))
}, this.options));
},
/**
* Returns a IIIF size parameter based off of the max dimension of
* a tile
* @param {Number} x - The width of a tile
* @param {Number} y - The height of a tile
* @returns {String}
*/
_iiifSizeParam: function(x, y) {
if (x >= y) {
return x + ',';
} else {
return ',' + y;
}
},
onAdd: function(map) {
var _this = this;

Expand Down Expand Up @@ -98,23 +116,11 @@ L.TileLayer.Iiif = L.TileLayer.extend({
}else {
profile = data.profile;
}
switch (profile) {
case 'http://library.stanford.edu/iiif/image-api/compliance.html#level1':
_this.quality = 100;
break;
case 'http://library.stanford.edu/iiif/image-api/1.1/compliance.html':
switch (true) {
case /^http:\/\/library.stanford.edu\/iiif\/image-api\/1.1\/compliance.html.*$/.test(profile):
_this.quality = 'native';
break;
case 'http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1':
_this.quality = 'native';
break;
case 'http://iiif.io/api/image/2/level2.json':
_this.quality = 'default';
break;
case 'http://iiif.io/api/image/2/level1.json':
_this.quality = 'default';
break;
case 'http://iiif.io/api/image/2/level0.json':
case /^http:\/\/iiif.io\/api\/image\/2.*$/.test(profile):
_this.quality = 'default';
break;
}
Expand All @@ -123,12 +129,20 @@ L.TileLayer.Iiif = L.TileLayer.extend({
return Math.ceil(Math.log(x) / Math.LN2);
};

// Calculates maxZoom for the layer
_this.maxZoom = Math.max(ceilLog2(_this.x / _this.options.tileSize),
// Calculates maximum native zoom for the layer
_this.maxNativeZoom = Math.max(ceilLog2(_this.x / _this.options.tileSize),
ceilLog2(_this.y / _this.options.tileSize));


// Enable zooming further than native if needed
if (_this.options.maxZoom && _this.options.maxZoom > _this.maxNativeZoom) {
_this.maxZoom = _this.options.maxZoom;
}
else {
_this.maxZoom = _this.maxNativeZoom;
}

for (var i = 0; i <= _this.maxZoom; i++) {
scale = Math.pow(2, _this.maxZoom - i);
scale = Math.pow(2, _this.maxNativeZoom - i);
width_ = Math.ceil(_this.x / scale);
height_ = Math.ceil(_this.y / scale);
tilesX_ = Math.ceil(width_ / _this.options.tileSize);
Expand Down Expand Up @@ -169,7 +183,7 @@ L.TileLayer.Iiif = L.TileLayer.extend({
tolerance = 0.8,
imageSize;

for (var i = _this.maxZoom; i >= 0; i--) {
for (var i = _this.maxNativeZoom; i >= 0; i--) {
imageSize = this._imageSizes[i];
if (imageSize.x * tolerance < mapSize.x && imageSize.y * tolerance < mapSize.y) {
return i;
Expand Down

0 comments on commit 1ea9b53

Please sign in to comment.