A demo of Mike Bostock’s TopoJSON using states & provinces boundaries from Natural Earth.
With simplification turned on (-s 100
), this reduces the original 57MB GeoJSON file to a mere 515KB!
xxxxxxxxxx
<meta charset="utf-8">
<style>
path {
fill: none;
stroke: #000;
}
.graticule {
fill: none;
stroke: #ccc;
stroke-width: .5px;
}
.foreground {
fill: none;
stroke: #333;
stroke-width: 1.5px;
}
</style>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="topojson.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.orthographic()
.scale(250)
.clipAngle(90);
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule();
var λ = d3.scale.linear()
.domain([0, width])
.range([-180, 180]);
var φ = d3.scale.linear()
.domain([0, height])
.range([90, -90]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.on("mousemove", function() {
var p = d3.mouse(this);
projection.rotate([λ(p[0]), φ(p[1])]);
svg.selectAll("path:not(.foreground)").attr("d", path);
});
svg.append("path")
.attr("class", "graticule")
.datum(graticule)
.attr("d", path);
svg.append("path")
.datum(graticule.outline)
.attr("class", "foreground")
.attr("d", path);
d3.json("readme-world-admin1.json", function(error, topology) {
svg.append("path")
.datum(topojson.mesh(topology))
.attr("d", path);
});
</script>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js