Last active
November 15, 2016 18:03
-
-
Save mbostock/1e32984cf0587a86c806779a5464b0cc to your computer and use it in GitHub Desktop.
Clipped Conic Conformal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 | |
border: no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<svg width="960" height="500"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://d3js.org/topojson.v2.min.js"></script> | |
<script> | |
var svg = d3.select("svg"), | |
width = +svg.attr("width"), | |
height = +svg.attr("height"); | |
var graticule = d3.geoGraticule().extentMajor([[-135, 0], [135, 90]]), | |
outline = graticule.outline(), | |
projection = d3.geoConicConformal().fitSize([width, height], outline), | |
path = d3.geoPath().projection(projection); | |
var defs = svg.append("defs"); | |
defs.append("path") | |
.attr("id", "extent") | |
.attr("d", path(outline)); | |
defs.append("clipPath") | |
.attr("id", "clip") | |
.append("use") | |
.attr("xlink:href", "#extent"); | |
var g = svg.append("g") | |
.attr("clip-path", "url(#clip)"); | |
g.append("path") | |
.attr("id", "graticule") | |
.attr("fill", "none") | |
.attr("stroke", "#777") | |
.attr("stroke-width", 0.5) | |
.attr("stroke-opacity", 0.5) | |
.attr("d", path(graticule())); | |
g.append("use") | |
.attr("fill", "none") | |
.attr("stroke", "#000") | |
.attr("xlink:href", "#extent"); | |
d3.json("https://d3js.org/world-50m.v1.json", function(error, world) { | |
if (error) throw error; | |
g.insert("path", "#graticule") | |
.attr("fill", "#222") | |
.attr("d", path(topojson.feature(world, world.objects.land))); | |
g.insert("path", "#graticule") | |
.attr("fill", "none") | |
.attr("stroke", "#fff") | |
.attr("stroke-width", 0.5) | |
.attr("d", path(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment