【发布时间】:2015-01-30 01:03:13
【问题描述】:
我通过以下方式预测国家边界:
d3.json("./admin_0.topo.json", function(error, json) {
var L0 = json.objects.admin_0;
//inland borders lines
svg.append("g").attr("id","border")
.attr("style", mesh)
.selectAll("path")
.data([topojson.mesh(json, L0, function(a, b) { return a !== b; })])
.enter().append("path")
.attr("d", path);
//coast lines
svg.append("g").attr("id","coast")
.attr("style", coast)
.append("path")
.datum(topojson.mesh(json, L0, function(a, b) { return a == b; }))
.attr("d", path);
});
一些边框svg线无缘无故地连接到其他的:
放大时:
注意:海岸线和封闭的多边形都不会被弄乱。我通过npm topojson 和自然地球形状文件生成了这些数据。黄色的印度(巴基斯坦、尼泊尔、柬埔寨边界)周围似乎也缺少二分之一的国际边界。
# Download (not tested)
curl https://github.com/nvkelso/natural-earth-vector/raw/master/10m_cultural/ne_10m_admin_0_countries.shp
# shp2topojson:
topojson \
--id-property name \
-p name=name \
-q 1e4 \
--filter=small \
-o admin_0.topo.json \
-- admin_0=ne_10m_admin_0_countries.shp
什么是窃听?我该如何解决?
Demo、#Mesh,可能与:D3js SVG open lines display a fill artifact, how to fix it? & "stroke-dasharray:x,y;" mess up svg path? (Chrome) 有关。
【问题讨论】:
-
如果你使用
topojson.feature而不是mesh,它是否有效? -
@LarsKotthoff:
data(topojson.feature(json,L0).features)有效,没有人工制品。那失去了内陆弧过滤,我不能总是被蓝色海岸线覆盖。政治边界线可能大于海岸线。 注意:黄色印度周围没有国际边界(巴基斯坦、尼泊尔、柬埔寨边界)。 -
我的理解是数据是正确的,mesh做错了。
-
好吧,看起来所有国家都出于某种原因都在一条道路上。你检查了
topojson.mesh()的输出,看看是不是这样? -
好的,Mesh 输出单个 MultiLineString 对象
{type: "MultiLineString", coordinates: Array[ [...],[...],...,[...] ]}。而.datum() handle single objects fine,.data()` 需要一个网格不提供的对象数组(我们的线)。如果我想通过网格过滤内陆线路,我必须坚持使用.datum()。如果我不使用网格,我可以切换到.data()。
标签: svg d3.js topojson stroke-dasharray