question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Excessive vector tile requests with modified tileUrlFunction

See original GitHub issue

Describe the bug I am using a modified tileUrlFunction to request vector tiles from variable paths depending on the current zoom level and context (e.g. UI selection). However, it seems that vector tiles are requested multiple times in this setup. This can be seen by returning the values calculated within the tileUrlFunction to the console. It is also noticeable visually: On zoom, tiles from several paths are loaded until they are overwritten by the correct tile at last. I suspect this might be one reason for the poor performance I’m experiencing when using vector tiles (cf. my question at GIS Stackexchange).

Using the same tileUrlFunction with raster tiles works as expected, requesting each tile only once.

To Reproduce Steps to reproduce the behavior:

  1. Use a modified tileUrlFunction to request vector tiles depending on current zoom level and context. At each call of the function, output the parameters of the requested tile to the console.
var selectedMode = ...;
function getVectorTilePath() { ... }

function loadTiles(tileCoordinate) {
    const z = tileCoordinate[0];
    const x = tileCoordinate[1];
    const y = tileCoordinate[2];

    var path = getVectorTilePath(z, selectedMode);

    console.log("z:", z, "x:", x, "y:", y, "path:", path);

    return "mytileserver/"
              + path
              + "/" + z + "/" + x + "/" + y
              + ".pbf";
    }
	
var vt = new VectorTileLayer({
              source: new VectorTileSource({
                format: new MVT(),
                tileGrid: ...,
                tileUrlFunction: loadTiles,
                zDirection: 0,
                transition: 0,
          }),
          preload: 0,
          useInterimTilesOnError: false,
          style: ...,
})	
	

var map = new Map({
    target: 'map',
    loadTilesWhileAnimating: true,
    loadTilesWhileInteracting: true,
    projection: ...,
    layers: [ vt ],
    view: ...,
});
  1. The output of the console (after a single zoom step) indicates that tiles are requested multiple times. Tiles might be excessively requested with a different path attribute (see above). Also, completely identical tiles seem to be requested multiple times.
z: 3 x: 11 y: 2 path: path1 
z: 3 x: 10 y: 2 path: path1 
z: 3 x: 11 y: 2 path: path1  
z: 3 x: 10 y: 2 path: path1 
z: 2 x: 5 y: 0 path: path0 
z: 1 x: 2 y: 0 path: path0
z: 2 x: 5 y: 0 path: path0
z: 3 x: 11 y: 2 path: path1 
z: 1 x: 2 y: 0 z: 1 path: path0
z: 3 x: 11 y: 2 z: 3 path: path1

This is, in principle, what the output looks like, path0 representing tiles usually requested at lower zoom levels z than those with path1. (The console output is much larger but I have modified it so that duplicates are better visible). When I use the same function with raster tiles, it works as intended without duplicate requests.

Expected behavior On an interaction with the map, request each vector tile only once and using the correct path only.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ahocevarcommented, Mar 24, 2021

Thanks for your continued effort on this. Looks like there is a bug indeed. I have a rough idea where it could come from - the getSourceTiles() function in ol/VectorRenderTile.

I won’t be able to fix this before May, so if someone else wants to take a look, a pull request would be much appreciated.

1reaction
ahocevarcommented, Mar 23, 2021

I think what you’re observing is not related to the custom tileUrlFunction. I’m not sure about the reason for the repeated requests for the same tile, but the high amount of requests for lower resolution tiles might be reduced by #12137.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass viewparams with vector tile request using open ...
A WMTS url can usually be constructed using {x} {y} {z} placeholders url: 'http://localhost:8080/geoserver/gwc/service/wmts?
Read more >
maplibre reduce xyz vector tile requests - Stack Overflow
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...
Read more >
Vector tiles tutorial — GeoServer 2.23.x User Manual
This tutorial will show how to use the GeoServer vector tiles output. ... to show off the capabilities, though with slight modifications, any...
Read more >
FastAPI – Vector Tiles with Autorization - GIS • OPS
Learn how to build a vector tile server with built-in authorization ... get that information from the database with every tile request.
Read more >
Advanced Mapbox Vector Tiles - OpenLayers
A vector tiles map which reuses the same source tiles for subsequent zoom levels to ... 3, 5, 7, 9, 11, 13, 15....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found