This is currently not supported out of the box by the library. There is an issue on its GitHub project page marked with PR accepted. However, this problem can be solved without this capability and the result might be even more robust. I'm planning to make a digitizing software as well in the future, and I would mimic the QGIS approach at this point.
In QGIS, you can only draw polygons by default. However, there is a dedicated tool for drawing rings. It is fully automatic, thus if you activate that tool, you get a drawing interaction just like the one you draw your polygons with. After you finished the ring, the software decides if it can form a valid ring of an existing polygon (e.g. no intersects), and if it can, it punches the ring into the polygon. BTW, you can check if a polygon is completely inside another one by calling the
intersectsCoordinate method of the outer ring with every coordinate of the hole. A little bit clumsy for my taste, but if you don't want to write or adapt an algorithm for checking intersections between polygons, it's working.
- This method is fully automatic.
- The feature order decides the chosen polygon, if there are more than one valid host for the given ring.
Because of the contra, I would alter QGIS's method, and require the user to select a polygon prior to making the "ring puncher" drawing tool active.