diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-04-27 23:35:11 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-04-27 23:35:11 +0200 |
commit | 1469e4552b0f9b789c46b3ce027d4acb9f906dbd (patch) | |
tree | 42363492b9157f396139511acb73a1ed73fe53a7 /chimere/static/leaflet-plugins/control/Permalink.Layer.js | |
parent | c6f7e24e373142e8618f4b6ed60df04bc0872354 (diff) | |
download | Chimère-1469e4552b0f9b789c46b3ce027d4acb9f906dbd.tar.bz2 Chimère-1469e4552b0f9b789c46b3ce027d4acb9f906dbd.zip |
Add leaflet-pluginsleaflet-permalink
Diffstat (limited to 'chimere/static/leaflet-plugins/control/Permalink.Layer.js')
-rw-r--r-- | chimere/static/leaflet-plugins/control/Permalink.Layer.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/chimere/static/leaflet-plugins/control/Permalink.Layer.js b/chimere/static/leaflet-plugins/control/Permalink.Layer.js new file mode 100644 index 0000000..b290d91 --- /dev/null +++ b/chimere/static/leaflet-plugins/control/Permalink.Layer.js @@ -0,0 +1,71 @@ +//#include "Permalink.js + +L.Control.Permalink.include({ + /* + options: { + useMarker: true, + markerOptions: {} + }, + */ + + initialize_layer: function() { + this.on('update', this._set_layer, this); + this.on('add', this._onadd_layer, this); + }, + + _onadd_layer: function(e) { + this._map.on('layeradd', this._update_layer, this); + this._map.on('layerremove', this._update_layer, this); + this._update_layer(); + }, + + _update_layer: function() { + if (!this.options.layers) return; + var layer = this.options.layers.currentBaseLayer(); + if (layer) + this._update({layer: layer.name}); + }, + + _set_layer: function(e) { + var p = e.params; + if (!this.options.layers || !p.layer) return; + this.options.layers.chooseBaseLayer(p.layer); + } +}); + +L.Control.Layers.include({ + chooseBaseLayer: function(name) { + var layer, obj; + for (var i in this._layers) { + if (!this._layers.hasOwnProperty(i)) + continue; + obj = this._layers[i]; + if (!obj.overlay && obj.name === name) + layer = obj.layer; + } + if (!layer || this._map.hasLayer(layer)) + return; + + for (var j in this._layers) { + if (!this._layers.hasOwnProperty(j)) + continue; + obj = this._layers[j]; + if (!obj.overlay && this._map.hasLayer(obj.layer)) + this._map.removeLayer(obj.layer); + } + this._map.addLayer(layer); + this._update(); + }, + + currentBaseLayer: function() { + for (var i in this._layers) { + if (!this._layers.hasOwnProperty(i)) + continue; + var obj = this._layers[i]; + if (obj.overlay) continue; + if (!obj.overlay && this._map.hasLayer(obj.layer)) + return obj; + } + } +}); + |