-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
36 lines (31 loc) · 1007 Bytes
/
index.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
var coordEach = require('@turf/meta').coordEach;
module.exports = {
addElevation: function(geojson, elevationProvider, cb, nodata) {
var waiting = 0,
allProcessed = false;
coordEach(geojson, function(coords) {
waiting++;
elevationProvider.getElevation([coords[1], coords[0]], function(err, elevation) {
if (err) {
if (nodata != null) {
coords[2] = nodata;
waiting--;
} else {
cb(err);
waiting = -1;
}
} else {
coords[2] = elevation;
waiting--;
}
if (allProcessed && waiting === 0) {
cb(undefined, geojson);
}
});
});
allProcessed = true;
if (waiting === 0) {
cb(undefined, geojson);
}
}
};