Mapbox: How to avoid JavaScript errors for tilesets that aren't available at the current zoom level?

一笑奈何 提交于 2019-12-01 20:37:21
Steve Bennett

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

I have improved our 404 handling for future releases.

In this case, you will still see the browser-provided GET https://... 404 (Not Found) message but not the Javascript Error: Not Found exception message.

If you are using your own tile server you can set it up to give a No Content 204 HTTP status.

Here is what it would like in a custom made node.js tile server:

app.use(function(req, res, next) {
  if(res.status(404)) {
    res.sendStatus(204)
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!