This is the code for Chapter 7, Figure 3 from D3.js in Action demonstrating how to load GeoJSON data and render it using d3.geo.path() and d3.geo.projection().
forked from emeeks's block: Ch. 7, Fig. 3 - D3.js in Action
xxxxxxxxxx
<html>
<head>
<title>D3 in Action Chapter 7 - Example 1</title>
<meta charset="utf-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
</head>
<style>
.countries {
fill: gray;
fill-opacity: .15;
stroke: black;
stroke-width: 1px;
}
</style>
<body>
</body>
<script>
var height = 1000, width = 1000;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var aProjection = d3.geo.mercator()
.scale(277)
.translate([height/2,width/2])
var geoPath = d3.geo.path().projection(aProjection);
d3.json("world.geojson", createMap);
function createMap(countries) {
d3.select("svg").selectAll("path")
.data(countries.features)
.enter()
.append("path")
.attr("d", geoPath)
.attr("class", "countries")
}
</script>
</html>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js