nitaliano / react-native-mapbox-gl

A Mapbox GL react native module for creating custom maps
Other
2.16k stars 699 forks source link

Functionality Similar to OpenLayers tileLoadFunction #1611

Closed jasonash closed 5 years ago

jasonash commented 5 years ago

I’m in the process of helping to migrate a project from Angular-Ionic/OpenLayers to React-Native/React-Native-Mapbox-GL and I’ve run into a roadblock with respect to loading dynamic tiles.

In my OpenLayers implementation, I am using OL’s tileLoadFunction to load tiles based on their availablilty. My tileLoadFunction basically looks for the tile specified on the local file system, and if it doesn’t exist it looks for the zoom level just above, and if that tile doesn’t exist, it looks for the zoom level just above that, etc… This allows me to download tiles for offline use and to limit the number of tiles I need to keep outside the main area of interest. When a user pans far away from their initial area of interest, there are still tiles being displayed, but they are quite pixelated due to the fact that they actually come from several zoom levels above. This is acceptable, as it only aids in letting the user see where they are on the map.

My question is how to accomplish something similar with React-Native-Mapbox-GL. Is there functionality similar to OL’s tileLoadFunction that would let me intercept the tile request and alter it according to my own ruleset? Can anyone recommend a strategy that might come close to duplicating OL’s functionality?

kristfal commented 5 years ago

Yes. The way you do this is to download a large area “base map”, for let’s say z0 to z6 and then download individual offline packs for smaller areas for z7 to z14 or whatever you need.

The SKD then handles the rest and picks up the best tiles available for any area you view.