bring this._map check back

This commit is contained in:
Vladimir Agafonkin 2013-12-13 18:35:51 -05:00
parent af9302ce19
commit f619e3b242
2 changed files with 11 additions and 9 deletions

View File

@ -7,8 +7,6 @@ L.Layer = L.Class.extend({
},
addTo: function (map) {
this._map = map;
var id = L.stamp(this);
if (map._layers[id]) { return this; }
map._layers[id] = this;
@ -19,17 +17,21 @@ L.Layer = L.Class.extend({
this.beforeAdd(map);
}
this._mapToAdd = map;
map.whenReady(this._layerAdd, this);
return this;
},
_layerAdd: function () {
var map = this._map;
var map = this._mapToAdd;
// check in case layer gets added and then removed before the map is ready
if (!map) { return; }
this._map = map;
this._mapToAdd = null;
this.onAdd(map);
if (this.getEvents) {
@ -43,7 +45,7 @@ L.Layer = L.Class.extend({
remove: function () {
var id = L.stamp(this),
map = this._map;
map = this._map || this._mapToAdd;
if (!map || !map._layers[id]) { return this; }
@ -62,7 +64,7 @@ L.Layer = L.Class.extend({
this.fire('remove');
}
this._map = null;
this._map = this._mapToAdd = null;
return this;
},

View File

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