gpt4 book ai didi

mapbox - react-map-gl 没有 API key 使用 osm 瓷砖

转载 作者:行者123 更新时间:2023-12-04 20:55:18 26 4
gpt4 key购买 nike

是否可以?
This告诉我它是,但不知道它为什么定义和 API key 。
但我无法让它与 react-map-gl 一起使用静态 map 类。我可以从该类中看到的属性只是 mapStyle这将采用标准的 Mapbox 矢量瓦片路径/名称。它需要一个对象吗?我的代码没有给我错误或显示我请求的图块。

    <DeckGL>
<StaticMap
mapStyle= {{
"version": 7,
"sources": {
"simple-tiles": {
"type": "raster",
"tiles":["http://a.tile.openstreetmap.org/{z}/{x}/{y}.png", "http://b.tile.openstreetmap.org/{z}/{x}/{y}.png"],
"tileSize": 256
},
"power": {
"type": "vector",
"tiles": ["http://gpstrails.info/ex/leaflet/power/osm/{z}/{x}/{y}.json"]
}
},
"layers": [{
"id": "simple-tiles",
"type": "raster",
"source": "simple-tiles",
"minzoom": 0,
"maxzoom": 22
},
{
"id": "road",
"source": "power",
"source-layer": "power",
"type": "line",
"layout": {
"line-join": "round",
"line-cap": "round",
},
"paint": {
"line-color": "red",
"line-width": 4,
}
}]
}}/>
</DeckGL>
谢谢
编辑:从正确的答案开始,并保持在 SO,这是 json住在 S3 上:
{
"version": 8,
"name": "OSM",
"metadata": {

},
"sources": {
"openmaptiles": {
"type": "vector",
"url": "https://free.tilehosting.com/data/v3.json?key={key}"
},
"osm": {
"type": "raster",
"tiles": [
"http://tile.openstreetmap.org/{z}/{x}/{y}.png"
],
"minzoom": 0,
"maxzoom": 14
},
"91y5159eg": {
"type": "vector",
"url": "http://localhost:3000/tilejson.json"
}
},
"sprite": "https://openmaptiles.github.io/klokantech-basic-gl-style/sprite",
"glyphs": "https://free.tilehosting.com/fonts/{fontstack}/{range}.pbf?key=undefined",
"layers": [
{
"id": "osm",
"type": "raster",
"source": "osm"
}
],
"id": "klokantech-basic"
}

更新: map 框 changed他们的许可证在 2.0 中,因此对于 < 2.0 的版本,接受的答案是正确的。如果没有提供 access_token,Mapbox > 2.0 会报错。

最佳答案

诀窍在于使用的样式。样式是一个 JSON 对象,您可以阅读有关其规范的更多信息 here .您可以使用诸如 Maputnik 之类的工具生成自定义样式。 ,一种可视化编辑器,可生成用于 MapboxGL map 的样式兼容文件。一旦生成了合适的样式,就可以在 React Map GL 中使用它。

这是基本组件的外观,与 Github repo 中的示例有所不同:

<ReactMapGL
mapStyle="https://s3.amazonaws.com/cdn.brianbancroft.io/assets/osmstyle.json"
{...this.state.viewport}
onViewportChange={viewport => this.setState({ viewport })}
/>

请注意,这只是一个抽象的例子。此处来自 OSM 的 tile 加载有点太慢而无法用于生产。但它应该说明如何在不依赖 Mapbox 的服务端的情况下制作 map 。

关于mapbox - react-map-gl 没有 API key 使用 osm 瓷砖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53669727/

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