Skip to content

Commit

Permalink
Negative minzoom fix (#71)
Browse files Browse the repository at this point in the history
* Copy imageSizes before mutation

* Add tests for imageSizes issue

* Test CI

* Adjust test--no jQuery

* Erm... Maybe I'm mutating map state?

* No really.. don't modify map state?

* Or... get rid of my tests entirely

* 😒 Move test up before expect() error 😒

* Remove failing example
  • Loading branch information
cbutcosk authored and mejackreed committed Apr 16, 2018
1 parent 990bbe2 commit 06f36d4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions leaflet-iiif.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ L.TileLayer.Iiif = L.TileLayer.extend({
// Wait for deferred to complete
$.when(_this._infoDeferred).done(function() {

// Store unmutated imageSizes
_this._imageSizesOriginal = _this._imageSizes.slice(0);

// Set maxZoom for map
map._layersMaxZoom = _this.maxZoom;

Expand Down Expand Up @@ -118,6 +121,7 @@ L.TileLayer.Iiif = L.TileLayer.extend({
var _this = this;

map._layersMinZoom = _this._prev_map_layersMinZoom;
_this._imageSizes = _this._imageSizesOriginal;

// Remove maxBounds set for this image
if(_this.options.setMaxBounds) {
Expand Down
39 changes: 38 additions & 1 deletion spec/LTileLayerIiifSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('L.TileLayer.Iiif', function() {
done();
});
});

});

describe('generated tile urls', function() {
Expand Down Expand Up @@ -228,7 +229,42 @@ describe('L.TileLayer.Iiif', function() {

});

describe('setMaxBounds', function() {
describe('negativeMinZoom', function() {

var iiifLayer;

beforeEach(function() {

iiifLayer = L.tileLayer.iiif('http://localhost:9876/base/fixtures/cantaloupe/info.json');
map.setMinZoom(-1);

iiifLayer.addTo(map)

});

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

it('with a large tileSize and negative minZoom, ensure that the layer does not persist zoom changes', function(done) {

$.when(iiifLayer._infoDeferred).done( function() {

map.removeLayer(iiifLayer);
map.addLayer(iiifLayer);

});

iiifLayer.on('load', function() {
expect(iiifLayer.options.minZoom).toBe(-2);
expect(iiifLayer.options.minNativeZoom).toBe(-2);
done();
});

});
});

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

beforeEach(function() {
Expand Down Expand Up @@ -259,4 +295,5 @@ describe('L.TileLayer.Iiif', function() {
});
});
});

});

0 comments on commit 06f36d4

Please sign in to comment.