使用 d3.js 的 v3,我在使用 geoJSON 数据绘制 map 时遇到问题。代码和生成的 map 显示在:http://bl.ocks.org/73833ec90a8a77b0e29f .此示例使用 d3.js 的 v2 生成正确的 map 。
我不想将我的 map 的坐标转换为 lon,lat 坐标,因为 map 已经按照我想要的方式投影了,据我所知,这不是一个微不足道的投影。
如果问题确实是由重采样引起的,我想禁用重采样。但是,在文档中我真的找不到如何做到这一点。我可以传递一个流对象,而不是将投影函数传递给 d3.geo.path.projection()。我认为以下方法可行:
var projection = d3.geo.projection(function(x, y) {
return [ scale*(x-xmin), height-scale*(y-ymin) ];
}).precision(0);
但事实并非如此。可能也与我没有经纬度坐标有关。如何使用自定义投影功能禁用重采样?
或者当其他原因导致问题时,我想听听。
谢谢。
最佳答案
我最近遇到了同样的问题。
这样做的方法是明确告诉 d3 您不想要投影。
答案就在这个link .
"If projection is null, the path uses the identity transformation, where the input
geometry is not projected and is instead rendered directly in raw coordinates. This can be
useful for fast rendering of already-projected geometry, or for fast rendering of the
equirectangular projection."
所以你想拥有
var path = d3.geo.path().projection(null);
然后,像这样的事情
g.selectAll("path")
.data(json.features)
.enter().append("path")
.attr("d", path)
关于d3.js - 在 d3.js 中绘制已经投影的 geoJSON map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14646656/