5

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.

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:

enter image description here

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.

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

4

3 回答 3

6

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

map.on('error', e => {
    // Hide those annoying non-error errors
    if (e && e.error !== 'Error: Not Found')
        console.error(e);
});
于 2017-03-14T04:11:07.120 回答
2

我为未来的版本改进了 404 处理。

在这种情况下,您仍然会看到浏览器提供的GET https://... 404 (Not Found)消息,但看不到 JavascriptError: Not Found异常消息。

于 2017-03-20T18:53:55.337 回答
2

如果您使用自己的磁贴服务器,您可以将其设置为提供无内容204 HTTP 状态

以下是它在定制的 node.js tile 服务器中的样子:

app.use(function(req, res, next) {
  if(res.status(404)) {
    res.sendStatus(204)
  }
});
于 2018-06-07T16:23:21.253 回答