Last active
August 29, 2015 14:03
-
-
Save stephanebachelier/49771f8d01167e5bd945 to your computer and use it in GitHub Desktop.
This file contains 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> | |
.state { | |
fill: #ccc; | |
} | |
.state-boundary { | |
fill: none; | |
stroke: #fff; | |
} | |
.state.selected { | |
fill: orange; | |
stroke: #000; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 960, | |
height = 600; | |
var projection = d3.geo.mercator() | |
.scale(800) | |
.translate([width / 2, height / 2]); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("./data.json", function(error, countries) { | |
svg.append("path") | |
.datum(topojson.feature(countries, countries.objects.ne_10m_admin_0_countries)) | |
.attr("class", "state") | |
.attr("d", path); | |
svg.append("path") | |
.datum(topojson.mesh(countries, countries.objects.ne_10m_admin_0_countries, function(a, b) { return a !== b; })) | |
.attr("class", "state-boundary") | |
.attr("d", path); | |
svg.append("path") | |
.datum(topojson.merge(countries, countries.objects.ne_10m_admin_0_countries.geometries.filter(function(g) { | |
return g.properties.ISO_A3 in ['SSD', 'SDN']; | |
}))) | |
.attr("class", "state selected") | |
.attr("d", path); | |
}); | |
d3.select(self.frameElement).style("height", height + "px"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment