forked from seikur0/PGO-mapscan-opt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
190 lines (170 loc) · 6.91 KB
/
index.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.7, maximum-scale=0.7">
<!--<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />-->
<style type="text/css">
html, body { height: 100%; margin: 0; padding: 0; }
#map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
/////////////////////////////////////////////////////////////////////
var pokdats = {};
var map;
var markers = [];
var spawns = [];
var pokenames;
var LAT_C;
var LNG_C;
var LANGUAGE;
var excludeIDs = [];
var scalesize;
var loadids;
var timenow;
var infowindow;
var iconSize;
var iconOrigin;
var iconAnchor;
var iconScaledSize;
var respath;
var timelefttext;
/////////////////////////////////////////////////////////////////////
function getFile(path, asynch, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", path, asynch);
xhr.onload = function (e) {
if (xhr.readyState === 4 && xhr.status === 200) {
callback(xhr.responseText);
}
};
xhr.send(null);
}
/////////////////////////////////////////////////////////////////////
function refreshData() {
for (var fileN=0;fileN<loadids.length;fileN++){
timenow=Math.round((new Date()).getTime() / 1000);
filenow=respath+"data".concat(loadids[fileN].toString(),".json");
getFile(filenow, false, function(fileData) {
pokdats = JSON.parse(fileData);
// Clear void markers
for (var i = 0; i < markers.length; i++) {
if (markers[i].validTill != 0) {
timeleft = markers[i].validTill-timenow;
if (timeleft <= 0) {
markers[i].setMap(null);
markers[i].validTill = 0;
}else
markers[i].infotext= "<b>"+pokenames[markers[i].id]+"</b><br>"+ timelefttext + Math.floor(timeleft/60) + "m " + (timeleft%60) + "s";
}
}
// Add updated markers
for (var i = 0; i < pokdats.length; i++) {
var p = pokdats[i];
var ban=0;
while (ban<excludeIDs.length && p[0]!=excludeIDs[ban]){ban++;}
var timeleft = p[4]-timenow;
if (ban>=excludeIDs.length&&timeleft>0) {
var cIcon= {
url: respath + "icons/" + p[0] + ".png",
size: iconSize,
origin: iconOrigin,
anchor: iconAnchor,
scaledSize: iconScaledSize
};
var s = 0;
while (s< spawns.length && spawns[s]!=p[1]){s++;}
if (s< spawns.length){
markers[s].infotext = "<b>"+pokenames[p[0]]+"</b><br>"+ timelefttext + Math.floor(timeleft/60) + "m " + (timeleft%60) + "s";
if (markers[s].validTill != p[4]) {
if (markers[s].validTill ==0) {
markers[s].id=p[0];
markers[s].icon = cIcon;
markers[s].setOpacity(1.0);
markers[s].setMap(map);
}
markers[s].validTill = p[4];
}
}else{
var marker = new google.maps.Marker({
map: map,
position: {lat: p[2], lng: p[3]},
optimized: false,
id: p[0],
infotext: "<b>"+pokenames[p[0]]+"</b><br>"+ timelefttext + Math.floor(timeleft/60) + "m " + (timeleft%60) + "s",
validTill: p[4],
spawnID: p[1],
icon: cIcon
});
marker.addListener('click', function() {
infowindow.close();
infowindow.setContent(this.infotext);
infowindow.open(map, this);
});
marker.addListener('dblclick', function() {
if (this.getOpacity()==0.5)
this.setOpacity(1);
else
this.setOpacity(0.5);
});
markers.push(marker);
spawns.push(p[1]);
}
}
}
});
}
anchor=infowindow.get('anchor');
if (anchor!=undefined&&anchor!==null) {
infowindow.setContent(anchor.infotext);
}
}
/////////////////////////////////////////////////////////////////////
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: LAT_C, lng: LNG_C},
zoom: 15,
disableDoubleClickZoom: true
});
getFile(respath+LANGUAGE+".json", false, function(tnames) {
pokenames=JSON.parse(tnames);
});
if (LANGUAGE=="german")
timelefttext = "Zeit übrig: ";
else if (LANGUAGE=="english")
timelefttext = "Time left: ";
infowindow = new google.maps.InfoWindow();
iconSize = new google.maps.Size(scalesize, scalesize);
iconOrigin= new google.maps.Point(0, 0);
iconAnchor= new google.maps.Point(Math.round(scalesize/2), Math.round(scalesize/2));
iconScaledSize= new google.maps.Size(scalesize, scalesize);
refreshData();
setInterval(refreshData, 10000);
google.maps.event.addListener(map, 'click', function(event) {
infowindow.close()
});
}
function initSite() {
getFile("res/usersettings.json", false, function(tsettings) {
var settings=JSON.parse(tsettings);
LAT_C=settings['profiles']['0']['coordinates']['lat'];
LNG_C=settings['profiles']['0']['coordinates']['lng'];
LANGUAGE=settings['language'];
excludeIDs=settings['exclude_ids'];
scalesize = Math.ceil(72*settings['icon_scalefactor']);
loadids = settings['load_ids'];
respath=settings['html_respath'];
document.getElementsByName("viewport").content = "width=device-width, initial-scale="+settings['mobile_scalefactor'].toString()+", maximum-scale="+settings['mobile_scalefactor'].toString();
var script = document.createElement("script");
script.src = "https://maps.googleapis.com/maps/api/js?key="+settings['api_key']+"&libraries=drawing&callback=initMap";
script.async = true;
script.defer = true;
document.body.appendChild(script);
});
}
initSite()
</script>
</body></html>