[英]Deck.GL with CARTO and React
I'm trying to use a CARTO basemap ( @deck.gl/carto
) with Deck.GL ( @deck.gl/react
) in a React application.我正在尝试在 React 应用程序中使用 CARTO 底图(
@deck.gl/carto
)和 Deck.GL( @deck.gl/react
)。 To render a map layer, the docs utilize Mapbox's <StaticMap/>
component from react-map-gl
.为了渲染 map 层,文档使用了来自
react-map-gl
的 Mapbox 的<StaticMap/>
组件。
However, when I pass CARTO's free basemap BASEMAP.VOYAGER
as a property to the <StaticMap
component, it refuses to show the map because I don't have a Mapbox access token.但是,当我将 CARTO 的免费底图
BASEMAP.VOYAGER
作为属性传递给<StaticMap
组件时,它拒绝显示 map,因为我没有 Mapbox 访问令牌。
So, I registered and got a Mapbox token and it works just fine, like below:所以,我注册并获得了一个 Mapbox 令牌,它工作得很好,如下所示:
<DeckGL
style={{
position: "relative",
width: "100%",
height: "600px",
}}
initialViewState={initViewState}
controller={true}
layers={layers}
onClick={(evt) => console.log(JSON.stringify(evt.coordinate))}
getTooltip={({ object }) =>
object &&
object.coordinates && {
text: `Longitude: ${object.coordinates[0]}\nLatitude: ${object.coordinates[1]}\nCost: ${object.cost}`,
}
}
>
<StaticMap
mapStyle={BASEMAP.DARK_MATTER}
mapboxApiAccessToken={process.env.NEXT_PUBLIC_MAPBOX_TOKEN}
/>
</DeckGL>
But I want to use a CARTO basemap WITHOUT using Mapbox.但我想在不使用 Mapbox 的情况下使用 CARTO 底图。 Is that at all possible?
这有可能吗? It seems that the only way I can get a CARTO basemap is by building a map via their Map Builder tool on their website, publish it, and then use the link generated from that to then use it.
似乎我可以获得 CARTO 底图的唯一方法是通过他们网站上的 Map Builder 工具构建 map,发布它,然后使用从中生成的链接然后使用它。 But I can't create a basemap until I link datasets to the map (ie.csv, URL, database, arcGIS, etc.).
但是在将数据集链接到 map(即 csv、URL、数据库、arcGIS 等)之前,我无法创建底图。 Right now, I don't have any of that.
现在,我没有这些。
So I'm confused as to how to actually access and use a CARTO basemap without using Mapbox.所以我对如何在不使用 Mapbox 的情况下实际访问和使用 CARTO 底图感到困惑。 Any tips or advice is much appreciated!
非常感谢任何提示或建议!
A workaround would be installing 5.3.11
version, so you app won't require a Mapbox token, that's due to internal use of Mapbox v2.0解决方法是安装
5.3.11
版本,因此您的应用不需要 Mapbox 令牌,这是由于内部使用 Mapbox v2.0
yarn add react-map-gl@5.3.11
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.