我的目标是使用 d3 为给定 GeoJSON 特征集合中的每个特征生成 svg 路径。
当我使用传单映射路径时,所有功能看起来都很完美。
d3.json("ct_counties.geo.json", function(data) {
    var leaflet_paths = leaflet_map.addLayer(new L.GeoJSON(data));
});

但是当我使用 d3 映射路径时,某些功能看起来是错误的。
d3.json("ct_counties.geo.json", function(collection) {
    var bounds = d3.geo.bounds(collection);
    var path = d3.geo.path().projection(project);
    var feature = g.selectAll("path")
        .data(collection.features)
      .enter().append("path")
        .attr('class','county');
    d3_map.on("viewreset", reset);
    reset();
    function project(x) {
      var point = d3_map.latLngToLayerPoint(new L.LatLng(x[1], x[0]));
      return [point.x, point.y];
    }
    function reset() {
      var bottomLeft = project(bounds[0]); 
      var topRight = project(bounds[1]);
      svg.attr("width", topRight[0] - bottomLeft[0])
        .attr("height", bottomLeft[1] - topRight[1])
        .style("margin-left", bottomLeft[0] + "px")
        .style("margin-top", topRight[1] + "px");
      g.attr("transform", "translate(" + -bottomLeft[0] + "," + -topRight[1] + ")");
      feature.attr("d", path);
    }
});
在此处查看地图差异。
并参考这里的完整代码。
既然两张图都使用同一个特征集合,为什么d3版本会出错呢?
