gpt4 book ai didi

javascript - d3.geoEquirectangular() 对 map 的渲染不一致

转载 作者:行者123 更新时间:2023-11-29 10:29:38 24 4
gpt4 key购买 nike

我最近使用 D3 制作了一些 map ,并且遇到了一些路径无法正确关闭的问题,如下面的第一个示例所示。我认为这是关于 -90 度纬度精度的某种数据问题,但我不确定如何验证这种怀疑。有趣的是,当我在页面上包含最新版本的 d3-geo 模块时, map 会按预期呈现(请参见下面的第二个示例)。这是怎么回事?

var svg = d3.select("#map").style("border","0px solid #000000");

var width = 600;
var height = 300;

var proj = d3.geoEquirectangular().scale(95).translate([300,150]);
var path = d3.geoPath(proj);

//countries from natural earth dataset
var url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_110m_admin_0_countries.geojson";

d3.json(url, function(err, json){

//draw paths once
svg.selectAll("path").data(json.features).enter().append("path")
.attr("d", path).attr("stroke","#00aaff");

});
<script src="https://d3js.org/d3.v4.min.js"></script>

<h2>Fig. 1 Multiple paths not closed properly</h2>

<svg width="600px" height="300px" id="map"></svg>

<p>Uses D3 Version 4.13.0</p>
<p>GeoJson data source: <a href="https://github.com/nvkelso/natural-earth-vector/tree/master/geojson">https://github.com/nvkelso/natural-earth-vector/tree/master/geojson</a></p>

var svg = d3.select("#map").style("border","0px solid #000000");

var width = 600;
var height = 300;

var proj = d3.geoEquirectangular().scale(95).translate([300,150]);
var path = d3.geoPath(proj);

//countries from natural earth dataset
var url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_110m_admin_0_countries.geojson";

d3.json(url, function(err, json){

//draw paths once
svg.selectAll("path").data(json.features).enter().append("path")
.attr("d", path).attr("stroke","#00aaff");

});
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-geo.v1.min.js"></script>

<h2>Fig. 2 Map renders as expected</h2>
<p>The only difference from above is the inclusion of <a href="https://d3js.org/d3-geo.v1.min.js">https://d3js.org/d3-geo.v1.min.js</a></p>

<svg width="600px" height="300px" id="map"></svg>

<p>Uses D3 Version 4.13.0</p>
<p>GeoJson data source: <a href="https://github.com/nvkelso/natural-earth-vector/tree/master/geojson">https://github.com/nvkelso/natural-earth-vector/tree/master/geojson</a></p>

最佳答案

我相信您引用的是 issue on github这与 d3 如何引用多边形有关。该问题可能会导致在某些投影上与南极重叠的多边形反转。

d3-geo.v1.min.js 的当前版本,位于 https://d3js.org/d3-geo.v1.min.js , 是 1.10,于 3 月发布。此版本实现了修复。最新版本的 d3v4(4.13) 于 1 月 29 日发布,因此不包含修复,因此发现了行为。

关于javascript - d3.geoEquirectangular() 对 map 的渲染不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49312172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com