Make GridLayer methods safe to call pre-setView

This commit is contained in:
John Firebaugh 2013-12-13 18:01:06 -05:00
parent c1654c4626
commit af9302ce19
2 changed files with 20 additions and 4 deletions

View File

@ -16,6 +16,22 @@ describe('GridLayer', function () {
document.body.removeChild(div); document.body.removeChild(div);
}); });
describe('#redraw', function () {
it('can be called before map.setView', function () {
var map = L.map(div),
grid = L.gridLayer().addTo(map);
expect(grid.redraw()).to.equal(grid);
});
});
describe('#setOpacity', function () {
it('can be called before map.setView', function () {
var map = L.map(div),
grid = L.gridLayer().addTo(map);
expect(grid.setOpacity(0.5)).to.equal(grid);
});
});
it('positions tiles correctly with wrapping and bounding', function () { it('positions tiles correctly with wrapping and bounding', function () {
var map = L.map(div).setView([0, 0], 1); var map = L.map(div).setView([0, 0], 1);

View File

@ -53,7 +53,7 @@ L.GridLayer = L.Layer.extend({
}, },
bringToFront: function () { bringToFront: function () {
if (this._map) { if (this._container) {
var pane = this.getPane(); var pane = this.getPane();
pane.appendChild(this._container); pane.appendChild(this._container);
this._setAutoZIndex(pane, Math.max); this._setAutoZIndex(pane, Math.max);
@ -62,7 +62,7 @@ L.GridLayer = L.Layer.extend({
}, },
bringToBack: function () { bringToBack: function () {
if (this._map) { if (this._container) {
var pane = this.getPane(); var pane = this.getPane();
pane.insertBefore(this._container, pane.firstChild); pane.insertBefore(this._container, pane.firstChild);
this._setAutoZIndex(pane, Math.min); this._setAutoZIndex(pane, Math.min);
@ -81,7 +81,7 @@ L.GridLayer = L.Layer.extend({
setOpacity: function (opacity) { setOpacity: function (opacity) {
this.options.opacity = opacity; this.options.opacity = opacity;
if (this._map) { if (this._container) {
this._updateOpacity(); this._updateOpacity();
} }
return this; return this;
@ -95,7 +95,7 @@ L.GridLayer = L.Layer.extend({
}, },
redraw: function () { redraw: function () {
if (this._map) { if (this._container) {
this._reset({hard: true}); this._reset({hard: true});
this._update(); this._update();
} }