我正在使用D3和D3.geo.projection创建一个简单的世界地球仪界面,上面有数据点,可以旋转。当我只是用圆形绘制点时,一切都很正常(即当它们在地平线后面旋转时,点被“遮蔽”)。
svg.append("g")
.attr("class","points")
.selectAll("text")
.data(places.features)
.enter()
//for circle-point------------------------------
.append("path")
.attr("d", path.pointRadius(function(d) {
if (d.properties)
return 3+(4*d.properties.scalerank);
}))
.attr("d", path)
.attr("class", "point")
.on("click",pointClick)
;
但是现在我想绘制符号而不是圆:
svg.append("g")
.attr("class","points")
.selectAll("text")
.data(places.features)
.enter()
//for image-------------------------------------
.append("image")
.attr("xlink:href", "img/x_symbol.png")
.attr("x", -12)
.attr("y", -12)
.attr("width", 24)
.attr("height", 24)
.attr("transform", function(d) {
return "translate(" + projection([
d.properties.longitude,
d.properties.latitude
]) + ")"
})
.attr("class", "point")
.on("click",pointClick)
;
虽然现在它能正常工作,而且符号也能正确地绘制在地球上,但即使当它们跨越到地球的背面时仍会保留。 如果我有一个方法来确定它们是否被遮挡,我可以使用可见性属性将它们隐藏起来,但我没有看到d3.geo.projection中有这样的方法。您有什么想法吗?
pointRadius
属性,我仍然需要调用.attr("d", path)
。省略那行代码对点样式渲染没有影响。 我不确定是否可以将相关部分提取到 fiddle 中。它依赖于两个数据 JSON 和几个 CSS。 - Craig Soich