Perform k-nearest neighbors search with rbush-knn
mainUse rbush-knn to perform k-nearest neighbors (kNN) searches on an existing RBush spatial index. The library implements a depth-first search algorithm using a priority queue to find the closest items to a specific coordinate.
import RBush from 'rbush';
import knn from 'rbush-knn';
const tree = new RBush(); // create RBush tree
tree.load(data); // bulk insert
// return 10 nearest items around point [40, 40]
const neighbors = knn(tree, 40, 40, 10);