map#hasLayer, ability to add tile layers below all others

This commit is contained in:
Mourner 2011-07-12 20:18:22 +03:00
parent 9b8db34fa3
commit 0936b5e18c
3 changed files with 22 additions and 7 deletions

View File

@ -13,6 +13,8 @@ Leaflet Changelog
* Improved circles performance by not drawing them if they're off the clip region.
* Improved browser-specific code to rely more on feature detection rather than user agent string.
* Improved superclass access mechanism to work with inheritance chains of 3 or more classes; now you should use `Klass.superclass` instead of `this.superclass` (by [@anru](https://github.com/anru)). [#179](https://github.com/CloudMade/Leaflet/pull/179)
* Added ability to add a tile layer below all others (`map.addLayer(layer, true)`) (useful for switching base tile layers).
* Added `hasLayer` method to `Map`.
### Bugfixes

View File

@ -30,11 +30,11 @@ L.TileLayer = L.Class.extend({
}
},
onAdd: function(map) {
onAdd: function(map, insertAtTheTop) {
this._map = map;
// create a container div for tiles
this._initContainer();
this._initContainer(insertAtTheTop);
// create an image to clone for tiles
this._createTileProto();
@ -89,11 +89,18 @@ L.TileLayer = L.Class.extend({
}
},
_initContainer: function() {
var tilePane = this._map.getPanes().tilePane;
_initContainer: function(insertAtTheTop) {
var tilePane = this._map.getPanes().tilePane,
first = tilePane.firstChild;
if (!this._container || tilePane.empty) {
this._container = L.DomUtil.create('div', 'leaflet-layer', tilePane);
this._container = L.DomUtil.create('div', 'leaflet-layer');
if (insertAtTheTop && first) {
tilePane.insertBefore(this._container, first);
} else {
tilePane.appendChild(this._container);
}
this._setOpacity(this.options.opacity);
}

View File

@ -113,7 +113,7 @@ L.Map = L.Class.extend({
return this;
},
addLayer: function(layer) {
addLayer: function(layer, insertAtTheTop) {
var id = L.Util.stamp(layer);
if (this._layers[id]) return this;
@ -137,7 +137,7 @@ L.Map = L.Class.extend({
}
var onMapLoad = function() {
layer.onAdd(this);
layer.onAdd(this, insertAtTheTop);
this.fire('layeradd', {layer: layer});
};
@ -170,6 +170,12 @@ L.Map = L.Class.extend({
return this;
},
hasLayer: function(layer) {
var id = L.Util.stamp(layer);
return (id in this._layers);
},
invalidateSize: function() {
this._sizeChanged = true;