-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
95 lines (79 loc) · 2.52 KB
/
app.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// rfmap
$(function(){
var overpassEndpoint = 'http://overpass-api.de/api/interpreter';
var initQuery = '[out:json][timeout:25];' +
'(' +
'node["rf:frequency"];' +
'way["rf:frequency"];' +
'rel["rf:frequency"];' +
'>;' +
');' +
'out body;';
function arEach(obj, fun){
var i, j, length;
for (i = 0, length = obj.length; i < length; i++) {
fun(obj[i]);
}
}
function showInfo(f) {
var out = '';
var tags = f.properties && f.properties.tags || {};
var rels = f.properties && f.properties.relations || {};
if (tags['rf:frequency']) {
rels.push({reltags: tags});
}
out += '<h2>'+ (tags.name || f.id) +'</h2>';
if (tags.description) {
out += '<p>'+ tags.description +'</p>';
}
out += '<ul>';
arEach(rels,function(rel){
var tags = rel.reltags || {}
out += '<li>'+(tags['rf:content'] || tags['name']) +' at ' + tags['rf:frequency']+ ' '+tags['rf:modulation']+'</li>';
});
out += '</ul>';
out += '<br><a href="https://www.openstreetmap.org/' + f.id + '">show details on OSM</a>'
$('#output').html(out);
};
function makeInfo(feature, layer) {
layer.on('click', function() {
console.log(feature);
showInfo(feature);
});
};
var map = L.map('rfmap', {
center: [50.09027, 14.41025],
zoom: 12
});
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'}).addTo(map);
var dataLayer = L.geoJSON(null, {onEachFeature: makeInfo}).addTo(map);
var request_headers = {};
request_headers["X-Requested-With"] = 'RFmap (http://rfmap.svita.cz)';
$.ajax({
type: 'POST',
url: overpassEndpoint,
data: { data: initQuery },
headers: request_headers,
success: function(data) {
var processed = osmtogeojson(data);
dataLayer.clearLayers();
dataLayer.addData(processed);
map.fitBounds(dataLayer.getBounds());
$('#output').html('Click on any marker to see details...');
}
});
/*$.ajax({
type: 'GET',
url: 'testdata.json',
data: { data: initQuery },
headers: request_headers,
success: function(data) {
data = JSON.parse(data);
var processed = osmtogeojson(data);
dataLayer.clearLayers();
dataLayer.addData(processed);
map.fitBounds(dataLayer.getBounds());
$('#output').html('Click on any marker to see details...');
}
});*/
});