gpt4 book ai didi

reactjs - 使用 React-mapbox-gl 使用 Mapbox 渲染矢量切片

转载 作者:行者123 更新时间:2023-12-02 11:22:33 30 4
gpt4 key购买 nike

我有一个 geoJSON 文件,我可以将其转换为 vector.tiles使用 this npm package .
我用 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 vector-tiles)如下 -

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 文件转换为矢量切片后,我将此数据发送到客户端,在其中渲染 map 使用 React.js Mapbox* .我使用以下来渲染 map ,但我无法弄清楚我做错了什么。我得到的错误是 error: layers.jsx-layer-0: layer "jsx-layer-0" must specify a "source-layer"
<Source type="vector" tiles={data.tiles} >
<Layer {...dataLayer}/>
</Source>

我浏览了 Mapbox 的文档,但我找不到我做错了什么。任何帮助都会有很大帮助。非常感谢。

最佳答案

文档表明 source-layerrequired field用于矢量图层。

也就是说,它在声明性 api 中的工作方式当然是不透明的。基于 example ,你可以试试这个,看看它是否有效 -

...
const url = 'mapbox://mapbox.mapbox-terrain-v2'
const source = 'my-source';

<Source id={{source}} name={{source}} type="vector" url={url} tiles={data.tiles} >
<Layer source={{source}} {...dataLayer}/>
</Source>
...

关于reactjs - 使用 React-mapbox-gl 使用 Mapbox 渲染矢量切片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62225562/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com