-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (65 loc) · 1.69 KB
/
app.js
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
var L = require('leaflet');
var omnivore = require('leaflet-omnivore');
var getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
var map = L.map('map');
var layer = Tangram.leafletLayer({
scene: 'scene.yaml'
})
layer.addTo(map);
map.setView([23.5515, 87.2963], 14);
var oldFile=[];
setInterval(function(){
getJSON(window.location.protocol + '//'+ window.location.hostname + ':3030',
function(err, data) {
if (err !== null) {
alert('Something went wrong: ' + err);
}
else {
var file_arr = Object.values(data);
//console.log(oldFile);
//console.log(file_arr);
var flag = false;
if(oldFile.length!==file_arr.length)
flag=true;
if(oldFile.length === file_arr.length){
for(var i=0;i<oldFile.length;i++){
if(oldFile[i]!==file_arr[i]){
flag=true;
}
}
}
//console.log(flag);
if(flag) {
map.eachLayer(function (layer) {
map.remove(layer);
});
map = L.map('map');
layer = Tangram.leafletLayer({
scene: 'scene.yaml'
})
layer.addTo(map);
map.setView([23.5515, 87.2963], 14);
for(var i=0;i<file_arr.length;i++) {
if(file_arr[i]!=null)
{
omnivore.kml('./kml-files/'+file_arr[i]).addTo(map);
}
}
oldFile=file_arr;
}
}
});
},1000);