-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (26 loc) · 870 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
const request = require('request-promise');
const turf = require('@turf/turf');
module.exports = (url, options) => {
const opts = { json: true };
return request(url, opts, (err, res, body) => {
return turf.truncate(body);
})
.then(truncated => {
return turf.simplify(truncated, options.tolerance, options.highQuality);
})
.then(simplified => {
const screenedProperties = options.keepProperties;
const filtered = simplified.features.map(function (feature) {
const result = {};
Object.keys(feature.properties).forEach(function (key) {
if (screenedProperties.includes(key)) {
result[key] = feature.properties[key];
}
});
feature.properties = result;
return feature;
});
simplified.features = filtered;
return simplified.features;
});
};