Skip to content

Instantly share code, notes, and snippets.

@jasondavies
Forked from mbostock/.block
Created September 14, 2012 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jasondavies/3721735 to your computer and use it in GitHub Desktop.
Save jasondavies/3721735 to your computer and use it in GitHub Desktop.
Antemeridian Cutting

D3 2.11’s d3.geo.path will automatically cut features for any aspect. Try dragging to rotate the world and see a new aspect.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.background {
fill: #a4bac7;
}
.foreground {
fill: none;
stroke: #333;
stroke-width: 1.5px;
}
.graticule {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
.graticule:nth-child(2n) {
stroke-dasharray: 2,2;
}
.land {
fill: #d7c7ad;
stroke: #766951;
}
.boundary {
fill: none;
stroke: #a5967e;
}
svg {
cursor: move;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.albers().translate([width / 2 - .5, height / 1.75 - .5]).scale(120),
path = d3.geo.path().projection(projection),
graticule = d3.geo.graticule();
var svg = d3.select("body").append("svg")
.datum({x: 0, y: 0})
.attr("width", width)
.attr("height", height)
.call(d3.behavior.drag()
.origin(Object)
.on("drag", function(d) {
d.x = d3.event.x;
d.y = d3.event.y;
projection.rotate([d.x, -d.y, 0]);
svg.selectAll("path").attr("d", path);
}));
svg.append("rect")
.attr("class", "background")
.attr("width", width)
.attr("height", height);
svg.selectAll(".graticule")
.data(graticule.lines)
.enter().append("path")
.attr("class", "graticule")
.attr("d", path);
d3.json("/d/3682676/readme-boundaries.json", function(err, collection) {
svg.insert("g", ".graticule")
.attr("class", "boundary")
.selectAll("path")
.data(collection.geometries)
.enter().append("path")
.attr("d", path);
});
d3.json("/d/3682676/readme-land.json", function(err, collection) {
svg.insert("g", ".graticule,.boundary")
.attr("class", "land")
.selectAll("path")
.data(collection.geometries)
.enter().append("path")
.attr("d", path);
});
</script>
@0NEMEDIA
Copy link

0NEMEDIA commented Feb 2, 2017

Hey Jason Davies, i've been working on this very project in another language.
Could we collaborate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment