path.centroid错误:路径未定义

时间:2013-10-04 17:56:33

标签: d3.js

我还在处理我的项目。 我尝试从geojson文件向地图添加一些圆圈,圆圈添加路径的中心。 我的Webinspektor说路径未定义:-(我认为他是对的,但我不明白为什么。 谢谢你的帮助。

以下是代码:

overlayBeschaeftigte.afterAdd = function () {
                    var div = d3.selectAll("#" + overlayBeschaeftigte.div.id);
                        //get the vector layer div element

                    div.selectAll("svg").remove();                  //remove the existing svg element and create a new one

                    var svg = div.append("svg");

                    var group = svg.append("g");
                    var bounds = d3.geo.bounds(collection);

                    var path = d3.geo.path()
                        .projection(project);

                    var feature  = group.selectAll("path")
                        .data(collection.features)
                        .enter()
                        .append("path")
                    group.selectAll("circle")
                        .data(collection.features)
                        .enter()
                        .append("circle")
                        .attr('cx', function(d) {
                             var x = path.centroid(d)[0];
                             return x;

                        })
                        .attr('cy', function(d) {
                             var y = path.centroid(d)[1];
                             return y;
                        })
                        .attr('r', 15)
                        .style("fill", "yellow")
                        .style("opacity", 0.75) 
                }

0 个答案:

没有答案