Skip to content

Instantly share code, notes, and snippets.

@arrayjam
Last active December 24, 2015 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arrayjam/6794082 to your computer and use it in GitHub Desktop.
Save arrayjam/6794082 to your computer and use it in GitHub Desktop.
Australia polling booth voronoi and ocean overlay
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
stroke-linejoin: round;
fill: none;
}
.topojson {
stroke: #222;
}
.voronoi {
stroke: none;
}
.geojson {
stroke: red;
}
.ocean {
fill: steelblue;
}
</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(20000)
.rotate([-ausCenter[0], 0])
.center([0, ausCenter[1]])
.parallels(parallels)
.clipExtent([[0, 0], [width, height]])
.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);
queue()
.defer(d3.json, "voronoi.json")
.defer(d3.json, "ocean.json")
.await(ready);
function ready(err, geo, ocean) {
window.geo = geo;
console.log(geo);
svg.selectAll("path.geojson")
.data(topojson.feature(geo, geo.objects.voronoi).features)
.enter().append("path")
.attr("class", "geojson")
.attr("d", path);
svg.append("path")
.datum(topojson.feature(ocean, ocean.objects.ocean))
.attr("class", "ocean")
.attr("d", path);
console.log(ocean);
}
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
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