Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions routes/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down