Skip to content

Commit

Permalink
Merge pull request #36 from mejackreed/fix-specs
Browse files Browse the repository at this point in the history
Fix specs for fitBounds and fixes a regression discovered with reference to the map object
  • Loading branch information
mejackreed committed Apr 17, 2016
2 parents 3d0e8d7 + 5e89c43 commit dea790f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 4 additions & 4 deletions leaflet-iiif.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ L.TileLayer.Iiif = L.TileLayer.extend({
var _this = this;

// Find best zoom level and center map
var initialZoom = _this._getInitialZoom(map.getSize());
var initialZoom = _this._getInitialZoom(_this._map.getSize());
var imageSize = _this._imageSizes[initialZoom];
var sw = map.options.crs.pointToLatLng(L.point(0, imageSize.y), initialZoom);
var ne = map.options.crs.pointToLatLng(L.point(imageSize.x, 0), initialZoom);
var sw = _this._map.options.crs.pointToLatLng(L.point(0, imageSize.y), initialZoom);
var ne = _this._map.options.crs.pointToLatLng(L.point(imageSize.x, 0), initialZoom);
var bounds = L.latLngBounds(sw, ne);

map.fitBounds(bounds, true);
_this._map.fitBounds(bounds, true);
},
_getInfo: function() {
var _this = this;
Expand Down
26 changes: 23 additions & 3 deletions spec/LTileLayerIiifSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ describe('L.TileLayer.Iiif', function() {

document.body.appendChild(div);

map = L.map(div);
map = L.map(div, {
center: [0, 0],
crs: L.CRS.Simple,
zoom: 0
});
});

afterEach(function() {
Expand All @@ -32,9 +36,25 @@ describe('L.TileLayer.Iiif', function() {
iiifLayer = iiifLayerFactory();
});

it('by default is on', function() {
expect(iiifLayer.options.fitBounds).toBe(true);
it('by default is on', function(done) {
map.addLayer(iiifLayer);
iiifLayer.on('load', function() {
expect(iiifLayer.options.fitBounds).toBe(true);
expect(map.getBounds().getSouthWest().toString()).toBe('LatLng(-539, -60)');
expect(map.getBounds().getNorthEast().toString()).toBe('LatLng(61, 740)');
done();
});
});

it('can be configured not to be on', function(done) {
var iiifLayerNoFitBounds = iiifLayerFactory({ fitBounds: false });
map.addLayer(iiifLayerNoFitBounds);
iiifLayerNoFitBounds.on('load', function() {
expect(iiifLayerNoFitBounds.options.fitBounds).toBe(false);
expect(map.getBounds().getSouthWest().toString()).toBe('LatLng(-300, -400)');
expect(map.getBounds().getNorthEast().toString()).toBe('LatLng(300, 400)');
done();
});
});
});
});

0 comments on commit dea790f

Please sign in to comment.