【发布时间】:2016-04-10 06:29:58
【问题描述】:
在下面的示例中,我看到当用户选择一个国家/地区时,地球会旋转并以该国家/地区为中心。我如何对其进行编码,以便在单击一个国家/地区时,地球以该国家/地区为中心?
我曾尝试在鼠标悬停事件之前添加一个单击处理程序,但它似乎不起作用。有什么想法吗?
.on("click", function(d) {
var rotate = projection.rotate(),
focusedCountry = country(countries, this),
p = d3.geo.centroid(focusedCountry);
svg.selectAll(".focused").classed("focused", focused = false);
//Globe rotating
(function transition() {
d3.transition()
.duration(2500)
.tween("rotate", function() {
var r = d3.interpolate(projection.rotate(), [-p[0], -p[1]]);
return function(t) {
projection.rotate(r(t));
svg.selectAll("path").attr("d", path)
.classed("focused", function(d, i) { return d.id == focusedCountry.id ? focused = d : false; });
};
})
})();
})
【问题讨论】:
标签: javascript jquery d3.js