传单错误:资源解释为图像
Leaflet err: Resource interpreted as Image
我想将传单地图包含到我的项目中,但是当我输入我的 setView()
时,我没有地图,只有带有缩放按钮的空层。我看了传单 Quick Start Guide 的手册,没有任何理由说明我的地图不起作用。我完成了所有说明(添加了 div
和 css
,添加了我的代码(首先在 main.js 文件中,然后添加到标记 script
中),尝试像示例中那样添加地图) .
我在 mapbox.org 中制作了我的地图并注意到一个不同的说明 L.tileLayer('http://{s}.tiles.mapbox.com/v3/MapID/{z}/{x}/{y}.png', {
我只需要更改我的 MapID
。当我这样做时,我有一个 error 401
但是在地图框中我有一个导出 link 像这样:https://a.tiles.mapbox.com/v4/MaoID/page.html?access_token=MY_ACCESS_TOKEN#z/x/y
我将它添加到我的代码中,然后我在控制台中收到一条通知:
Resource interpreted as Image but transferred with MIME type text/html: https://...
如何将此地图添加到项目中???
我不知道你从哪里得到那些 URL 但它们完全错误:
L.tileLayer('https://{s}.tiles.mapbox.com/v4/{mapId}/{z}/{x}/{y}.png?access_token={token}', {
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>',
subdomains: ['a','b','c','d'],
mapId: 'myMapId',
token: 'myUserToken'
});
现在您需要使用您自己的地图 ID 和访问令牌更改 myMapId
和 myUserToken
,就可以了。如果您没有这些,则需要在 Mapbox 上创建一个帐户:https://www.mapbox.com/signup/ to get a token and create your own map with the editor: https://www.mapbox.com/editor/#app to get a map ID. You could also just use mapbox.js
, which is an extension of Leaflet, see: https://www.mapbox.com/mapbox.js/example/v1.0.0/
我想将传单地图包含到我的项目中,但是当我输入我的 setView()
时,我没有地图,只有带有缩放按钮的空层。我看了传单 Quick Start Guide 的手册,没有任何理由说明我的地图不起作用。我完成了所有说明(添加了 div
和 css
,添加了我的代码(首先在 main.js 文件中,然后添加到标记 script
中),尝试像示例中那样添加地图) .
我在 mapbox.org 中制作了我的地图并注意到一个不同的说明 L.tileLayer('http://{s}.tiles.mapbox.com/v3/MapID/{z}/{x}/{y}.png', {
我只需要更改我的 MapID
。当我这样做时,我有一个 error 401
但是在地图框中我有一个导出 link 像这样:https://a.tiles.mapbox.com/v4/MaoID/page.html?access_token=MY_ACCESS_TOKEN#z/x/y
我将它添加到我的代码中,然后我在控制台中收到一条通知:
Resource interpreted as Image but transferred with MIME type text/html: https://...
如何将此地图添加到项目中???
我不知道你从哪里得到那些 URL 但它们完全错误:
L.tileLayer('https://{s}.tiles.mapbox.com/v4/{mapId}/{z}/{x}/{y}.png?access_token={token}', {
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>',
subdomains: ['a','b','c','d'],
mapId: 'myMapId',
token: 'myUserToken'
});
现在您需要使用您自己的地图 ID 和访问令牌更改 myMapId
和 myUserToken
,就可以了。如果您没有这些,则需要在 Mapbox 上创建一个帐户:https://www.mapbox.com/signup/ to get a token and create your own map with the editor: https://www.mapbox.com/editor/#app to get a map ID. You could also just use mapbox.js
, which is an extension of Leaflet, see: https://www.mapbox.com/mapbox.js/example/v1.0.0/