-
Notifications
You must be signed in to change notification settings - Fork 9
/
OverPassLayer.js
72 lines (57 loc) · 1.47 KB
/
OverPassLayer.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function poiInfo(tags) {
r = '';
if (tags.hasOwnProperty('name')) {
r += tags['name'];
}
if (tags.hasOwnProperty('addr:city')) {
r += ' - ' + tags['addr:city'];
}
if (tags.hasOwnProperty('website')) {
r += ' - <a href="' + tags['website'] + '">' + tags['website'] + '</a>'
}
return $('<div>').append(r).html();
};
L.OverPassLayer = L.FeatureGroup.extend({
options: {
query: "",
map: "",
oms: "",
callback: function(data) {
for(i=0;i<data.elements.length;i++) {
e = data.elements[i];
var loc = new L.LatLng(e.lat, e.lon);
var marker = new L.Marker(loc);
marker.desc = poiInfo(e.tags);
this.map.addLayer(marker);
this.oms.addMarker(marker);
}
}
},
initialize: function (options) {
L.Util.setOptions(this, options);
this._layers = {};
this._ids = {};
this.map = options.map;
this.oms = options.oms;
this.onMoveEnd();
if (this.options.query.indexOf("(BBOX)") != -1) {
this.map.on('moveend', this.onMoveEnd, this);
}
},
_poiInfo: function(tags) {
var r = $('<table>');
for (key in tags)
r.append($('<tr>').append($('<th>').text(key)).append($('<td>').text(tags[key])));
return $('<div>').append(r).html();
},
onMoveEnd: function () {
$.ajax({
url: this.options.query,
context: this,
crossDomain: true,
dataType: "json",
data: {},
success: this.options.callback
});
},
});