如何全屏显示地图并以 react-simple-maps 为中心
How can I display map full screen and centered with react-simple-maps
我想显示墨西哥地图时遇到这个问题
如您所见,显示不完整,我不想放大,我只希望地图显示居中且完整
到目前为止,这是我的代码。
const geoUrl = 'https://gist.githubusercontent.com/diegovalle/5129746/raw/c1c35e439b1d5e688bca20b79f0e53a1fc12bf9e/mx_tj.json'
//const geoUrl = mapa2 ;
return (
<div>
<h1>Bienvenido a Blog!</h1>
<ComposableMap style={{backgroundColor:'gray'}} projection={'geoAlbers'}>
<Geographies style={{backgroundColor:'green', bottom:100}} geography={geoUrl}>
{({ geographies }) =>
geographies.map(geo => (
<Geography key={geo.rsmKey} geography={geo} />
))
}
</Geographies>
</ComposableMap>
要使地图居中,您可以使用 projectionConfig
道具和 center
。类似于:
<ComposableMap
style={{ backgroundColor: "gray" }}
projection="geoAlbers"
projectionConfig={{
center:[-5, 25]
}}
>
结果是:
Here 修改了你的代码的一个codesandbox。
我想显示墨西哥地图时遇到这个问题
到目前为止,这是我的代码。
const geoUrl = 'https://gist.githubusercontent.com/diegovalle/5129746/raw/c1c35e439b1d5e688bca20b79f0e53a1fc12bf9e/mx_tj.json'
//const geoUrl = mapa2 ;
return (
<div>
<h1>Bienvenido a Blog!</h1>
<ComposableMap style={{backgroundColor:'gray'}} projection={'geoAlbers'}>
<Geographies style={{backgroundColor:'green', bottom:100}} geography={geoUrl}>
{({ geographies }) =>
geographies.map(geo => (
<Geography key={geo.rsmKey} geography={geo} />
))
}
</Geographies>
</ComposableMap>
要使地图居中,您可以使用 projectionConfig
道具和 center
。类似于:
<ComposableMap
style={{ backgroundColor: "gray" }}
projection="geoAlbers"
projectionConfig={{
center:[-5, 25]
}}
>
结果是:
Here 修改了你的代码的一个codesandbox。