-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend.html
98 lines (91 loc) · 2.81 KB
/
frontend.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
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<script>
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("form").addEventListener("submit", function(e) {
e.preventDefault();
e.stopPropagation();
var twitterHandle = document.getElementById("twitterHandle");
reloadMapData(twitterHandle.value);
});
});
var map;
var currentMarkers = [];
var infoWindow;
var infoWindowContent = "";
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 43.653, lng: -79.382 },
zoom: 3
});
infoWindow = new google.maps.InfoWindow({
content: infoWindowContent
});
}
function clearMarkers() {
for (var i = 0; i < currentMarkers.length; i++) {
currentMarkers[i].setMap(null);
}
currentMarkers = [];
}
function reloadMapData(twitterHandle) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
markers = JSON.parse(this.response);
clearMarkers();
applyMarkers(markers);
}
};
xhttp.open("GET", "map.php?username=" + twitterHandle, true);
xhttp.send();
}
function applyMarkers(markers) {
var marker;
for (var i = 0; i < markers.length; i++){
var tweetText = markers[i].text;
var lng = markers[i].lng;
var lat = markers[i].lat;
var source = markers[i].source;
marker = new google.maps.Marker({
position: {'lng':lng, 'lat':lat},
map: map,
title: 'Hello World!'
});
google.maps.event.addListener(marker,'click', (function(marker,tweetText,source, infowindow){
return function() {
infowindow.setContent(tweetText + " " + source);
infowindow.open(map,marker);
};})(marker,tweetText,source,infoWindow));
currentMarkers.push(marker);
}
}
</script>
<form id="form">
Name (max 10 characters): <input type="text" id="twitterHandle" size="20">
<input type="submit" value="Submit">
</form>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDIMnibDecOLdbDzmCX_IaLQLscdVOGwmA&callback=initMap"
async defer></script>
</body>
</html>