Skip to content

Instantly share code, notes, and snippets.

@mikeskaug
Last active October 26, 2015 20:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mikeskaug/4540864bb185987d5820 to your computer and use it in GitHub Desktop.
Shaded Relief with AlbersUsa Projection
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script>
</head>
<body>
<script type="text/javascript">
var w = 900;
var h = 500;
var projection = d3.geo.albersUsa()
.translate([w/2-100, h/2+20])
.scale([850]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h)
.append("g");
d3.json("us-land.json", function(error, us) {
if (error) throw error;
var defs = svg.append("defs");
defs.append("path")
.datum(topojson.feature(us, us.objects.land))
.attr("id", "land")
.attr("d", path)
.style("fill", "none");
svg.append("clipPath")
.attr("id", "clip1")
.attr("transform","translate(18,-48)")
.append("use")
.attr("xlink:href", "#land");
//append and clip the shaded relief bitmap
//scale factor and translation determined through trial and error
svg.append("image")
.attr("width", 900*0.8)
.attr("height", 600*0.8)
.attr("transform","translate(-18,48)")
.attr("clip-path", "url(#clip1)")
.attr("xlink:href", "lower48.png");
svg.append("clipPath")
.attr("id", "clip2")
.attr("transform","translate(-3,-368)")
.append("use")
.attr("xlink:href", "#land");
svg.append("image")
.attr("width", 300*0.62)
.attr("height", 202*0.62)
.attr("transform","translate(3,368)")
.attr("clip-path", "url(#clip2)")
.attr("xlink:href", "alaska.png");
svg.append("use")
.attr("xlink:href", "#land");
});
</script>
</body>
</html>
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