* Pick a compact longitude range for `fitbounds`-style auto-framing when the * data straddles the antimeridian (±180°). * * Longitude is cyclic, so the naive [min, max] range used by the autorange * machinery can include a large empty span when points sit on both sides of * ±180° (e.g. lon = [1
(lons)
| 417 | * more compact, otherwise null (caller keeps the autorange result). |
| 418 | */ |
| 419 | function getFitboundsLonRange(lons) { |
| 420 | const sorted = lons.filter(isFinite).sort((a, b) => a - b); |
| 421 | if (sorted.length < 2) return null; |
| 422 | |
| 423 | const n = sorted.length; |
| 424 | const naiveSpan = sorted[n - 1] - sorted[0]; |
| 425 | // Data already wraps the whole globe; there is nothing to compact. |
| 426 | if (naiveSpan >= 360) return null; |
| 427 | |
| 428 | // Widest gap between consecutive longitudes. |
| 429 | let maxGap = -Infinity; |
| 430 | let gapStart = -1; |
| 431 | for (let i = 0; i < n - 1; i++) { |
| 432 | const gap = sorted[i + 1] - sorted[i]; |
| 433 | if (gap > maxGap) { |
| 434 | maxGap = gap; |
| 435 | gapStart = i; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | // Only worth wrapping when an interior gap is wider than the gap that the |
| 440 | // naive [min, max] range already leaves open across the antimeridian. |
| 441 | const antimeridianGap = 360 - naiveSpan; |
| 442 | if (maxGap <= antimeridianGap) return null; |
| 443 | |
| 444 | return [sorted[gapStart + 1], sorted[gapStart] + ANTIMERIDIAN_LON_SHIFT]; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Return an unwrapped version of a `[lon0, lon1]` longitude range. |
no outgoing calls
no test coverage detected
searching dependent graphs…