Created
July 10, 2013 23:27
-
-
Save robinkraft/5971160 to your computer and use it in GitHub Desktop.
Two geojson files (humid tropics and countries), grouped on map.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment