Create a gist now

Instantly share code, notes, and snippets.

@hugolpz /README.md forked from mjhoy/README.md
Last active Aug 29, 2015

Raster clipping via D3js
<!doctype html>
<meta charset='utf-8'>
<title>Lake Superior</title>
<style>
.lake {
stroke: none;
fill: none;
}
</style>
<svg></svg>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<script>
var width = 960,
height = 500,
svg = d3.select("svg").attr("width", width).attr("height", height);
var projection = d3.geo.albers()
.rotate([88.1, 0])
.center([0, 47.7])
.parallels([45.5, 49.8])
.scale(9600)
var path = d3.geo.path()
.projection(projection);
d3.json("lakes-topo.json", function(error, data) {
var lakes = topojson.object(data, data.objects.lakes);
svg.append("image")
.attr("xlink:href", "hill-relief.jpg")
.attr("width", width)
.attr("height", height)
.attr("class", "bg");
svg.selectAll(".lake")
.data(lakes.geometries)
.enter().append("path")
.attr("d", path)
.attr("class", "lake")
.attr("id", "superior"); // There is only one lake in this set.
svg.append("clipPath")
.attr("id", "clip")
.append("use")
.attr("xlink:href", "#superior");
svg.append("image")
.attr("clip-path", "url(#clip)")
.attr("xlink:href", "superior.jpg")
.attr("width", width)
.attr("height", height)
.attr("class", "bg");
});
</script>
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