Mapbox-gl.js 在浏览器控制台中为图块记录大量 404 错误

Mapbox-gl.js logs lots of 404 errors for tiles in the browser console

好的,我使用 Mapbox 作为我的地图库,我使用上传到 mapbox 帐户的图块 (geojson) 渲染地图图层。 Demo here

地图呈现正确,但我收到很多源图块的 404 未找到错误。

如何消除这些错误?

这是我的代码:

mapboxgl.accessToken = 'token';
var map = new mapboxgl.Map({
    container: 'map',
    //style: 'mapbox://styles/mapbox/streets-v9',
    style: 'mapbox://styles/saurabhp/cizmll8v200452sqj5c16hc55?optimize=true', // optimize=true,
    center: [-1.41, 6.32],
    zoom: 5
});

map.on('load', function () {
    map.addLayer({
        'id': 'maine',
        'type': 'fill',
        'layout': {},
        'paint': {
            'fill-color': {
              property: 'NDVI6',
                stops: [
                    [0, '#F2F12D'],
                    [1, '#EED322'],
                    [2, '#E6B71E'],
                    [3, '#DA9C20'],
                    [4, '#CA8323'],
                    [5, '#B86B25'],
                    [6, '#A25626'],
                    [7, '#8B4225'],
                    [8, '#723122']
                ]
            },
            'fill-opacity': 0.8
        },
        'source': {
            'type': 'vector',
            'url': 'mapbox://saurabhp.cizs70g1e003033lkqw0u2rjj-6kayy'
        },
       "source-layer": "ghanaTestTileset",
    });
});

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

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

正如 mollymerp 所指出的,将 mapbox-gl js 从 0.32.0 更新到 0.37.0 解决了我的问题。