Skip to content

Instantly share code, notes, and snippets.

@robinkraft
Created July 10, 2013 23:27
Show Gist options
  • Save robinkraft/5971160 to your computer and use it in GitHub Desktop.
Save robinkraft/5971160 to your computer and use it in GitHub Desktop.
Two geojson files (humid tropics and countries), grouped on map.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
stroke: white;
stroke-width: 0.25px;
fill: grey;
}
</style>
<body>
<!-- Inspiration: http://www.d3noob.org/2013/03/a-simple-d3js-map-explained.html and
http://knowledgestockpile.blogspot.com/2012/01/creating-svg-groups-using-d3js-example.html -->
<script src="http://d3js.org/topojson.v1.js"></script>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.azimuthalEqualArea()
.center([0, 0])
.scale(200)
.rotate([0,0]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var path = d3.geo.path()
.projection(projection);
var world = svg.append("svg:g");
var humid = svg.append("svg:g");
// load and display the humid tropical biome
d3.json("world.json", function(error, topology) {
world.selectAll("path")
.data(topojson.feature(topology, topology.objects.countries).features)
.enter()
.append("path")
.attr("d", path)
.style("stroke", "red")
});
d3.json("humid.json", function(error, topology) {
humid.selectAll("path")
.data(topojson.feature(topology, topology.objects.humid)
.features)
.enter()
.insert("path")
.attr("d", path)
.style("fill", "green")
});
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment