我正在使用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中看到這樣做的方法。有任何想法嗎?
不一定與你的問題,但也許會刺激你創建一個小提琴......我注意到你正在爲d的屬性使得兩個賦值你的圈子點......是隻是一個複製/粘貼問題或你的原始代碼? – FernOfTheAndes
啊,是的,@FernOfTheAndes,這顯然是一個多餘的線。我認爲自從我設置'pointRadius'屬性後,我仍然不得不調用'.attr(「d」,path)'。省略該行對點樣式呈現沒有影響。 我不確定我是否可以將相關部分提取到小提琴中。它依賴於兩個數據JSON和一些CSS。 –
@mbostock,也許你可以點亮一些光線?我可以使用.png圖像作爲d3.geo.orthographic投影上的點嗎? –