Javascript 它太大了,地理质心很容易落在我在上面的评论中设置的基本排除半径内。嗯,这件事我得再考虑一下。 function position_labels() { var centerPos = projection.invert([width / 2,
它太大了,地理质心很容易落在我在上面的评论中设置的基本排除半径内。嗯,这件事我得再考虑一下。Javascript 它太大了,地理质心很容易落在我在上面的评论中设置的基本排除半径内。嗯,这件事我得再考虑一下。 function position_labels() { var centerPos = projection.invert([width / 2, ,javascript,d3.js,Javascript,D3.js,它太大了,地理质心很容易落在我在上面的评论中设置的基本排除半径内。嗯,这件事我得再考虑一下。 function position_labels() { var centerPos = projection.invert([width / 2, height / 2]); var arc = d3.geo.greatArc(); // update: update path projection before applying it to labels position
function position_labels() {
var centerPos = projection.invert([width / 2, height / 2]);
var arc = d3.geo.greatArc();
// update: update path projection before applying it to labels position
path.projection(projection);
svg.selectAll(".label")
.attr("transform", function(d) {
return "translate(" + path.centroid(d) + ")";
})
.style("display", function(d) {
var d = arc.distance({
source: path.centroid(d),
target: centerPos
});
return (d > 1.57) ? 'inline' : 'none';
})
}
.attr("id", function(d) { return d.properties.name.split(' ').join('_'); })
if (d3.select("#"+d.properties.name.split(' ').join('_')).attr('d') != null) {
return 'inline';
}
else {
return 'none';
}
.style("text-anchor","middle");
var country = d3.select("#"+d.properties.name.split(' ').join('_'));
// Exclude labels this far from center:
var r = 350;
// Check to see if the country has a path visible as before
if (country.attr('d') != null) {
// Then check to see if the bounding box
// for the country as drawn is far from center
var BB = country.node().getBBox();
var x = (BB.x + (BB.x + BB.width)) / 2;
var y = (BB.y + (BB.y + BB.height)) / 2;
if ( ( (width-x)*(width-x) + (height-y)*(height-y) ) < (r * r) ) {
// And ensure the geographic centroid is also not on the edge:
center = path.centroid(d);
x = center[0];
y = center[1];
if ( ( (width-x)*(width-x) + (height-y)*(height-y) ) < (r * r) ) {
return 'inline';
}
else {
return 'none';
}
}
else { return 'none'; }
else { return 'none'; }