-
Notifications
You must be signed in to change notification settings - Fork 52
/
index.js
37 lines (32 loc) · 892 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
37
var turf = require('turf')
var flatten = require('lodash.flatten')
var data = require('./data')
module.exports = function boundaries (options) {
var dataset = options.dataset
var long = options.long
var lat = options.lat
var point = turf.point([long, lat])
var collection = {
type: 'FeatureCollection',
features: []
}
collection.features = flatten(Object.keys(data).map(function (key) {
return data[key].features
.filter(function (boundary) {
if (dataset) {
if (key == dataset) return boundary
} else {
return boundary
}
})
.filter(function (boundary) {
return turf.inside(point, boundary)
})
.map(function (boundary) {
boundary.properties = boundary.properties || {}
boundary.properties.dataset = key
return boundary
})
}))
return collection
}