2

I'm fairly new to maplibre/mapbox. I've about 40,000 polygons in my PostGIS database. That's just too much data to load it all at once into the maplibre map as a geojson source when the webapp starts. Thus I implemented a simple rest server which returns the polygons compiled into X/Y/Z MVT Vector tiles, so I can use it as a "vector" source in my maplibre style file. This works fine, polygons start showing up at zoom-level 10.

The question is... for the sake of performance and server load I would like to reduce the amount of tile requests. At the moment when I change the zoom level from 10 to 11, maplibre requests new tiles, which actually isn't necessary, as all needed data already was included in the tile it got for zoom-level 10. Is there a way to tell maplibre to request tiles not for the current zoom-level, but for the higher zoom level instead? e.g. instead of requesting 1/1/12, request 1/1/10.

In other words, I would like to tell maplibre to always use the data from the z10 tile, even for greater zoom levels. And to load the z10 tile if it hasn't been loaded yet.

Thanks

Humppakäräjät
  • 1,156
  • 2
  • 13
  • 17

1 Answers1

2

I may be misinterpreting your question, but yes, you can tell the client library to never request tiles above zoom 10, and always to overzoom them, by setting maxzoom on your source:

map.addSource('polys', { type: 'vector', /*...*/, maxzoom: 10 });
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
  • Thank you for pointing me to the right direction Steve. I also had to add `minzoom:10` to the source as maplibre somehow still requested a few z11 and z12 tiles on startup. – Humppakäräjät Oct 31 '22 at 09:41
  • I also had to add the `cache-control max-age=3600` header to my MVT rest service to make the web-browser start caching the tiles. I assume that maplibre does not has a built in logic that prevents re-requesting same tiles over and over again. Could you please add `minzoom` and a short note about the caching to your answer? I'll then mark it as accepted answer. Thanks! – Humppakäräjät Oct 31 '22 at 09:46
  • I can't see why minzoom would be required. And I don't think cache parameters are relevant to the core question. – Steve Bennett Oct 31 '22 at 10:18
  • With only `maxzoom:10` being present in the source definition maplibre occasionally still requested tiles for other zoomlevels but 10. After additionally adding `minzoom:10` to the source definition maplibre stopped doing that and only requested z10 tiles as required. You are right the cache-control stuff is relevant for my use case, but not for the question. Thanks again. – Humppakäräjät Oct 31 '22 at 10:26