Updates
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
const SpatialIndex = require('../index.js')
|
||||
const { setTimeout } = require('bare-timers')
|
||||
|
||||
async function main () {
|
||||
const index = new SpatialIndex({
|
||||
storageDir: './spatial-demo-storage'
|
||||
})
|
||||
|
||||
await index.ready()
|
||||
console.log('Spatial index ready')
|
||||
|
||||
// Simulate inserting locations
|
||||
await index.insert('drone-1', 500, 600, { type: 'drone', battery: 87 })
|
||||
await index.insert('vehicle-42', 1200, 800, { type: 'vehicle', speed: 45 })
|
||||
|
||||
const nearby = await index.rangeQuery(400, 500, 1000, 1000)
|
||||
console.log('Nearby assets:', nearby.length)
|
||||
|
||||
const closest = await index.nearestNeighbor(600, 700, 2)
|
||||
console.log('Closest:', closest.map(p => p.id))
|
||||
|
||||
// Keep alive for demo
|
||||
await new Promise(r => setTimeout(r, 5000))
|
||||
await index.close()
|
||||
console.log('Demo complete')
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
Reference in New Issue
Block a user