diff --git a/routes/search.go b/routes/search.go index ae8f4cd..9fabd45 100644 --- a/routes/search.go +++ b/routes/search.go @@ -17,6 +17,8 @@ import ( "github.com/paulmach/orb/geojson" ) +const UNITS_BOUNDS_EXPANSION = 100 + type SearchResponse struct { Results []spatialindex.CodePoint `json:"results"` Attribution []string `json:"attribution"` @@ -62,6 +64,10 @@ func PolygonSearch(spatialIndex *spatialindex.SpatialIndex, cache *memoize.Memoi tooBig := isTooBig(bbox) target := map[bool]string{true: "districts", false: "units"}[tooBig] + if target == "units" { + expandBounds(&bbox, UNITS_BOUNDS_EXPANSION) + } + requested := make(map[string]struct{}, 100) districts := make(map[string]struct{}, 20) @@ -110,6 +116,14 @@ func PolygonSearch(spatialIndex *spatialindex.SpatialIndex, cache *memoize.Memoi } } +func expandBounds(bbox *[]uint32, extendBy uint32) { + b := *bbox + b[0] -= extendBy // min_easting + b[1] -= extendBy // min_northing + b[2] += extendBy // max_easting + b[3] += extendBy // max_northing +} + func parseBBox(bboxStr string) ([]uint32, error) { bboxParts := strings.Split(bboxStr, ",") if len(bboxParts) != 4 {