Patrick Brosi 4 years ago
parent
commit
1270c4ece2
1 changed files with 19 additions and 23 deletions
  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
 backend = "http://staty.cs.uni-freiburg.de/backend/";
5
 backend = "http://staty.cs.uni-freiburg.de/backend/";
6
 
6
 
7
-function $(id) {
8
-    return document.getElementById(id);
9
-}
10
-
11
 function marker(stat, z) {
7
 function marker(stat, z) {
12
     if (z > 15) {
8
     if (z > 15) {
13
         return L.circle(
9
         return L.circle(
@@ -166,16 +162,16 @@ function renderStat(stat) {
166
 }
162
 }
167
 
163
 
168
 function openStat(id) {
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
             var content = JSON.parse(this.responseText);
168
             var content = JSON.parse(this.responseText);
173
             renderStat(content);
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
 function renderGroup(grp, ll) {
177
 function renderGroup(grp, ll) {
@@ -235,16 +231,16 @@ function renderGroup(grp, ll) {
235
 }
231
 }
236
 
232
 
237
 function openGroup(id, ll) {
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
             var content = JSON.parse(this.responseText);
237
             var content = JSON.parse(this.responseText);
242
             renderGroup(content, ll);
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
 function groupHl(id) {
246
 function groupHl(id) {
@@ -303,11 +299,11 @@ map.on("moveend", function() {
303
 });
299
 });
304
 
300
 
305
 function render() {
301
 function render() {
306
-    var xmlhttp = new XMLHttpRequest();
302
+    window.xmlhttp = new XMLHttpRequest();
307
 
303
 
308
     if (map.getZoom() < 11) {
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
                 var content = JSON.parse(this.responseText);
307
                 var content = JSON.parse(this.responseText);
312
 
308
 
313
                 layer.clearLayers();
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
     } else {
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
                 var content = JSON.parse(this.responseText);
358
                 var content = JSON.parse(this.responseText);
363
 
359
 
364
                 layer.clearLayers();
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