停止在 OpenLayers 3 tileloadstart 事件中加载图块 [英] Stop loading a tile in OpenLayers 3 tileloadstart event

查看:104
本文介绍了停止在 OpenLayers 3 tileloadstart 事件中加载图块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 OpenLayers 3(版本 3.13.1)中有一个使用 XYZ 源的 Tile 层,url 属性设置为 http://my.server/map/z{z}/row{y}/{z}_{x}_{y}.jpg.在我的服务器上,文件夹 z2 到 z8 中的平铺图像可用.但是 OpenLayers 也尝试从不存在的文件夹 z1 中获取图像.地图显示正确,但我的浏览器控制台显示文件未找到错误.有没有办法在 tileloadstart 事件中停止加载明显不存在的图块?我的代码如下:

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
    });
}

非常感谢任何帮助.

推荐答案

解决方案是正确设置源,这样它就不会尝试获取您没有可用缩放级别的图像:

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
  })
});

这篇关于停止在 OpenLayers 3 tileloadstart 事件中加载图块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆