bb01e9a06c
## Summary - **ADS-B & AIS:** OpenSky and AISStream OSINT feeds upsert into the CoT store; tactical tracks still arrive via adsbcot/aiscot on `:8089`. Map clients subscribe via `GET /api/cot/stream` (SSE) with viewport bbox filtering and Air / Surface / Team layer toggles. - **ALPR (Flock/OSM):** Toggleable license-plate reader layer sourced from OpenStreetMap, with SQLite cache, Overpass fallback, tiled viewport fetching, and clustered markers with direction cones. - **Map performance:** Ring-based tile selection (fixes zoom-out crash), immutable tile cache, incremental marker sync, split cluster load/query, and padded SSE bbox to reduce reconnect churn. ## Docs - `docs/tracking.md` — ADS-B/AIS accuracy tiers, freshness, self-hosted receivers, optional OSINT API keys - `docs/map-and-cameras.md` — ALPR layer and map behavior updates --------- Co-authored-by: Madison Grubb <madison@elastiflow.com> Reviewed-on: #36
56 lines
2.4 KiB
JavaScript
56 lines
2.4 KiB
JavaScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { createClusterIndex } from '../../app/utils/mapCluster.js'
|
|
import { clearFeatureMarkers, syncFeatureMarkers } from '../../app/utils/mapMarkerSync.js'
|
|
import { bboxFetchKey, tilesNearCenter } from '../../app/utils/alprViewport.js'
|
|
|
|
describe('mapCluster', () => {
|
|
it('loads once and queries by viewport', () => {
|
|
const index = createClusterIndex({ radius: 50, maxZoom: 14, minPoints: 2 })
|
|
const features = Array.from({ length: 20 }, (_, i) => ({
|
|
type: 'Feature',
|
|
geometry: { type: 'Point', coordinates: [-122.4 + i * 0.01, 37.7] },
|
|
properties: { id: i },
|
|
}))
|
|
index.load(features)
|
|
const zoomedOut = index.query({ west: -123, south: 37, east: -122, north: 38, zoom: 6 })
|
|
expect(zoomedOut.some(f => f.properties?.cluster)).toBe(true)
|
|
const zoomedIn = index.query({ west: -123, south: 37, east: -122, north: 38, zoom: 15 })
|
|
expect(zoomedIn).toHaveLength(20)
|
|
})
|
|
})
|
|
|
|
describe('mapMarkerSync', () => {
|
|
it('reuses markers by key', () => {
|
|
const layer = {
|
|
_layers: [],
|
|
addLayer(m) { this._layers.push(m) },
|
|
removeLayer(m) { this._layers = this._layers.filter(x => x !== m) },
|
|
}
|
|
const create = vi.fn(f => ({ id: f.properties.id }))
|
|
const update = vi.fn()
|
|
const opts = { keyFor: f => f.properties.id, create, update }
|
|
const pt = (id, lng, lat) => ({ type: 'Feature', geometry: { type: 'Point', coordinates: [lng, lat] }, properties: { id } })
|
|
|
|
syncFeatureMarkers(layer, [pt(1, -122, 37)], opts)
|
|
syncFeatureMarkers(layer, [pt(1, -121.9, 37.1)], opts)
|
|
expect(create).toHaveBeenCalledTimes(1)
|
|
expect(update).toHaveBeenCalledTimes(1)
|
|
clearFeatureMarkers(layer)
|
|
expect(layer._layers).toHaveLength(0)
|
|
})
|
|
})
|
|
|
|
describe('alprViewport', () => {
|
|
it('selects nearby tiles without scanning the world', () => {
|
|
const world = { south: -85, west: -180, north: 85, east: 180 }
|
|
expect(tilesNearCenter(world, 16)).toHaveLength(16)
|
|
expect(tilesNearCenter(world, 1)[0]).toEqual({ south: 0, west: 0, north: 0.5, east: 0.5 })
|
|
})
|
|
|
|
it('coarsens fetch keys when zoomed out', () => {
|
|
const bounds = { south: 37.01, west: -122.51, north: 37.99, east: -122.01, zoom: 6 }
|
|
expect(bboxFetchKey(bounds)).toBe(bboxFetchKey({ ...bounds, south: bounds.south + 0.05 }))
|
|
expect(bboxFetchKey({ ...bounds, zoom: 14 })).not.toBe(bboxFetchKey(bounds))
|
|
})
|
|
})
|