首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用d3.data().enter().call()

如何使用d3.data().enter().call()
EN

Stack Overflow用户
提问于 2012-04-23 21:58:34
回答 1查看 3K关注 0票数 1

我正在尝试将一个d3项目链接到一个打开的layers项目。我尝试做的是使用d3来查找DOM中是否存在给定的节点。

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

代码语言:javascript
复制
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());

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-25 14:18:32

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

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10281997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档