-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
80 lines (68 loc) · 1.97 KB
/
map.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LocToMap</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<style>
#mapid{
height: 800px;
}
input[type=text], select {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit]:hover {
background-color: #45a049;
}
#domainInput {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
</head>
<body>
<input type="text" id="domainInput" placeholder="Enter a domain which holds a LOC record and press Enter">
<br />
<br />
<div id="container">
<div id="mapid"></div>
</div>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script>
var map = L.map('mapid');
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
function fetchData() {
var domain = document.getElementById("domainInput").value;
if (!domain) {
alert("Please enter a domain");
return;
}
fetch('/api/' + domain)
.then(response => response.json())
.then(data => {
var latitude = data.latitude;
var longitude = data.longitude;
map.setView([latitude, longitude], 13);
L.marker([latitude, longitude]).addTo(map);
L.marker([latitude, longitude]).bindPopup("<b>" + domain + "</b>" + "<br \>" + data.full).addTo(map).openPopup();
})
.catch(error => console.error('Error:', error));
}
document.getElementById("domainInput").addEventListener("keypress", function(event) {
if (event.key === "Enter") {
fetchData();
}
});
</script>
</body>
</html>