gpt4 book ai didi

javascript - 如何使用 d3.data().enter().call()

转载 作者:行者123 更新时间:2023-11-30 18:28:15 25 4
gpt4 key购买 nike

我正在尝试将 d3 项目与开放层项目链接起来。我想要做的是使用 d3 来查明给定节点是否存在于我的 DOM 中。

如果存在,我会使用转换。如果它不存在,我需要通过 openlayers API 插入节点。这是必需的,因为节点已在 openlayers 中注册。我最初的想法是调用 d3.data().enter().call(myInsertFunction())但这似乎不起作用。我希望有人能帮助我或指出正确的方向。我是 d3 库的新手。

function insertNewFeature(d) {
var word = d;
var pixel = new OpenLayers.Pixel(word.x,word.y);
var lonlat = map.getLonLatFromPixel(pixel);
var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
var feature = new OpenLayers.Feature.Vector(point);
feature.id = word.city+'_'+word.text,
feature.attributes = {
text: word.text,
sentiment: word.sentiment,
count: word.count
};
feature.style = {
label: word.text,
labelAlign: 'mm',
fontColor: word.color,
fontFamily: word.font,
fontSize: word.size,
rotation: word.rotate,
strokeColor: '#FFFFFF',
strokeWidth: 1,
strokeOpacity: 0.5
}
svgLayer.addFeatures([feature]);
}


function update(data)
{
var text = d3.select("OpenLayers.Layer.Vector_4_troot").selectAll("text").data(data, function(d) { return d.cityCode + "_" + d.text.toLowerCase() });

text.transition()
.duration(1000)
.attr("transform", function(d) { return "translate(" + [ d.x , d.y ] + ")rotate(" + d.rotate + ")"; });
//text.style("font-size", function(d) { return d.size + "px"; });
text.enter().call(insertNewFeature());

}

最佳答案

试试这个 jsfiddle:http://jsfiddle.net/Q8b2z/

我不确定为什么,但您不能对 text.enter() 的结果调用 call。相反,它应该可以调用类似的 insertNewFeature(text.enter())

关于javascript - 如何使用 d3.data().enter().call(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10281997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com