2
votes

I have a JSON file that d3 map is not rendering an Australia TopoJSON file I have created.

The same code renders an American map just fine. There are no errors in the browser inspector and both maps render fine on online visualisation sites like geojson.io.

I have provided links to the JSON's.

<html>

<head>
  <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
  <script src="http://d3js.org/topojson.v1.min.js"></script>
  <style>
    path {
      fill: #ccc;
    }
  </style>
</head>

<body>
  <h1>topojson simplified Australia</h1>
  <script>
    var width = window.innerWidth,
      height = window.innerHeight;

    var path = d3.geo.path();

    var svg = d3.select("body").append("svg")
      .attr("width", width)
      .attr("height", height);

    d3.json("topo-australia-simplified.json", function(error, topology) {
      if (error) throw error;

      svg.selectAll("path")
        .data(topojson.feature(topology, topology.objects.australia).features)
        .enter().append("path")
        .attr("d", path);
    });
  </script>


</body>

</html>
1

1 Answers

0
votes

The problem is that you are using:

var path = d3.geo.path();

You have not given the projection:

var projection = d3.geo.mercator()
  .scale(500)//scale it up as per your choice.
  .translate([-900,0]);//translate as it was scaled up.

var path = d3.geo.path()
  .projection(projection);

working code here