const kd = require('k-d-tree')
const data = new Array(1000)
.fill()
.map(() => ({
type: "Point",
coordinates: [Math.random(), Math.random()]
}))
const distFn = (a, b) => Math.pow(a.coordinates[0] - b.coordinates[0], 2) + Math.pow(a.coordinates[1] - b.coordinates[1], 2)
const tree = new kd(data, distFn)
const point = { type: "Point", coordinates: [0.5, 0.5] }
const maxNeighbors = 10
const maxDist = 0.15
const neighbors = tree.nearest(point, maxNeighbors, maxDist)
// neighbors: [[neighbor, distance], [...]]