I am loading a lot of vector tile layers onto my OpenLayers (v.9) map and I'm trying to get restrict the extent of the tiles it tries to load in order to suppress 404 errors in the console, but I'm still getting a few.
I'm defining my VectorTileLayer like this:
const vtSrc = createVectorTileSource(wrkspaceName, layerName, idField, featureType); const mvt = new VectorTileLayer({ opacity: 1, declutter: true, extent: vtSrc.getTileGrid().getExtent(), source: vtSrc, style: createStyleFunc(layerName, geomType, isAOI, fillColor), properties: { name: layerName, isAOI: isAOI }, zIndex: 1, }); For reference this is how I create the VectorTileSource:
export const createVectorTileSource = ( wrkspaceName: string, layerName: string, idField: string, featureType?: string ) => { const vts = new VectorTileSource({ url: 'https://mydomain.com/geoserver/gwc/service/tms/1.0.0/' + wrkspaceName + '%3A' + layerName + '@EPSG%3A' + '900913' + '@pbf/{z}/{x}/{-y}.pbf', format: new MVT({ featureClass: featureType == 'feature' ? Feature : RenderFeature, idProperty: idField, }), }); return vts; }; My OpenLayers map uses the default EPSG 3857 projection and my GeoServer layers are being served with EPSG 900913 tiles (tile size [512, 512]). When I print the tilegrid extent of this layer to the console, I get these coordinates:
[-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244] That compares to the whole 900913 gridset in GeoServer: 
I can confirm that by plotting the coordinates in bbox finder. Obviously, that's not the extent of my layer but rather the extent of the whole gridset. When I get the bbox of the layer out of GeoServer in lat/long, its bbox has these coordinates and this is the extent I would like to set the Vector Tile Layer too:
[-124.7556263784179, 24.51862984111434, -66.95402637841792, 49.385634455558026] In GeoServer, I can also get the bounds of the data in its native units (EPSG 900913 - m) and it returns these coordinates. When I plot this on bbox finder the result doesn't make much sense to me, but if I explicitly set the VectorTileLayer extent property to these values, the 404 errors go away and I know they're in the proper units for the OpenLayers map, unlike the lat/longs.
[-13887732.802041369, 2816733.970116345, -7453288.123004889, 6340550.623693095] Is the only way to limit the vector tile layer extent by explicitly hardcoding it for each layer when I create the vector tile source or can I derive it and set it using the layer itself?