Search code examples
reactjsfrontendreact-simple-maps

How can I display map full screen and centered with react-simple-maps


I am facing this issue when I want to display Mexico mapenter image description here As you can see is not showing completely, I dont want to be able to zoom in, I just want the map to be shown centered and complete

this is my code so far.

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>

Solution

  • To center the map you could use projectionConfig props with center. Something like:

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

    The result is:

    enter image description here

    Here a codesandbox of your code modified.