How to get the intersecting polygon of two polygons? (using JSTS intersection)

I want to intersect two polygons within an OpenLayers layer. I found the JSTS library, which should be able to intersect two polygons, and return the new created polygon of the intersection. The function to use: intersection


Using the OpenLayers Polygons directly, I get errors, resulting of the missing functions, added by JSTS. And if I use JSTS Polygons, there seems still something missing.this.getFactory().createGeometryCollection is not a function

How do I get an intersection of those two polygons?

The intersects method in OpenLayers will only return a boolean value, not the intersection of the features.

if(polygon1.intersects(polygon2)){ //polygons intersect

Edit: I see you mean using the OpenLayers polygon type rather than the OpenLayers intersect method.

The JSTS library has only been out a few days, and the intersects function you referenced was updated 6 hours ago, so not sure how stable it is at the moment.

Watch the video: intersect Point with Polygon ArcMap (October 2021).