This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.html
133 lines (112 loc) · 5.15 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DesertBus Community Chatmap</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!-- Leaflet -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
<!-- Mapbox GL (for the custom English map, which uses vector tiles) -->
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.5.0/mapbox-gl.css' rel='stylesheet' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.5.0/mapbox-gl.js'></script>
<script src="https://unpkg.com/mapbox-gl-leaflet/leaflet-mapbox-gl.js"></script>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
width: 100%;
}
#searchbar {
width: 20em;
position: fixed;
top: 1em;
left: 4em;
z-index: 500;
}
</style>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/2.6.1/fuse.min.js"></script>
<script type="text/javascript">
var chatizens, searchIndex, map;
function doSearch() {
var results = searchIndex.search(document.getElementById("searchbar").value);
document.getElementById("suggestions").innerHTML = "";
results.forEach(result => document.getElementById("suggestions").innerHTML += "<option>" + result + "</option>");
}
function submitSearch() {
chatizens.forEach(function (chatizen) {
if (chatizen.nick.toUpperCase() === document.getElementById("searchbar").value.toUpperCase()) {
map.setView({lat: chatizen.lat, lon: chatizen.lon}, 6);
}
});
}
</script>
</head>
<body>
<form action="#" onsubmit="submitSearch()">
<input type="search" id="searchbar" placeholder="Search" list="suggestions" oninput="doSearch()" autocomplete="off">
<datalist id="suggestions"></datalist>
</form>
<div id="map"></div>
<script>
function initMap() {
// initialize Leaflet
var mainLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19, attribution: '© <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
});
var EnglishLayer = L.mapboxGL({
attribution: '<a href="https://www.maptiler.com/copyright/" target="_blank">© MapTiler</a> <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>',
accessToken: 'not-needed',
style: 'https://api.maptiler.com/maps/4d188d87-c11b-4328-8e70-01c4cacc8c3f/style.json?key=gxTeBGYDCi08suCVsWUo'
});
var GermanLayer = L.tileLayer('https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png', {
maxZoom: 19, attribution: '© <a href="https://openstreetmap.de/copyright">OpenStreetMap contributors</a>'
});
var FrenchLayer = L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {
maxZoom: 19, attribution: '© <a href="https://openstreetmap.fr/copyright">OpenStreetMap contributors</a>'
});
var WikipediaLayer = L.tileLayer('https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png', {
maxZoom: 19, attribution: '© <a href="https://foundation.wikimedia.org">Wikimedia</a>'
});
map = L.map('map', {
center: {lat: 0, lon: 0},
zoom: 3,
layers: mainLayer
});
// show the scale bar on the lower left corner
L.control.scale().addTo(map);
// show the layer control
var baseMaps = {
"Open Street Maps": mainLayer,
"English Map": EnglishLayer,
"German OSM": GermanLayer,
"French OSM": FrenchLayer,
"Wikipedia": WikipediaLayer
};
L.control.layers(baseMaps).addTo(map);
// Add a marker for each chatizen to the map
function addPin(chatizen) {
L.marker({lat: chatizen.lat, lon: chatizen.lon}, {riseOnHover: true})
.bindPopup(chatizen.nick, {autoClose: false, closeOnClick: false})
.bindTooltip(chatizen.nick, {/*permanent: true*/}).openTooltip()
.addTo(map);
}
document.cookie = "password=sadmcasldkfjsdclasdkcmascdmklasdm";
fetch("/api/chatizen", {credentials: "include"}).then(response => response.json()).then((data) => {
var options = {
keys: ["nick"],
id: "nick"
};
chatizens = data;
searchIndex = new Fuse(data, options);
data.forEach(chatizen => addPin(chatizen));
});
}
initMap();
</script>
</body>
</html>