Skip to content

Instantly share code, notes, and snippets.

@zackbatist
Last active August 29, 2015 14:00
Embed
What would you like to do?
Map of countries in M.A. Thesis
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.subunit.TUR { fill: #acb; }
.subunit.SYR { fill: #cab; }
.subunit.IRQ { fill: #abd; }
.subunit.LBN { fill: #cba; }
.subunit.ISR { fill: #abc; }
.subunit.JOR { fill: #bac; }
.subunit.IRN { fill: #daa; }
.subunit.ARM { fill: #dcc; }
.subunit.AZE { fill: #abb; }
.subunit.CYP { fill: #cca; }
.subunit-label {
fill: #666;
fill-opacity: 1;
font-size: 10px;
font-weight: 500;
text-anchor: middle;
}
body {
background-color:#888;
}
</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 = 500,
centered;
var projection = d3.geo.mercator()
.center([44, 34])
.scale(200 * 7)
.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("map.json", function(error, map) {
svg.selectAll(".subunit")
.data(topojson.feature(map, map.objects.map).features)
.enter().append("path")
.attr("class", function(d) { return "subunit " + d.id; })
.attr("d", path);
svg.selectAll(".subunit-label")
.data(topojson.feature(map, map.objects.map).features)
.enter().append("text")
.attr("class", function(d) { return "subunit-label " + d.id; })
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("dy", ".35em")
.text(function(d) { return d.properties.name; });
});
/* JavaScript goes here. */
</script>
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