forked from recoded-co/coinmap
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Permalink.Line.js
49 lines (44 loc) · 1.17 KB
/
Permalink.Line.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//#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) {
//console.info("onAdd::line", 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) {
//console.info("Set line", e.params.line);
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);
}
});