Skip to content

Instantly share code, notes, and snippets.

@fccoelho
Created November 27, 2012 23:09
Show Gist options
  • Save fccoelho/4157853 to your computer and use it in GitHub Desktop.
Save fccoelho/4157853 to your computer and use it in GitHub Desktop.
D3.js map choroplethmap
<script src="/js/d3.v2.js"></script>
<link type="text/css" rel="stylesheet" href="/css/colorbrewer/colorbrewer.css">
<style type="text/css">
svg {
background: #eee;
width: 960px;
height: 500px;
}
#polygons path {
stroke: #fff;
stroke-width: .25px;
}
</style>
<script type="text/javascript">
var map = {{ simulation.map }}
var svg = d3.select("#map_div")
.append("svg")
.call(d3.behavior.zoom()
.on("zoom", redraw))
.append("g");
var polygons = svg.append("g")
.attr("id", "polygons")
.attr("class","Blues");
var proj = d3.geo.mercator();
proj.translate(-43.8,-23.2).scale(10);
var path = d3.geo.path().projection(proj);
function draw (json) {
polygons.selectAll("path")
.data(json.features)
.enter().append("path")
.attr("d", path)
};
function redraw() {
svg.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
}
draw(map);
</script>
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.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment