Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 295
Richard Avatar asked Mar 13 '17 20:03

Richard


2 Answers

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);
});
like image 76
Steve Bennett Avatar answered Oct 24 '22 20:10

Steve Bennett


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.

like image 24
Lucas Wojciechowski Avatar answered Oct 24 '22 20:10

Lucas Wojciechowski