Skip to content

fix: incorrect distance to tile in globe projection#7234

Open
jtfedd wants to merge 5 commits intomaplibre:mainfrom
jtfedd:fix-globe-tiling-lod
Open

fix: incorrect distance to tile in globe projection#7234
jtfedd wants to merge 5 commits intomaplibre:mainfrom
jtfedd:fix-globe-tiling-lod

Conversation

@jtfedd
Copy link

@jtfedd jtfedd commented Mar 10, 2026

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

Summary

The distance to tiles was not being calculated correctly with globe projection. This would cause high-detail tiles to be loaded all the way to the horizon which looks incorrect and very slow in the browser.

Before After
Screenshot 2026-03-09 at 7 50 47 PM Screenshot 2026-03-08 at 9 56 22 PM

Root Cause

The issue was specifically in calculating the x distance to the tile. The condition for checking whether the camera is to the right of the tile was checking whether the distance to the tile was greater than 1. Since all of the coordinates are in the range [0..1] this condition is always false, and we would fall into the final case which is that the camera is inside the tile, and return a distance of 0. The correct condition is to check whether the camera is to the right of the tile is to check whether the distance from the top-left corner of the tile to the camera position is greater than the width of the tile.

Testing

  • Added additional cases in covering_tiles.test.ts to cover cases where the camera is looking toward the horizon in each major direction in globe projection.
  • To reproduce the issue locally run the following example:
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <link rel='stylesheet' href='./dist/maplibre-gl.css' />
  <script src='./dist/maplibre-gl.js'></script>
  <style>
    body { margin: 0; padding: 0; }
    html, body, #map { height: 100%; }
  </style>
</head>
<body>
<div id="map"></div>
<script>
  const map =
  new maplibregl.Map({
    container: "map",
    zoom: 10,
    pitch: 70,
    bearing: 270,
    maxZoom: 18,
    maxPitch: 85,
    style: 'https://demotiles.maplibre.org/debug-tiles/style.json',
  });

console.log(map.version);

map.on("style.load", () => {
  map.setProjection({ type: "globe" });
});

map.addControl(
  new maplibregl.NavigationControl({
    visualizePitch: true,
    showZoom: true,
    showCompass: true,
  })
);
  
map.addControl(
  new maplibregl.GlobeControl()
);

map.addControl(
  new maplibregl.TerrainControl({
    source: "terrainSource",
    exaggeration: 1,
  })
);

</script>
</body>
</html>

Issues

Fixes #7219

@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.71%. Comparing base (568dccd) to head (0af22a0).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7234   +/-   ##
=======================================
  Coverage   92.71%   92.71%           
=======================================
  Files         289      289           
  Lines       24074    24074           
  Branches     5112     5112           
=======================================
+ Hits        22320    22321    +1     
+ Misses       1754     1753    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Globe projection calculates lod incorrectly when camera has bearing 270

1 participant