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.Line.js | |
parent | c6f7e24e373142e8618f4b6ed60df04bc0872354 (diff) | |
download | Chimère-leaflet-permalink.tar.bz2 Chimère-leaflet-permalink.zip |
Add leaflet-pluginsleaflet-permalink
Diffstat (limited to 'chimere/static/leaflet-plugins/control/Permalink.Line.js')
-rw-r--r-- | chimere/static/leaflet-plugins/control/Permalink.Line.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/chimere/static/leaflet-plugins/control/Permalink.Line.js b/chimere/static/leaflet-plugins/control/Permalink.Line.js new file mode 100644 index 0000000..794880a --- /dev/null +++ b/chimere/static/leaflet-plugins/control/Permalink.Line.js @@ -0,0 +1,47 @@ +//#include "Permalink.js + +L.Control.Permalink.include({ + /* + options: { + line: null + }, + */ + + initialize_line: function() { + this.on('update', this._set_line, this); + this.on('add', this._onadd_line, this); + }, + + _onadd_line: function(e) { + if (!this.options.line) return; + this.options.line.on('edit', this._update_line, this); + this._update_line(); + }, + + _update_line: function() { + if (!this.options.line) return; + var line = this.options.line; + if (!line) return; + var text = [], coords = line.getLatLngs(); + if (!coords.length) + return this._update({line: null}); + for (var i in coords) + text.push(coords[i].lat.toFixed(4) + ',' + coords[i].lng.toFixed(4)); + this._update({line: text.join(';')}); + }, + + _set_line: function(e) { + var p = e.params, l = this.options.line; + if (!l || !p.line) return; + var coords = [], text = p.line.split(';'); + for (var i in text) { + var ll = text[i].split(','); + if (ll.length !== 2) continue; + coords.push(new L.LatLng(ll[0], ll[1])); + } + if (!coords.length) return; + l.setLatLngs(coords); + if (!this._map.hasLayer(l)) + this._map.addLayer(l); + } +}); |