Skip to content

Instantly share code, notes, and snippets.

@blech
Forked from mbostock/.block
Last active December 19, 2015 12:19
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 blech/5953864 to your computer and use it in GitHub Desktop.
Save blech/5953864 to your computer and use it in GitHub Desktop.
SF: buildings & railways
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
margin: 0;
}
path {
fill: none;
stroke: none;
stroke-linejoin: round;
stroke-linecap: round;
}
.rail { stroke: #ecc; }
.buildings path { stroke: #ccc; stroke-width: 1px; fill: none; }
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.tile.v0.min.js"></script>
<script>
var width = Math.max(960, window.innerWidth),
height = Math.max(500, window.innerHeight);
var tiler = d3.geo.tile()
.size([width, height]);
var projection = d3.geo.mercator()
.center([-122.405, 37.79])
.scale((1 << 23) / 2 / Math.PI)
.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)
.call(renderTiles, "highroad")
.call(renderTiles, "buildings");
function renderTiles(svg, type) {
svg.append("g")
.attr("class", type)
.selectAll("g")
.data(tiler
.scale(projection.scale() * 2 * Math.PI)
.translate(projection([0, 0])))
.enter().append("g")
.each(function(d) {
var g = d3.select(this);
d3.json("http://" + ["a", "b", "c"][(d[0] * 31 + d[1]) % 3] + ".tile.openstreetmap.us/vectiles-" + type + "/" + d[2] + "/" + d[0] + "/" + d[1] + ".json", function(error, json) {
g.selectAll("path")
.data(json.features.sort(function(a, b) { return a.properties.sort_key - b.properties.sort_key; }))
.enter().append("path")
.attr("class", function(d) { return d.properties.kind; })
.attr("d", path);
});
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment