-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscripts.js
More file actions
56 lines (51 loc) · 1.65 KB
/
scripts.js
File metadata and controls
56 lines (51 loc) · 1.65 KB
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
var file
function getFile(fn){
$.get(fn, function(data) {
var lines = data.split("\n");
$.each(lines, function(n, elem) {
try {
let json = JSON.parse(elem)
if (typeof json['name'] !== 'undefined' && typeof json['geometry']['coordinates'][0] !== 'undefined' && json["osm_type"] == "way") {
// addLocation(json['name'], json['geometry']['coordinates'][0])
addLocationV2(json['name'], json['geometry']['coordinates'][0])
}
} catch (e) {}
});
});
}
function addLocation(name, coordinates) {
firebase.database().ref('/locations/' + name).set({
name: name,
})
for (let i = 0; i < coordinates[0].length; i++) {
firebase.database().ref('/locations/' + name + '/geometry/coordinates/' + i).set({
lat: coordinates[0][i][0],
long: coordinates[0][i][1]
})
// console.log(i)
}
}
function addLocationV2(name, coordinates) {
console.log (name);
var c = []
c['coordinates'] = []
for (let i = 0; i < coordinates[0].length; i++) {
var t = []
t['lat'] = coordinates[0][i][1]
t['long'] = coordinates[0][i][0]
c['coordinates'].push(t)
}
firebase.database().ref('/locations/' + name).set({
name: name,
geometry: c
})
}
function getFiles () {
for (let i = 0; i <= 13; ++i) {
file = "https://raw.githubusercontent.com/Noverdose/Preventanyl-Server/develop/canada/admin_level_" + i + ".geojson";
getFile (file);
}
}
firebase.database().ref('/locations/').set(null)
// getFile(file)
getFiles();