Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank map tiles - Error 410 gone (Mapbox & Leaflet JS)

I am using Leaflet JS and MapBox to create a map. My browser displays as below:

Blank map tiles with MapBox

The map does not show at all, my map tile is blank. The errors that I get in the dev tools console is:

Error messages in console

GET https://api.tiles.mapbox.com/v4/mapbox.streets/9/123/183.png?access_token=pk.eyJ1IjoibXl2ZXJkaWN0IiwiYSI6ImNrZmoyYmpuNDB1eHYycG16bms0aHN2ZWwifQ.w0DRp5yDUHxa2RJa0aDRlQ 410 (Gone)
Image (async)       
createTile  @   TileLayer.js:158
_addTile    @   GridLayer.js:812
_update     @   GridLayer.js:709
_setView    @   GridLayer.js:570
_resetView  @   GridLayer.js:526
 onAdd      @   GridLayer.js:162
_layerAdd   @   Layer.js:114
whenReady   @   Map.js:1465
addLayer    @   Layer.js:176
addTo       @   Layer.js:52
(anonymous) @   maps.js:16

The maps.js:16 above references the last line .addTo(map) in the maps.js code snippet below:

let coordinates = [ 44.96, -93.2 ] 
let zoomLevel = 9
let map = L.map("college-map").setView(coordinates, zoomLevel)

L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery &copy; <a href="https://www.mapbox.com/">Mapbox</a>',
id: 'mapbox.streets',
accessToken: 'your-access-token'
}).addTo(map)

How do I fix this error and display the map successfully?

like image 428
myverdict Avatar asked Sep 26 '20 03:09

myverdict


People also ask

What does 410 Gone Client Error response code mean?

Doc: Mapbox Leaflet Implementaton (On the right side is a switch with before and after (now)). Show activity on this post. "410 Gone client error response code indicates that access to the target resource is no longer available at the origin server and that this condition is likely to be permanent."

What do you want to learn in Mapbox tiling service?

Learn best practices for setting up an account and collaborating on projects. Learn how to address CORS errors. Learn how to fix errors when uploading CSV files. How area is calculated for Mapbox Tiling Service and the Uploads API

Why is my map not showing up in WebGL?

Mapbox GL JS maps (including the Mapbox Studio style editor and dataset editor) can fail to display because of issues with your browser, your network, your computer, or some combination of all three. WebGL compatibility can be tricky to troubleshoot, but here are some general guidelines and resources:

Why is invalidatesize not working in Mapbox GL JS?

Read more about invalidateSize in the mapbox.js documentation. Mapbox GL JS maps (including the Mapbox Studio style editor and dataset editor) can fail to display because of issues with your browser, your network, your computer, or some combination of all three.


2 Answers

Mapbox changed the url schema from:

var map = L.map('map');

L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
    attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
    maxZoom: 18,
    id: 'mapbox.streets',
    accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN'
}).addTo(map);

To:

var map = L.map('map');

L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
    attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
    tileSize: 512,
    maxZoom: 18,
    zoomOffset: -1,
    id: 'mapbox/streets-v11',
    accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN'
}).addTo(map);

The url https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken} and the {id: 'mapbox/streets-v11'} changed.

Doc: Mapbox Leaflet Implementaton (On the right side is a switch with before and after(now)).

Url params: Static Tiles Style

Default Styles

The new default style Ids:

  • mapbox/streets-v11
  • mapbox/outdoors-v11
  • mapbox/light-v10
  • mapbox/dark-v10
  • mapbox/satellite-v9
  • mapbox/satellite-streets-v11
like image 90
Falke Design Avatar answered Sep 20 '22 12:09

Falke Design


https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/410

"410 Gone client error response code indicates that access to the target resource is no longer available at the origin server and that this condition is likely to be permanent."

If you open your link https://api.tiles.mapbox.com/v4/mapbox.streets/9/123/183.png?access_token=pk.eyJ1IjoibXl2ZXJkaWN0IiwiYSI6ImNrZmoyYmpuNDB1eHYycG16bms0aHN2ZWwifQ.w0DRp5yDUHxa2RJa0aDRlQ in the browser, you will get this:

{"message":"Classic styles are no longer supported; see https://blog.mapbox.com/deprecating-studio-classic-styles-d8892ac38cb4 for more information"}

See also this:

https://docs.mapbox.com/help/troubleshooting/migrate-legacy-static-tiles-api/#will-the-apis-return-an-error-when-classic-styles-are-no-longer-supported

like image 42
Anatoly Sukhanov Avatar answered Sep 16 '22 12:09

Anatoly Sukhanov