xxxxxxxxxx
<meta charset="utf-8">
<style>
/*path {
fill: none;
stroke: #000;
stroke-linejoin: round;
stroke-linecap: round;
}
*/
.subunit {
fill: #777;
}
.country {
stroke: #fff;
fill: none;
}
/*
*/
</style>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 600;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("croatiatopo.json", function(error, cro) {
if (error) return console.error(error);
var subunits = topojson.feature(cro, cro.objects.croatia);
var projection = d3.geo.mercator()
.center([15, 37.5]) // x to left, y to bottom
.scale(5400)
.translate([width / 3, height * 2]);
var path = d3.geo.path()
.projection(projection);
zupanije = svg.selectAll(".subunit")
.data(topojson.feature(cro, cro.objects.croatia).features)
.enter().append("path")
.attr("class", function(d) { /* console.log(d);*/ return "subunit " + d.properties.HASC_1.substr(3,2); }) //str.substr(start[, length])
.attr("d", path);
zupanije.append("title")
.text(function(d, i) { return d.properties.NAME_1; });
zupanije.on("mouseover", function (d, i) {
d3.select(this).style("fill", "steelblue"); // .attr("transform", "translate(5,5)");
//console.log(d.properties.NAME_1);
});
zupanije.on("mouseout", function (d, i) {
d3.select(this).style("fill", "#777");
});
svg.append("path")
.datum(subunits)
.attr("d", path)
.attr("class", "country");
});
d3.select(self.frameElement).style("height", height + 80 + "px");
</script>
Modified http://d3js.org/d3.v3.min.js to a secure url
Modified http://d3js.org/topojson.v1.min.js to a secure url
https://d3js.org/d3.v3.min.js
https://d3js.org/topojson.v1.min.js