为何D3无法正确渲染该GeoJSON文件?
提问:为何D3无法正确渲染该GeoJSON?
以下是我的代码,目前D3无法正确渲染这份GeoJSON,求各位帮忙定位原因:
<!DOCTYPE html> <meta charset="utf-8"> <body> <svg width="960" height="720"></svg> <div id='neighborhoodPopover'> </div> <script src="https://d3js.org/d3.v4.min.js"></script> <script src="https://d3js.org/topojson.v1.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/d3-array@3"></script> <script src="https://cdn.jsdelivr.net/npm/d3-geo@3"></script> <script src="https://cdn.jsdelivr.net/npm/d3-geo-projection@4"></script> <script> var svg = d3.select("svg"), width = +svg.attr("width"), height = +svg.attr("height"); const nycGeoJson = { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "neighborhood": "Hamilton Heights", "boroughCode": null, "borough": null, "@id": null }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -73.96083942042421, 40.81944719738439 ], [ -73.95280837990867, 40.81581771326914 ], [ -73.9527010915481, 40.81654806965256 ], [ -73.95171403863061, 40.8179276097718 ], [ -73.95072698571312, 40.81844695861872 ], [ -73.94803047114694, 40.8221363829966 ], [ -73.94612073832833, 40.82127625710196 ], [ -73.94475459746901, 40.82419761694012 ], [ -73.94385337524001, 40.82387305252829 ], [ -73.93918905697315, 40.82999573657146 ], [ -73.948905, 40.83406600000012 ], [ -73.949342, 40.833982 ], [ -73.95015520996616, 40.83439675981593 ], [ -73.95725896977153, 40.82711730987318 ], [ -73.96127700238141, 40.82169843098817 ], [ -73.96083942042421, 40.81944719738439 ] ] ] }, "id": 169 } ] }; const projection = d3.geoAlbers() .fitSize([width, height], nycGeoJson); var path = d3.geoPath() .projection(projection); svg.selectAll("path") .data(nycGeoJson.features) .enter().append("path") .attr("d", path) </script> </body>
当前渲染结果(非正确路径):
正确效果应为:
原地图中的多个要素均出现此问题,推测是D3渲染地图数据的方式导致的异常,但无法定位具体原因,其他地图渲染库可正常渲染该GeoJSON。恳请各位提供相关见解,感谢您的时间与关注。
内容的提问来源于stack exchange,提问作者jbeard4
相关产品推荐
相关产品推荐

