2014-05-08 19 views
1

wiki說:topojson中的merge/mesh和mergeArcs/meshArcs有什麼區別?

相當於topojson.merge/.mesh,但返回TopoJSON的MultiPolygon/MULTILINESTRING對象,而不是GeoJSON的。

但這是什麼意思?什麼是TopoJSON MultiPolygon/MultiLineString對象的一個​​很好的使用示例返回?我試圖取代:

topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; })

...有:

topojson.meshArcs(world, world.objects.countries, function(a, b) { return a !== b; })

...但是從d3.js得到了錯誤Uncaught TypeError: Cannot read property 'length' of undefined

回答

6

區別在於合併和網格返回的GeoJSON要素可以傳遞給d3.geo.path以使用SVG路徑元素顯示在屏幕上。相比之下,mergeArcs和meshArcs會返回拓撲,這些拓撲需要傳遞迴topojson.feature以傳遞給要顯示的d3.geo.path。

你會使用mergeArcs和meshArcs的原因是你想對你的數據執行更多的拓撲函數,比如合併它們或者尋找鄰居。