Skip to main content

Function: _sortItemsByDistanceFromViewportCenter()

_sortItemsByDistanceFromViewportCenter<T>(items, viewport, getCenter): T[]

Defined in: packages/deck.gl-raster/src/raster-tileset/sort-by-distance.ts:75

Sort items in place by ascending distance of each item's center from the viewport's bounds-midpoint, so loads initiate center-out. Returns the same array reference.

The reference point is the midpoint of viewport.getBounds(), which is always WGS84 [minLon, minLat, maxLon, maxLat] regardless of viewport type (Mercator, Globe, etc.). getCenter must return each item's center in the same WGS84 space so the comparison is meaningful — callers working in a projected CRS should run their tile/source centers through the descriptor's projectTo4326 before returning.

getCenter is called exactly once per item; see sortByDistanceFromPoint for the underlying perf contract and the items.length < 2 short-circuit. Caller-side short-circuits such as length <= maxRequests should still be applied before invoking this helper when they would skip useful work entirely.

Type Parameters

T

T

Parameters

items

T[]

viewport

Viewport

getCenter

(item) => readonly [number, number]

Returns

T[]