javascript - Failed to load resource: the server responded with a status of 401 for mapbox api -
i have followed leaflet "get started" tutorial
but 401 error while trying load tiles
https://api.tiles.mapbox.com/v4/your.mapbox.project.id/13/4093/2724.png?access_token=your.mapbox.public.access.token failed load resource: server responded status of 401 (unauthorized)
what missing?
my html
<html> <head> <title></title> <link rel="stylesheet" href="elad_map.css" /> <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" /> </head> <body> <div id="map"></div> <script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script> <script type="text/javascript" src="elad_map.js"></script> </body> </html>
document.onload = loadmap(); function loadmap() { var map = l.map('map').setview([51.505, -0.09], 13); l.tilelayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accesstoken}', { attribution: 'map data © <a href="http://openstreetmap.org">openstreetmap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">cc-by-sa</a>, imagery © <a href="http://mapbox.com">mapbox</a>', maxzoom: 18, id: 'your.mapbox.project.id', accesstoken: 'your.mapbox.public.access.token' }).addto(map); var circle = l.circle([51.508, -0.11], 500, { color: 'red', fillcolor: '#f03', fillopacity: 0.5 }).addto(map); var polygon = l.polygon([ [51.509, -0.08], [51.503, -0.06], [51.51, -0.047] ]).addto(map); }
what forgot swap out id
, accesstoken
:
id: 'your.mapbox.project.id', accesstoken: 'your.mapbox.public.access.token'
you'll need change accesstoken
1 when registering mapbox , id
mapbox project id mapbox.streets
, mapbox-outdoors
, mapbox-satellite
or custom id when creating custom map via mapbox studio classic.
Comments
Post a Comment