admin管理员组文章数量:1325510
I have followed leaflet "get started" tutorial
but I get an 401 error while trying to load the tiles
.mapbox.project.id/13/4093/2724.png?access_token=your.mapbox.public.access.token Failed to load resource: the server responded with a status of 401 (Unauthorized)
what am I missing?
my html
<html>
<head>
<title></title>
<link rel="stylesheet" href="elad_map.css" />
<link rel="stylesheet" href=".7.7/leaflet.css" />
</head>
<body>
<div id="map"></div>
<script src=".7.7/leaflet.js"></script>
<script type="text/javascript" src="elad_map.js"></script>
</body>
</html>
I have followed leaflet "get started" tutorial
but I get an 401 error while trying to load the tiles
https://api.tiles.mapbox./v4/your.mapbox.project.id/13/4093/2724.png?access_token=your.mapbox.public.access.token Failed to load resource: the server responded with a status of 401 (Unauthorized)
what am I missing?
my html
<html>
<head>
<title></title>
<link rel="stylesheet" href="elad_map.css" />
<link rel="stylesheet" href="http://cdn.leafletjs./leaflet/v0.7.7/leaflet.css" />
</head>
<body>
<div id="map"></div>
<script src="http://cdn.leafletjs./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./v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="http://openstreetmap">OpenStreetMap</a> contributors, <a href="http://creativemons/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.">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);
}
Share
Improve this question
asked Jan 28, 2016 at 11:59
Elad BendaElad Benda
36.7k92 gold badges283 silver badges493 bronze badges
2 Answers
Reset to default 3What forgot to swap out the id
and accessToken
:
id: 'your.mapbox.project.id',
accessToken: 'your.mapbox.public.access.token'
You'll need to change the accessToken
to the one you get when registering with Mapbox and the id
to a mapbox project id like mapbox.streets
, mapbox-outdoors
, mapbox-satellite
or a custom id you get when creating a custom map via Mapbox Studio Classic.
document.onload = loadMap();
function loadMap() {
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://api.tiles.mapbox./v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="http://openstreetmap">OpenStreetMap</a> contributors, <a href="http://creativemons/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.">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);
}
版权声明:本文标题:javascript - Failed to load resource: the server responded with a status of 401 for mapbox api - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742196960a2431256.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论