reactjs - 使用 Mapbox 使用 react-mapbox-gl 渲染矢量瓦片
问题描述
vector.tiles
我有一个 geoJSON 文件,我使用这个 npm 包转换成它。我用const tileIndex = geojsonvt(geoJSON)
. geoJSON 文件具有以下格式,并且转换后没有任何错误。
const geoJSON = {
type: 'FeatureCollection',
crs: {
type: 'name',
properties: { name: 'urn:ogc:def:crs:OGC:1.3:CRS84' }
},
features: [
{
properties: [Object],
geometry: [Object],
type: 'Feature',
_id: '5ed7b221a61a4b2970433932'
},
... 1840 more items
]
}
转换后得到的结果(geoJSON 矢量图块)如下 -
const tiles = {
options: {},
tiles: {
'0': {
features: [Array],
numPoints: 540529,
numSimplified: 3,
numFeatures: 1940,
source: null,
x: 0,
y: 0,
z: 0,
transformed: false,
minX: 0.5162953202777778,
minY: 0.316725863688461,
maxX: 0.5338655772222223,
maxY: 0.34955196703359503
},
'1': { ... }
},
tileCoords: [
{ z: 0, x: 0, y: 0 }, { z: 1, x: 1, y: 1 },
{ z: 1, x: 1, y: 0 }, { z: 2, x: 3, y: 1 },
{ z: 2, x: 3, y: 0 }, { z: 2, x: 2, y: 1 },
{ z: 3, x: 5, y: 3 }, { z: 3, x: 5, y: 2 },
{ z: 3, x: 4, y: 3 }, { z: 3, x: 4, y: 2 },
{ z: 4, x: 9, y: 5 }, { z: 4, x: 9, y: 4 },
{ z: 4, x: 8, y: 5 }, { z: 5, x: 17, y: 11 },
{ z: 5, x: 17, y: 10 }, { z: 5, x: 16, y: 11 },
{ z: 5, x: 16, y: 10 }, { z: 4, x: 8, y: 4 },
{ z: 2, x: 2, y: 0 }, { z: 1, x: 0, y: 1 },
{ z: 1, x: 0, y: 0 }
]
}
将具有 5000 层的巨大 geoJSON 文件转换为矢量图块后,我将此数据发送到客户端,在客户端使用React.js和Mapbox*渲染地图。我使用以下来渲染地图,但我无法弄清楚我做错了什么。我得到的错误说error: layers.jsx-layer-0: layer "jsx-layer-0" must specify a "source-layer"
<Source type="vector" tiles={data.tiles} >
<Layer {...dataLayer}/>
</Source>
我同样浏览了 Mapbox 的文档,但我找不到我做错了什么。任何帮助都会有很大帮助。非常感谢。
解决方案
推荐阅读
- javascript - 如何在 react.js 的 setState 中创建 THREE.PerspectiveCamera 对象
- bash - 打印基于另一个索引文件的压缩 gz 文件的行
- php - Symfony 安全性 - 获取有关拒绝访问的详细信息
- apache-zeppelin - 如何将 Zeppelin 笔记本迁移到 Azure Databricks
- terraform - Terraform 在模块中使用变量和其他资源
- python - 在 Python tkinter 中,Text 小部件的 yscrollcommand 无法按预期工作
- php - 如何在 authorize.net 中设置试用期间隔?
- c++ - 复合地图:从另一个地图中获取数据
- javascript - this.title 不是数据表上的函数
- python - 如何将不平衡库与 sklearn 管道一起使用?