Skip to content

Instantly share code, notes, and snippets.

@arrayjam
Created September 29, 2013 17:19
Show Gist options
  • Save arrayjam/6754483 to your computer and use it in GitHub Desktop.
Save arrayjam/6754483 to your computer and use it in GitHub Desktop.
Topojson voronoi problem
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
stroke-linejoin: round;
fill: none;
}
.topojson {
stroke: #222;
}
.geojson {
stroke: red;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 600;
var ausCenter = [144.9, -37.8];
var parallels = [-36, -18];
var projection = d3.geo.albers()
.translate([width / 2, height / 2])
.scale(171600)
.rotate([-ausCenter[0], 0])
.center([0, ausCenter[1]])
.parallels(parallels)
.precision(0);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var zoom = d3.behavior.zoom()
.translate(projection.translate())
.scale(projection.scale())
.on("zoom", zoomed);
svg.call(zoom);
d3.json("voronoi.topo.json", function(err, topo) {
svg.append("path")
.datum(topojson.mesh(topo, topo.objects.voronoi))
.attr("class", "topojson")
.attr("d", path);
});
function zoomed() {
projection
.translate(d3.event.translate)
.scale(d3.event.scale);
svg.selectAll("path").attr("d", path);
}
</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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment