Skip to content

Instantly share code, notes, and snippets.

@AnaMal08
Last active March 30, 2017 22:18
Show Gist options
  • Save AnaMal08/629e228d2e1b8be7a50b8cceafe3bef7 to your computer and use it in GitHub Desktop.
Save AnaMal08/629e228d2e1b8be7a50b8cceafe3bef7 to your computer and use it in GitHub Desktop.
Homework 7
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path.counties, path.county-border {
fill: none;
stroke: #000;
stroke-opacity: .2;
}
path.state {
fill: none;
stroke: #000;
}
path.quake, circle.quake {
fill: crimson;
fill-opacity: 0.4;
}
</style>
<svg width="960" height="960"></svg>
<script src="//d3js.org/d3.v4.min.js"></script>
<script src="//d3js.org/d3-tile.v0.0.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var pi = Math.PI,
tau = 2 * pi;
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var projection = d3.geoMercator()
.scale((1 << 15) / tau)
.translate([width / 2, height / 2])
.center([-98.5355, 32.965]);
var path = d3.geoPath()
.projection(projection);
d3.json("ok-counties.json", function(error, ok) {
if (error) throw error;
var tiles = d3.tile()
.size([width, height])
.scale(projection.scale() * tau)
.translate(projection([0, 0]))
();
svg.selectAll("image")
.data(tiles)
.enter().append("image")
.attr("xlink:href", function(d) { return "http://" + "abc"[d[1] % 3] + ".tile.openstreetmap.org/" + d[2] + "/" + d[0] + "/" + d[1] + ".png"; })
.attr("x", function(d) { return (d[0] + tiles.translate[0]) * tiles.scale; })
.attr("y", function(d) { return (d[1] + tiles.translate[1]) * tiles.scale; })
.attr("width", tiles.scale)
.attr("height", tiles.scale);
svg.append("path")
.attr("translate", "path.counties")
.datum(topojson.mesh(ok, ok.objects.ok))
.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