【问题标题】:How can I display map full screen and centered with react-simple-maps如何全屏显示地图并以 react-simple-maps 为中心
【发布时间】:2021-09-01 00:04:56
【问题描述】:

当我想显示墨西哥地图时,我遇到了这个问题 如您所见,没有完全显示,我不想放大,我只想让地图居中显示并完整

这是我目前的代码。

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>

【问题讨论】:

  • 请不要使用不相关的标签(在本例中为google-maps)标记您的问题。

标签: reactjs frontend react-simple-maps


【解决方案1】:

要使地图居中,您可以使用projectionConfig 道具和center。比如:

<ComposableMap
      style={{ backgroundColor: "gray" }}
      projection="geoAlbers"
      projectionConfig={{
        center:[-5, 25]
      }}
 >

结果是:

Here 修改后的代码的代码框。

【讨论】:

  • 哇!非常感谢解决了我的问题!
  • @josesantosalvarezmacias 没问题。快乐编码 =)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-26
  • 1970-01-01
  • 2020-11-03
  • 1970-01-01
  • 2014-07-03
  • 1970-01-01
相关资源
最近更新 更多