mapbox / mapbox/mapbox-gl-js

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

Open
#12,431 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/geo/transform.js around line 1424 and reproduce the issue using the linked JSBin with a terrain layer over a mountainous region. Compare getBounds() with the displayed map coverage and evaluate the proposed minimum-elevation change across other projections. Done means the returned bounds cover the full terrain-enabled viewport without breaking other projection behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.