简体   繁体   English

如何在CartoDB中使用Mapbox地图

[英]How to use a mapbox map in cartodb

I tried to integrate this map: https://a.tiles.mapbox.com/v4/felixmichel.kh7h21lp/page.html?access_token=pk.eyJ1IjoiZmVsaXhtaWNoZWwiLCJhIjoiZWZrazRjOCJ9.62fkOEqGMxFxJZPJuo2iIQ#11/47.6732/7.5352 into cartodb. 我试图整合这张地图: https ://a.tiles.mapbox.com/v4/felixmichel.kh7h21lp/page.html ? access_token = pk.eyJ1IjoiZmVsaXhtaWNoZWwiLCJhIjoiZWZrazRjOCJ9.62fkOEqGMxFxJZPJuo7.6iIQ#1352。 But, it doesn't work. 但是,它不起作用。 I work with cartodb.js because I added some more queries, so I needed the right link for this part: 我使用cartodb.js,因为我添加了更多查询,因此我需要此部分的正确链接:

L.tileLayer('https://a.tiles.mapbox.com/v4/felixmichel.kh7h21lp/page.html?access_token=pk.eyJ1IjoiZmVsaXhtaWNoZWwiLCJhIjoiZWZrazRjOCJ9.62fkOEqGMxFxJZPJuo2iIQ#11/47.6732/7.5352', {
      attribution: 'CartoDB'
    }).addTo(map);

Or if somebody knows a beautiful terrain map I am happy too. 或者,如果有人知道美丽的地形图,我也很高兴。

Your tileLayer url is faulty, it expects the url to have placeholders for zoomlevel {z} and {x} and {y} for the axis values. 您的tileLayer URL错误,它期望该URL在缩放级别{z}和{x}和{y}的轴值中具有占位符。 You've used the url from an actual tile, which will not work. 您已经使用了实际磁贴中的网址,但无法使用。

L.tileLayer('https://a.tiles.mapbox.com/v4/felixmichel.kh7h21lp/{z}/{x}/{y}.png?access_token={token}', {
    attribution: 'Mapbox',
    subdomains: ['a','b','c','d'],
    token: 'pk.eyJ1IjoiZmVsaXhtaWNoZWwiLCJhIjoiZWZrazRjOCJ9.62fkOEqGMxFxJZPJuo2iIQ'
}).addTo(map);

Note that as you can see, it also supports the {s} placeholder to load from multiple subdomains (which must be supported by your tileprovider. Mapbox does) which is much faster because browsers can simultaneously load from four subdomains at once. 请注意,如您所见,它还支持{s}占位符以从多个子域加载(必须由tileprovider支持。Mapbox确实如此),这要快得多,因为浏览器可以一次从四个子域同时加载。 I also separated the access token from the url with the {token} placeholder to demonstrate that you can use your own custom tokens if needed. 我还使用{token}占位符将访问令牌与url分开,以说明您可以根据需要使用自己的自定义令牌。

Here's a working example of this on Plunker: http://plnkr.co/edit/lsTO9KzPMyzEKr06It1I?p=preview 这是在Plunker上的一个工作示例: http ://plnkr.co/edit/lsTO9KzPMyzEKr06It1I?p=preview

And here's the reference for Leaflet's L.TileLayer: http://leafletjs.com/reference.html#tilelayer 这是Leaflet的L.TileLayer的参考: http ://leafletjs.com/reference.html#tilelayer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM