zcreativelabs / react-simple-maps

Beautiful React SVG maps with d3-geo and topojson using a declarative api.
https://www.react-simple-maps.io/
MIT License
3.04k stars 424 forks source link

Full topoJSON map not showing #164

Open rbent98 opened 4 years ago

rbent98 commented 4 years ago

I used map shapper to convert many layers into a topoJSON file. I can see see the multiple layers in the mapshapper visual but when I import the geography into the simple-maps geography components only polygons of one of the layers show up and function as intended. When I read through the topoJSON file I can see that the information from the other layers are indeed there.

zimrick commented 4 years ago

Hi @rbent98, Currently, react-simple-maps does not handle these multilayered topojson/geojson files. You can do two things though:

  1. Use multiple Geographies. You can use more than one <Geographies /> component in your map and load the files separately. This will give you geography "layers" in react-simple-maps. Export your layers as separate files and then reference each file separately:
...
<Geographies geography={file1url}>
  {({geographies}) => geographies.map(geo >
    <Geography key={geo.rsmKey} geography={geo} />
  )}
</Geographies>
<Geographies geography={file2url}>
  {({geographies}) => geographies.map(geo >
    <Geography key={geo.rsmKey} geography={geo} />
  )}
</Geographies>
<Geographies geography={file3url}>
  {({geographies}) => geographies.map(geo >
    <Geography key={geo.rsmKey} geography={geo} />
  )}
</Geographies>
...
  1. You can load the topojson manually, transform it to geojson, and then feed the various 'layers' to separate Geographies. That way you can still do the rendering with react-simple-maps, but you take care fo the file loading and topojson conversion yourself.