Built with blockbuilder.org
forked from anonymous's block: fresh block
forked from EvertLagerberg's block: Brazil
forked from EvertLagerberg's block: Brazil
forked from EvertLagerberg's block: Russia
forked from EvertLagerberg's block: Russia
forked from EvertLagerberg's block: Russia
xxxxxxxxxx
<meta charset="utf-8">
<style>
.feature {
fill: #ccc;
}
.mesh {
fill: none;
stroke: #fff;
stroke-width: .5px;
stroke-linejoin: round;
}
.outline {
fill: #ddd;
stroke: #000;
stroke-width: 1.5px;
}
svg {
border:1px solid black
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 500,
height = 400;
var projection = d3.geo.mercator();
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("pl-topo.json", function(error, us) {
if (error) throw error;
var state = topojson.feature(us, us.objects.subunits);
//state = states.features.filter(function(d) { return d.id === 34; })[0];
console.log(projection);
projection
.scale(1)
.translate([0, 0]);
var b = path.bounds(state),
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);
svg.append("path")
.datum(topojson.mesh(us, us.objects.subunits, function(a, b) { return a !== b; }))
.attr("class", "mesh")
.attr("d", path);
svg.append("path")
.datum(state)
.attr("class", "outline")
.attr("d", path);
});
</script>
https://d3js.org/d3.v3.min.js
https://d3js.org/topojson.v1.min.js