简体   繁体   English

在 Leaflet 中使用 Mapzen 图块

[英]Using Mapzen tiles with Leaflet

My reading of the Leaflet and Mapzen documentations suggest that in order to use a custom tile provider with Leaflet, one needs to do just two things:我对 Leaflet 和Mapzen文档的阅读表明,为了在 Leaflet 中使用自定义贴提供程序,只需要做两件事:

  1. Specify the tile provider in L.tilelayer(urlTemplateToTileProvider)L.tilelayer(urlTemplateToTileProvider)指定瓦片提供者
  2. Set this provider to MapZen将此提供程序设置为 MapZen
var urlTemplateToTileProvider =
  'http://tile.mapzen.com/mapzen/vector/v1/all/{z}/{x}/{y}.mvt?api_key=apiKey'

However, when I try this I end up with an empty map which then proceeds to display markers etc correctly.但是,当我尝试这样做时,我最终得到了一张空地图,然后继续正确显示标记等。 And yet a manual test for a generated tile URL, eg并且对生成的磁贴 URL 进行手动测试,例如

http://tile.mapzen.com/mapzen/vector/v1/all/14/8471/5583.mvt?api_key=apiKey

did in fact download some - unintelligible to me - data.事实上确实下载了一些 - 我无法理解的 - 数据。

I also tried using the other two formats mentioned in the Mapzen docs ( .json and .geojson ) but with exactly the same result.我使用的Mapzen文档(中提到的其他两种格式也试图.json.geojson ),但完全相同的结果。 Given that the latter two formats return human readable data, I checked them out for my test tile in my browser and the data is indeed for the area I want to use.鉴于后两种格式返回人类可读的数据,我在浏览器中检查了我的测试图块,数据确实适用于我想要使用的区域。

Curiously enough, the Leaflet docs and tutorials request a PNG tile layer ( http://{s}.tile.osm.org/{z}/{x}/{y}.png ), not raw data.奇怪的是,Leaflet 文档和教程需要一个 PNG 平铺层 ( http://{s}.tile.osm.org/{z}/{x}/{y}.png ),而不是原始数据。

What am I doing wrong here?我在这里做错了什么?

The Tile Layer is for raster tiles (ie plain images, like the PNG format for example).平铺层用于光栅平铺(即普通图像,例如 PNG 格式)。

Mapzen delivers vector tiles. Mapzen 提供矢量切片。 To use them with Leaflet, you could use a plugin, eg Leaflet.VectorGrid ( license )要将它们与 Leaflet 一起使用,您可以使用插件,例如Leaflet.VectorGrid ( license )

Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet 1.0.0在 Leaflet 1.0.0 中显示网格矢量数据(切片 GeoJSON 或 protobuf 矢量瓦片)

See the demo , which includes tiles from Mapzen请参阅演示,其中包括 Mapzen 中的图块

var mapzenTilesUrl = "https://tile.mapzen.com/mapzen/vector/v1/all/{z}/{x}/{y}.mvt?api_key={apikey}";
var mapzenVectorTileOptions = {
  rendererFactory: L.canvas.tile,
  attribution: '<a href="https://mapzen.com/">&copy; MapZen</a>, <a href="http://www.openstreetmap.org/copyright">&copy; OpenStreetMap</a> contributors',
  vectorTileLayerStyles: vectorTileStyling,
  apikey: 'KEY',
};
var mapzenTilesPbfLayer = L.vectorGrid.protobuf(mapzenTilesUrl, mapzenVectorTileOptions);

Since you have raw data in the vector tiles, you need to provide the styling spec ( vectorTileStyling )由于您在矢量切片中有原始数据,您需要提供样式规范( vectorTileStyling

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

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