mapbox/mapbox-gl-js

map.getBounds() not providing full coverage when terrain enabled

ted-piotrowski opened this issue · 1 comments

mapbox-gl-js version: Latest

browser: Firefox

Steps to Trigger Behavior

  1. Create map with terrain layer
  2. Center map on "mountainous" region, wait for terrain to load, and call getBounds()

Link to Demonstration

Creating a GeoJSON Polygon using map.getBounds() coordinates does not cover the entire map (see example and screenshots)

https://jsbin.com/lekonabole/edit?html,output

Expected Behavior

Screen Shot 2022-12-01 at 8 03 32 AM

Actual Behavior

Screen Shot 2022-12-01 at 8 02 57 AM

Potential solution

It appears that changing https://github.com/mapbox/mapbox-gl-js/blob/main/src/geo/transform.js#L1424 from

let tl = this.pointCoordinate(topLeft, min);
let tr = this.pointCoordinate(topRight, min);
const br = this.pointCoordinate(bottomRight, max);
const bl = this.pointCoordinate(bottomLeft, max);

to

let tl = this.pointCoordinate(topLeft, min);
let tr = this.pointCoordinate(topRight, min);
const br = this.pointCoordinate(bottomRight, min);
const bl = this.pointCoordinate(bottomLeft, min);

fixes the issue but I'm not sure if it affects other projections, etc. Just thought I'd offer it as a potential starting point.

any news on this?