Dancing through the 1983 State Plane zone projections in the continental US.
xxxxxxxxxx
<meta charset="utf-8">
<style>
path {
stroke-linejoin: round;
fill: none;
stroke: #444;
stroke-width: 1px;
}
text {
font: 32px sans-serif;
font-weight: bold;
}
.highlight {
fill: #f0f;
stroke: none;
}
</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.14/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.20/topojson.min.js"></script>
<script>
var width = 960,
height = 500;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("stateplane.topo.json",function(err,stateplane){
var inner = topojson.mesh(stateplane,stateplane.objects.stateplane,function(a, b) { return a !== b; }),
zones = topojson.feature(stateplane,stateplane.objects.stateplane).features;
outer = topojson.merge(stateplane,stateplane.objects.stateplane.geometries);
zones.forEach(function(zone){
var fn = d3.geo[zone.properties.type]().rotate(zone.properties.rotate);
if (zone.properties.parallels) {
fn.parallels(zone.properties.parallels);
}
zone.properties.path = scaledPath(fn);
});
d3.shuffle(zones);
svg.append("path")
.attr("class","outer")
.datum(outer);
var highlight = svg.append("path")
.attr("class","highlight")
.datum(zones[0]);
svg.append("path")
.attr("class","inner")
.datum(inner);
var paths = d3.selectAll("path")
.attr("d",zones[0].properties.path);
var text = svg.append("text")
.attr("x",0)
.attr("y",height)
.attr("dy","-1em")
.text(zones[0].properties.name);
morph();
function morph() {
var current = zones[0],
next = zones.pop();
zones.unshift(next);
highlight.datum(next)
.attr("d",current.properties.path);
text.transition()
.delay(100)
.duration(0)
.each("end",function(){
text.text(next.properties.name);
});
paths.transition()
.delay(100)
.duration(1200)
.attr("d",next.properties.path)
.each("end",function(d,i){
if (i === 2) {
morph();
}
});
}
function scaledPath(projection) {
var p = d3.geo.path().projection(projection);
// Auto-scale a la https://bl.ocks.org/mbostock/4707858
projection
.scale(1)
.translate([0, 0]);
var b = p.bounds(outer),
s = .95 / Math.max((b[1][0] - b[0][0]) / width, (b[1][1] - b[0][1]) / height),
t = [(width - s * (b[1][0] + b[0][0])) / 2, (height - s * (b[1][1] + b[0][1])) / 2];
projection
.scale(s)
.translate(t);
return p;
}
});
</script>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.14/d3.min.js
https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.20/topojson.min.js