Created
June 6, 2014 00:24
-
-
Save tonyta/1b5859cebab15274c859 to your computer and use it in GitHub Desktop.
Southeast Asia
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"> | |
<html> | |
<head> | |
<title></title> | |
<link rel="stylesheet" type="text/css" href="style.css" /> | |
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> | |
<script type="text/javascript" src="http://d3js.org/topojson.v1.min.js"></script> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script type="text/javascript" src="script.js"></script> | |
</body> | |
</html> |
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
var width = 960, | |
height = 800; | |
var svg = d3.select("div#map").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
d3.json("seasia.json", function(err, json) { | |
if (err) { | |
return console.log(err); | |
} | |
var subunits = topojson.feature(json, json.objects.subunits); | |
var places = topojson.feature(json, json.objects.places); | |
var projection = d3.geo.mercator() | |
.center([103.5,15]) | |
.scale(2200) | |
.translate([width / 2, height / 2]); | |
var path = d3.geo.path() | |
.projection(projection); | |
path.pointRadius(2); | |
svg.append("text") | |
.attr("class", "title") | |
.attr("transform", "translate("+width/2+",24)") | |
.attr("text-anchor", "middle") | |
.style("dominant-baseline", "hanging") | |
.text("Southeast Asia"); | |
svg.selectAll(".country") | |
.data(subunits.features) | |
.enter().append("path") | |
.attr("class", function(d) { return "country " + d.id; }) | |
.attr("d", path); | |
svg.append("path") | |
.datum(topojson.mesh(json, json.objects.subunits, function(a,b) { | |
return a !== b && a.id !== "VNM" && b.id !== "VNM"; | |
})) | |
.attr("d", path) | |
.attr("class", "country-boundary"); | |
svg.selectAll(".country-label") | |
.data(subunits.features) | |
.enter().append("text") | |
.attr("class", function(d) { return "country-label " + d.id }) | |
.attr("dy", ".35em") | |
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; }) | |
.attr("text-anchor", "middle") | |
.text(function(d) { return d.properties.name; }); | |
svg.append("path") | |
.datum(places) | |
.attr("d", path) | |
.attr("class", "city"); | |
svg.selectAll(".city-label") | |
.data(places.features) | |
.enter().append("text") | |
.attr("class", "city-label") | |
.attr("transform", function(d) { | |
return "translate(" + projection(d.geometry.coordinates) + ")"; | |
}) | |
.attr("x", function(d) { return d.geometry.coordinates[0] > 103 ? 6 : -6; }) | |
.style("text-anchor", function(d) { return d.geometry.coordinates[0] > 103 ? "start" : "end"; }) | |
.text(function(d) { return d.properties.name; }); | |
}); |
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
#map { | |
background-color: #333; | |
width: 960px; | |
font-family: "helvetica"; | |
} | |
.country.VNM { fill: #F44; } | |
.country.LAO { fill: #534; } | |
.country.KHM { fill: #523; } | |
.country.THA { fill: #512; } | |
.country-boundary { | |
fill: none; | |
stroke: #F44; | |
stroke-width: 2px; | |
stroke-dasharray: 2, 3; | |
stroke-linejoin: round; | |
} | |
.city-label { | |
font-size: 0.5em; | |
fill: #BBB; | |
} | |
.country-label { | |
font-size: 2em; | |
fill: #A33; | |
font-weight: bold; | |
} | |
.title { | |
font-size: 7em; | |
font-weight: 100; | |
fill: #222; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment