How can I set max zoom available on a tile server?

Viewed 148

Question:

Let's say my tile server has only tile images for zooms 8, 9, and 10.

When the client starts with zoom 11, I want Openlayers to fetch zoom 10 (maximum available zoom on the server) and stretch the tile in the client. So, I want the user to see something, albeit lower quality, even on zoom 11.

Is this possible?

More explanation:

(More explanation follows, in case the question didn't make sense)

By default, if the Javascript client starts fresh with zoom 11, nothing is shown (bad), but if the client starts with zoom 10, and then zooms in to 11 the already-fetched tiles of zoom 10 are stretched and shown (much better) while still attempting to get zoom 11 tiles and getting 404 from the server.

My best attempt was setting the tileLoadFunction option, because it is given the [z, x, y] values and can apparently set the src of the tile image. I say "apparently" because I haven't tried it. The problem is that decreasing the value of z is not enough, I have to calculate the [x, y] for the new z as well, which is complicated and I think I should avoid doing it manually.

Here is the code for the layer:

let heatmapLayer = new TileLayer({
  visible: true,
  opacity: 0.75,
  source: new XYZ({
    tileSize: [512, 512],
    url: "http://myserver/heatmap-z{z}-x{x}-y{y}.png",
  }),
});
1 Answers

You can specify the min and max zoom levels the tiles are served at

  source: new XYZ({
    tileSize: [512, 512],
    url: "http://myserver/heatmap-z{z}-x{x}-y{y}.png",
    minZoom: 8,
    maxZoom: 10,
  }),

For other resolutions the view will scale tiles up or down

Related