forked from DenisCarriere/geojson-rbush
-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.ts
38 lines (29 loc) · 917 Bytes
/
types.ts
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
38
import { point, polygon, featureCollection, Point, Polygon } from '@turf/helpers'
import { BBox } from 'geojson'
import rbush from './'
// Fixtures
const bbox: BBox = [-180, -90, 180, 90]
const pt = point([0, 0])
const points = featureCollection([pt, pt])
const poly = polygon([[[0, 0], [1, 1], [1, 1], [0, 0]]])
const polygons = featureCollection([poly, poly])
// Initialize GeoJSON RBush Tree
const tree = rbush<Point | Polygon>()
// Load Tree with a FeatureCollection
tree.load(points);
tree.load(polygons);
// Insert by Feature
tree.insert(pt)
tree.insert(poly)
// Find All (returns FeatureCollection)
const all = tree.all()
// Search by Feature (returns FeatureCollection)
const search = tree.search(poly)
// Collides by Feature (returns FeatureCollection)
const collides = tree.collides(poly)
// Remove by Feature
tree.remove(pt)
tree.remove(poly)
// BBox support
tree.search(bbox)
tree.collides(bbox)