Reputation: 153
I have a Tile layer using an XYZ source in OpenLayers 3 (version 3.13.1) with url property set to http://my.server/map/z{z}/row{y}/{z}_{x}_{y}.jpg
. On my server Tile images in folders z2 to z8 are available. But OpenLayers also tries to fetch images from folder z1 which doesn't exist. The map displays correctly, but my browser's console shows a file not found error. Is there a way to stop loading obviously non-existent tiles in the tileloadstart event? My code is as follows:
function createTileLayer() {
var xyzSource = new ol.source.XYZ({
url: 'http://my.server/map/z{z}/row{y}/{z}_{x}_{y}.jpg'
});
xyzSource.on('tileloadstart', function(evt) {
if (evt.tile.tileCoord[0] == 1) {
// Stop loading the Tile ?!?!
}
});
return new ol.layer.Tile({
extent: _maxExtent,
preload: 1,
source: xyzSource
});
}
Any help is greatly appreciated.
Upvotes: 2
Views: 1176
Reputation: 5648
The solution is to set up the source properly so it does not try to fetch images for zoom levels that you do not have available:
var xyzSource = new ol.source.XYZ({
url: 'http://my.server/map/z{z}/row{y}/{z}_{x}_{y}.jpg',
tileGrid: ol.tilegrid.createXYZ({
minZoom: 2,
maxZoom: 8
})
});
Upvotes: 3