-
Notifications
You must be signed in to change notification settings - Fork 2
/
lowestLevel.js
49 lines (46 loc) · 1.26 KB
/
lowestLevel.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
if(!zoom || !input) {
print("You didn't define the arguments: zoom, input");
}
var output = "level" + zoom;
var map = function() {
var c = this.value.geo.coordinates;
var tile = latLonToGoogleTile(c[0], c[1], zoom);
var key = "" + tile[0] + "," + tile[1];
emit(key, { count: 1, geo: c, id: this._id} );
};
var reduce = function(key, values) {
var result = {
count: 0,
geo: values[0].geo,
id: values[0]._id,
};
for (var i = 0; i < values.length; ++i) {
result.count += values[i].count;
}
return result;
};
/*
var finalize = function(key, value) {
return {
total: value,
counts: [value],
res: 1,
};
}
*/
if (db[input].count() == 0) {
print("Input collection (" + db[input] + ") is empty.");
}
else {
print("Input collection (" + input + ") pre-count: " + db[input].count());
print("Output collection (" + output + ") pre-count: " + db[output].count());
db[input].mapReduce(map, reduce, {
out: output,
//finalize: finalize,
scope: {
zoom: zoom
}
});
print("Output collection (" + output + ") post-count: " + db[output].count());
print("Input collection (" + input + ") post-count: " + db[input].count());
}