maplibre / maplibre-gl-js

MapLibre GL JS - Interactive vector tile maps in the browser
https://maplibre.org/maplibre-gl-js/docs/
Other
6.74k stars 726 forks source link

Globe - Improve tile management #3887

Open Pheonor opened 8 months ago

Pheonor commented 8 months ago

Rationale

Tile loading mechanism should be updated to work with a Globe projection.

Impact

Load every tile needed to cover the whole Globe with the right resolution.

HarelM commented 8 months ago

Bounty direction: https://github.com/maplibre/maplibre/issues/190

vlarrieu commented 8 months ago

@HarelM Could you assign it to me please ? (On Pheonor account, sorry)

kubapelc commented 5 months ago

@Pheonor Hi, I'm currently doing a lot of changes in my branch that affect how this would be implemented. Since your other PR is nearly finished, I thought I should tell you about this so we can avoid hard to solve merge conflicts :)

I've moved most logic from the Projection interface to the Transform class. Transform is now an abstract class, with implementations for mercator and globe projections. I decided to do this, because Transform is the class already used by MapLibre to do everything related to projecting and unprojecting pixels and coordinates. Transform also already stores the map's center, pitch, bearing, etc., which is all needed for projections.

Transform is also cloneable in MapLibre, and this is used to store the map's state from a given frame, and use it for a longer period of time to do projections. This is used in symbols, and the old Projection interface didn't account for this at all, so the globe symbol implementation was slightly wrong. Moving most projection stuff to Transform fixes this.

I think the abstract transform mightmake implementing better tile management for different projections easier.

You can preview the changes here:

https://github.com/windycom/maplibre-gl-js/blob/kubapelc/globe-vector/src/geo/projection/globe_transform.ts

https://github.com/windycom/maplibre-gl-js/blob/kubapelc/globe-vector/src/geo/transform.ts

I hope to have a PR ready within about two weeks (hopefully).

Pheonor commented 5 months ago

@Pheonor Hi, I'm currently doing a lot of changes in my branch that affect how this would be implemented. Since your other PR is nearly finished, I thought I should tell you about this so we can avoid hard to solve merge conflicts :)

I've moved most logic from the Projection interface to the Transform class. Transform is now an abstract class, with implementations for mercator and globe projections. I decided to do this, because Transform is the class already used by MapLibre to do everything related to projecting and unprojecting pixels and coordinates. Transform also already stores the map's center, pitch, bearing, etc., which is all needed for projections.

Transform is also cloneable in MapLibre, and this is used to store the map's state from a given frame, and use it for a longer period of time to do projections. This is used in symbols, and the old Projection interface didn't account for this at all, so the globe symbol implementation was slightly wrong. Moving most projection stuff to Transform fixes this.

I think the abstract transform mightmake implementing better tile management for different projections easier.

You can preview the changes here:

https://github.com/windycom/maplibre-gl-js/blob/kubapelc/globe-vector/src/geo/projection/globe_transform.ts

https://github.com/windycom/maplibre-gl-js/blob/kubapelc/globe-vector/src/geo/transform.ts

I hope to have a PR ready within about two weeks (hopefully).

Thanks for the information @kubapelc. I already start this issue but I will wait your refactoring.

This is a great change. When I first test the tile improvement, I was facing the problem of update of transform information that are needed by the projection code. Good job !