D3: Merge interior svg paths?

前端 未结 1 1573
梦毁少年i
梦毁少年i 2020-12-29 05:40

I have an svg element composed of many different path objects, each of which represents one U.S state.

相关标签:
1条回答
  • 2020-12-29 06:42

    Assuming you can ignore the stated restriction of manipulating an existing SVG image (which seems like an arbitrary restriction given the ready availability of cartographic boundaries in more easy-to-manipulate formats…), you can use topojson.mesh to merge multiple polygons. Though, note this approach has a few limitations as described in this example:

    Another simple approach is to just draw the highlighted polygons twice: once with a thick black stroke and no fill, and a second time on top with orange fill and no stroke. This achieves the same effect without any need for topological manipulation:

    I suppose if you really had to, you could reach into the SVG element and do the same thing by extracting the vector data, but it will be easier if you start from clean data.

    0 讨论(0)
提交回复
热议问题