0

Ok, I am using Mapbox as my mapping library, I render the map layers using the tiles (geojson) uploaded to the mapbox account. Demo here

The map renders properly but I get lots of 404 not found errors for the source tiles.

How to get rid of these errors?

enter image description here

Here is my code:

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",
    });
});
Saurabh Palatkar
  • 3,242
  • 9
  • 48
  • 107
  • Possible duplicate of [Mapbox: How to avoid JavaScript errors for tilesets that aren't available at the current zoom level?](https://stackoverflow.com/questions/42772538/mapbox-how-to-avoid-javascript-errors-for-tilesets-that-arent-available-at-the) – Steve Bennett May 22 '17 at 23:35
  • 1
    What version of mapbox-gl-js are you using? Recent versions should avoid requesting tiles that do not exist in a given source. – mollymerp May 23 '17 at 10:57

2 Answers2

0

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);
});
MehulJoshi
  • 879
  • 8
  • 19
  • Though it removed few of the 404 errors, but I still see the bunch of 404 errors in the console. – Saurabh Palatkar May 22 '17 at 11:16
  • it will remove error, when browser get's 404 on any resource, it logs that in console, you can't remove that, you can only catch errors which is from script. it's browser's log. ;-) you can't remove it. – MehulJoshi May 22 '17 at 11:32
  • So do you know the reason, why mapbox fails to download the resources, even though the source layer url is correct? – Saurabh Palatkar May 22 '17 at 12:24
  • 1
    Heh, you literally copy-pasted my answer from https://stackoverflow.com/questions/42772538/mapbox-how-to-avoid-javascript-errors-for-tilesets-that-arent-available-at-the/42777638#42777638 . For future reference, you should just mention that the question is a duplicate (with a link), and vote to close it (if you can). – Steve Bennett May 22 '17 at 23:36
  • 1
    @SaurabhPalatkar The normal reason is because there is no data in the region you're trying to download. I thought Mapbox had switched to using a different code ("No data, but no error") but maybe not. – Steve Bennett May 22 '17 at 23:37
0

As pointed out by mollymerp, updating the mapbox-gl js from 0.32.0 to 0.37.0 resolved the issue for me.

Saurabh Palatkar
  • 3,242
  • 9
  • 48
  • 107