admin管理员组

文章数量:1429844

Question :

I want to remove overlaps from existing polygons with javascript.

I guess merging overlapping polygons to single polygon is the easiest way to do this but i don't know how to do this.

Question :

I want to remove overlaps from existing polygons with javascript.

I guess merging overlapping polygons to single polygon is the easiest way to do this but i don't know how to do this.

Share Improve this question edited Apr 13, 2020 at 12:33 Utku asked Nov 3, 2015 at 15:21 UtkuUtku 3004 silver badges19 bronze badges 1
  • Just wondering if there is some simpler workaround. Is the main aim trying to get the polygons together as one, or is that a workaround for something else you are trying to achieve, if so, whats that ? – Ian Commented Nov 4, 2015 at 8:22
Add a ment  | 

2 Answers 2

Reset to default 3

You need to implement Vatti's algorithm or use some polygon library which realizes it (or other reliable algo).

Clipper library uses this algorithm, but seems it has not JavaScript binding yet.

Javascript port exists for GPC (sometimes less robust)

Since @MBo's answer is out of date, here is a new answer. The math has already been written down in JavaScript:

  • polygon-clipping
  • martinez-polygon-clipping

polygonClipping.union(triangle, hexagon, house, diamond) (from the first package) returns the polygons like in your question.

本文标签: javascriptMerging intersecting polygons to single polygonStack Overflow