-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.html
58 lines (55 loc) · 1.92 KB
/
card.html
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
<!DOCTYPE html>
<html lang="en_US">
<head>
<meta charset="UTF-8">
<title>OSM Business Card</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300" rel="stylesheet" />
<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
function gup (name) {
name = RegExp ('[?&]' + name.replace (/([[\]])/, '\\$1') + '=([^&#]*)');
return (window.location.href.match (name) || ['', ''])[1];
}
</script>
<script src="card.js"></script>
</head>
<body>
<div id="map"></div>
<div id="card">
<h2 id="name"></h2>
<p id="address"></p>
<div id="contact"></div>
<!-- TODO: small OSM logo in bottom corner, links to OSM object -->
</div>
<script src="map.js"></script>
<script>
// Form Overpass query from url parameters
type = gup('type'); // TODO: combine these into one param?
id = gup('id');
query = "[out:json][timeout:10];";
if (type == 'n') {
query = query + 'node(' + id + ');out;'
}
else if (type == 'w') {
query = query + 'way(' + id + ');out center;'
}
else if (type == 'r') {
query = query + 'rel(' + id + ');out center;'
}
else {
throw new Error('Unknown object type given.')
}
// get response from Overpass
$.getJSON('https://overpass-api.de/api/interpreter?data=' + query, function(data) {
console.log(data);
buildCard(data.elements[0]);
updateMap(data.elements[0]);
// TODO: update 'report an error' with map coords
});
</script>
</body>
</html>