Mapbox:如何避免当前缩放级别不可用的图块的JavaScript错误? [英] Mapbox: How to avoid JavaScript errors for tilesets that aren't available at the current zoom level?

查看:303
本文介绍了Mapbox:如何避免当前缩放级别不可用的图块的JavaScript错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mapbox GL JS,并从我的Mapbox帐户加载图块图层.其中一些tileet图层仅适用于10到15缩放级别.

I'm using Mapbox GL JS and loading tileset layers from my Mapbox account. Some of these tileset layers are only available for zoom levels 10 to 15.

我的地图的默认缩放级别是5,加载地图时,我收到一个JavaScript控制台错误,说该图块是404ing:

The default zoom level of my map is 5, and when I load the map I get a JavaScript console error, saying that the tileset is 404ing:

有什么办法可以避免这种情况吗?我不想一直重新创建tileset来缩放级别5,因为它会不必要地增加其大小.

Is there any way I can avoid this? I don't want to recreate the tileset all the way to zoom level 5, as it will unnecessarily increase its size.

我不认为控制台错误会导致Chrome出现任何问题,但我不知道它是否会在其他浏览器中出现.

I don't think the console error is causing any problems in Chrome, but I don't know whether it will in other browsers.

推荐答案

最简单的方法是替换默认的错误处理程序,过滤掉未找到"消息:

The easiest way is to replace the default error handler, filtering out the "Not Found" message:

map.on('error', e => {
    // Hide those annoying non-error errors
    if (e && e.error !== 'Error: Not Found')
        console.error(e);
});

这篇关于Mapbox:如何避免当前缩放级别不可用的图块的JavaScript错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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