Script and makefile adjustments for updating extlib
[larjonas-mediagoblin.git] / extlib / leaflet / src / layer / LayerGroup.js
blob58940d40f3cf1ead88bf83022612ec3cbb0a2610
1 /*
2 * L.LayerGroup is a class to combine several layers so you can manipulate the group (e.g. add/remove it) as one layer.
3 */
5 L.LayerGroup = L.Class.extend({
6 initialize: function(layers) {
7 this._layers = {};
9 if (layers) {
10 for (var i = 0, len = layers.length; i < len; i++) {
11 this.addLayer(layers[i]);
16 addLayer: function(layer) {
17 var id = L.Util.stamp(layer);
18 this._layers[id] = layer;
20 if (this._map) {
21 this._map.addLayer(layer);
23 return this;
26 removeLayer: function(layer) {
27 var id = L.Util.stamp(layer);
28 delete this._layers[id];
30 if (this._map) {
31 this._map.removeLayer(layer);
33 return this;
36 clearLayers: function() {
37 this._iterateLayers(this.removeLayer, this);
38 return this;
41 onAdd: function(map) {
42 this._map = map;
43 this._iterateLayers(map.addLayer, map);
46 onRemove: function(map) {
47 this._iterateLayers(map.removeLayer, map);
48 delete this._map;
51 _iterateLayers: function(method, context) {
52 for (var i in this._layers) {
53 if (this._layers.hasOwnProperty(i)) {
54 method.call(context, this._layers[i]);
58 });