This document describes the spatial calculations, clustering mechanics, and network hydration strategies utilized within the Geospatial Explorer and WiGLE map panels.
- Materialized Views:
app.api_network_explorer_mv: Powers the explorer grid by pre-calculating geocoded values, threat scores, and lists of adjacent sibling BSSIDs (sibling_bssids).app.mv_sibling_groups: Computes and aggregates connected components groupings to display sibling clusters on the map.
- Query Path:
- React hook
useSiblingLinkscallsnetworkApi.getNetworkSiblingLinks(anchorBssid)andnetworkApi.getNetworkSiblingLinksBatch(bssids)to fetch link coordinates. - Sibling missing network details are loaded in batch chunks of 100 via
networkApi.getNetworksByBssids(chunkBssids).
- React hook
- Precomputed Adjacency:
- Sibling hydration uses a fallback strategy inside
siblingGroupGraph.ts. If a network already containssibling_bssidsin the loaded list,buildAdjacencyFromPrecomputedbuilds adjacent link segments locally to bypass redundant API lookup requests.
- Sibling hydration uses a fallback strategy inside
- Hooks:
useNearestAgencies(bssid | bssids): Searches within a 250m radius around BSSID location coords.useNearestCourthouses(bssids): Searches within a 250m radius.
- Clustering Utility (
mergeNearestPlaces):- Merges matching arrays of
AgencyandCourthouseMatchobjects into a list ofNearestPlaceClusterobjects keyed bycluster_id. - Centroid Logic: Centroid lat/lon values prefer the agency cluster location; if missing, they fall back to the courthouse cluster location.
- See mergeNearestPlaces.ts for details.
- Sorting Order: Clusters are sorted numerically by
clusterIdascending. Synthetic or fallback IDs are placed at the end of the collection. - Null Matches: If a cluster contains an agency but no courthouse inside the search radius, the courthouse fields are returned as
undefined.
- Merges matching arrays of
- Symmetry & Keys:
- Key generators like
useNearestAgenciesbuild a stable BSSID dependency key using[...bssid].sort().join(',')to avoid mutating the caller's array.
- Key generators like
- Cluster Merging Logic:
tests/unit/utils/mergeNearestPlaces.test.ts - Dependency Key Mutation Guard:
tests/unit/useNearestAgencies.test.ts