render vector tiles offline, or render vector tiles to raster for later offline use?
My desktop application has an offline tiles mode. The user can pre-download tiles in a given area (such as a city, down to a certain zoom level) and use these tiles later when they are not connected online. Previously, I was able to download Esri's raster files for streets and satellite (world imagery), and store these tiles in a database for later use. Now that the street tiles are vector, I'm trying to figure out the best way to achieve the same result. One way could be to download individual .pbf files, save them in the database, and then serve them from localhost, using a cached version of the style .json, with the URL modified for localhost (that is the sources->esri->url value https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer/ would be modified to read the .pbf files from localhost, and I would serve them from my database storage. However, I'm dubious about two other URLs in the style json:
"sprite": "https://cdn.arcgis.com/sharing/rest/content/items/de26a3cf4cc9451298ea173c4b324736/resources/styles/../sprites/sprite",
"glyphs": "https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer/resources/fonts/{fontstack}/{range}.pbf",
I'm not sure if I could fake those.
The other approach would be that, at tile download/storage time, I could render each tile (say, on an open layers canvas of size 256x256), and then grab those pixels as a .png or .jpg to save in the database.
Can you tell if either of those approaches sounds reasonable? For the second idea of rendering to raster at download time, can you tell me if there's an olms API to render a tile to a raster (or SVG), which would be more direct than actually rendering the tile on a map layer?
In my experience, the easiest way to achieve a sound offline capability without having to write application code for the offline scenario is to use a service worker that caches responses of the tile server you're using. Then all you need to do is trigger loads of the tiles of the area you want to provide offline (use OpenLayers's TileGrid API), and you're done. You can use Workbox with a Network First strategy: https://developer.chrome.com/docs/workbox/modules/workbox-strategies#network_first_network_falling_back_to_cache.
Thanks. My application already has a lot of infrastructure for managing its cache of tiles, and querying that cache to present the set of downloaded tiles to the user in a certain way. So if you had to write code to render a vector tile to a raster tile for saving, how would you approach it?
For the resources linked from the style.json, you can specify the transformRequest option to map the request in the style file to your local, cached resource.