From c5ba5b0456a711d157e317f220e9c739226e7f50 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Tue, 10 Jan 2012 01:54:37 +0100 Subject: Installed leaflet in extlib --- extlib/leaflet/src/layer/LayerGroup.js | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 extlib/leaflet/src/layer/LayerGroup.js (limited to 'extlib/leaflet/src/layer/LayerGroup.js') diff --git a/extlib/leaflet/src/layer/LayerGroup.js b/extlib/leaflet/src/layer/LayerGroup.js new file mode 100644 index 00000000..58940d40 --- /dev/null +++ b/extlib/leaflet/src/layer/LayerGroup.js @@ -0,0 +1,58 @@ +/* + * L.LayerGroup is a class to combine several layers so you can manipulate the group (e.g. add/remove it) as one layer. + */ + +L.LayerGroup = L.Class.extend({ + initialize: function(layers) { + this._layers = {}; + + if (layers) { + for (var i = 0, len = layers.length; i < len; i++) { + this.addLayer(layers[i]); + } + } + }, + + addLayer: function(layer) { + var id = L.Util.stamp(layer); + this._layers[id] = layer; + + if (this._map) { + this._map.addLayer(layer); + } + return this; + }, + + removeLayer: function(layer) { + var id = L.Util.stamp(layer); + delete this._layers[id]; + + if (this._map) { + this._map.removeLayer(layer); + } + return this; + }, + + clearLayers: function() { + this._iterateLayers(this.removeLayer, this); + return this; + }, + + onAdd: function(map) { + this._map = map; + this._iterateLayers(map.addLayer, map); + }, + + onRemove: function(map) { + this._iterateLayers(map.removeLayer, map); + delete this._map; + }, + + _iterateLayers: function(method, context) { + for (var i in this._layers) { + if (this._layers.hasOwnProperty(i)) { + method.call(context, this._layers[i]); + } + } + } +}); \ No newline at end of file -- cgit v1.2.3