Patrick Brosi 4 роки тому
батько
коміт
1270c4ece2
1 змінених файлів з 19 додано та 23 видалено
  1. 19 23
      web/script.js

+ 19 - 23
web/script.js

@@ -4,10 +4,6 @@ mwidths = [1, 1, 1, 1.5, 2, 3, 5, 6, 6, 4, 3, 2];
4 4
 
5 5
 backend = "http://staty.cs.uni-freiburg.de/backend/";
6 6
 
7
-function $(id) {
8
-    return document.getElementById(id);
9
-}
10
-
11 7
 function marker(stat, z) {
12 8
     if (z > 15) {
13 9
         return L.circle(
@@ -166,16 +162,16 @@ function renderStat(stat) {
166 162
 }
167 163
 
168 164
 function openStat(id) {
169
-    var xmlhttp = new XMLHttpRequest();
170
-    xmlhttp.onreadystatechange = function() {
171
-        if (this.readyState == 4 && this.status == 200) {
165
+    window.xmlhttp = new XMLHttpRequest();
166
+    window.xmlhttp.onreadystatechange = function() {
167
+        if (this.readyState == 4 && this.status == 200 && this == window.xmlhttp) {
172 168
             var content = JSON.parse(this.responseText);
173 169
             renderStat(content);
174 170
         }
175 171
     };
176 172
 
177
-    xmlhttp.open("GET", backend + "/stat?id=" + id, true);
178
-    xmlhttp.send();
173
+    window.xmlhttp.open("GET", backend + "/stat?id=" + id, true);
174
+    window.xmlhttp.send();
179 175
 }
180 176
 
181 177
 function renderGroup(grp, ll) {
@@ -235,16 +231,16 @@ function renderGroup(grp, ll) {
235 231
 }
236 232
 
237 233
 function openGroup(id, ll) {
238
-    var xmlhttp = new XMLHttpRequest();
239
-    xmlhttp.onreadystatechange = function() {
240
-        if (this.readyState == 4 && this.status == 200) {
234
+    window.xmlhttp = new XMLHttpRequest();
235
+    window.xmlhttp.onreadystatechange = function() {
236
+        if (this.readyState == 4 && this.status == 200 && this == window.xmlhttp) {
241 237
             var content = JSON.parse(this.responseText);
242 238
             renderGroup(content, ll);
243 239
         }
244 240
     };
245 241
 
246
-    xmlhttp.open("GET", backend + "/group?id=" + id, true);
247
-    xmlhttp.send();
242
+    window.xmlhttp.open("GET", backend + "/group?id=" + id, true);
243
+    window.xmlhttp.send();
248 244
 }
249 245
 
250 246
 function groupHl(id) {
@@ -303,11 +299,11 @@ map.on("moveend", function() {
303 299
 });
304 300
 
305 301
 function render() {
306
-    var xmlhttp = new XMLHttpRequest();
302
+    window.xmlhttp = new XMLHttpRequest();
307 303
 
308 304
     if (map.getZoom() < 11) {
309
-        xmlhttp.onreadystatechange = function() {
310
-            if (this.readyState == 4 && this.status == 200) {
305
+        window.xmlhttp.onreadystatechange = function() {
306
+            if (this.readyState == 4 && this.status == 200 && this == window.xmlhttp) {
311 307
                 var content = JSON.parse(this.responseText);
312 308
 
313 309
                 layer.clearLayers();
@@ -354,11 +350,11 @@ function render() {
354 350
             }
355 351
         };
356 352
 
357
-        xmlhttp.open("GET", backend + "/heatmap?z=" + map.getZoom() + "&bbox=" + [map.getBounds().getSouthWest().lat, map.getBounds().getSouthWest().lng, map.getBounds().getNorthEast().lat, map.getBounds().getNorthEast().lng].join(","), true);
358
-        xmlhttp.send();
353
+        window.xmlhttp.open("GET", backend + "/heatmap?z=" + map.getZoom() + "&bbox=" + [map.getBounds().getSouthWest().lat, map.getBounds().getSouthWest().lng, map.getBounds().getNorthEast().lat, map.getBounds().getNorthEast().lng].join(","), true);
354
+        window.xmlhttp.send();
359 355
     } else {
360
-        xmlhttp.onreadystatechange = function() {
361
-            if (this.readyState == 4 && this.status == 200) {
356
+        window.xmlhttp.onreadystatechange = function() {
357
+            if (this.readyState == 4 && this.status == 200 && this == window.xmlhttp) {
362 358
                 var content = JSON.parse(this.responseText);
363 359
 
364 360
                 layer.clearLayers();
@@ -409,8 +405,8 @@ function render() {
409 405
             }
410 406
         };
411 407
 
412
-        xmlhttp.open("GET", backend + "/map?bbox=" + [map.getBounds().getSouthWest().lat, map.getBounds().getSouthWest().lng, map.getBounds().getNorthEast().lat, map.getBounds().getNorthEast().lng].join(","), true);
413
-        xmlhttp.send();
408
+        window.xmlhttp.open("GET", backend + "/map?bbox=" + [map.getBounds().getSouthWest().lat, map.getBounds().getSouthWest().lng, map.getBounds().getNorthEast().lat, map.getBounds().getNorthEast().lng].join(","), true);
409
+        window.xmlhttp.send();
414 410
     }
415 411
 }
416 412