且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

D3添加标线和geojson

更新时间:2023-12-05 16:10:40

如果您首先绘制网格,则第一个功能不会显示,因为您选择的是path s,其中网格是其中的一个.这意味着第一个数据元素(即第一个要素)与现有路径匹配,而不是.enter()选择的一部分.

The first feature doesn't show up if you're drawing the grid first because you're selecting paths, of which the grid is one. This means that the first data element (i.e. the first feature) is matched to the existing path and not part of the .enter() selection.

要解决此问题,只需为您的功能path s分配一个类,然后进行相应选择:

To fix this, simply assign a class to your feature paths and select accordingly:

aSVG.selectAll("path.feature")
    .data(json.features)
    .enter()
    .append("path")
    .attr("class", "feature")
    .attr("d", path);