私はd3プロジェクトを開いたレイヤプロジェクトにリンクしようとしています。私がしようとしているのは、d3を使用して、指定されたノードがDOMに存在するかどうかを調べることです。d3.data()の使い方enter()。call()
存在する場合は、トランジションを使用します。 存在しない場合は、openlayers API経由でノードを挿入する必要があります。これは、ノードがopenlayersで登録されている場合に必要です。私の最初の考えはd3.data().enter().call(myInsertFunction())の呼び出しを実行することでした。 これは動作していないようです。 私に助けてくれる人、または正しい方向に向ける人がいることを願っています。私はd3のlibにかなり新しいです。
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());
}
ありがとうございます!これは機能します。 – Bjarne77