【问题标题】:topojson.mesh outputting incorect path? (stroke-dasharray)topojson.mesh 输出不正确的路径? (笔划破折号)
【发布时间】: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


【解决方案1】:

错误实际上是由于 `style="stroke-dasharray:4,4;"在 Chrome 浏览器上。 "stroke-dasharray:x,y;" mess up svg path? (Chrome)

【讨论】:

    猜你喜欢
    • 2022-11-22
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 2015-11-29
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多