We are using Leaflet.js to allow our users to draw polygons and save them to their GIS server. We do this by converting the geometry from Leaflet into WFS format and making an Insert Transaction via WFS.
We are having problems where users are drawing polygons that intersect themselves and saving them. These are then showing up as invalid in PostGIS.
Is there any way to check for validity in JavaScript before we insert them?
We are using Leaflet.Geoman for drawing:
map.on('pm:create', function (e) {
var layerToDraw = e.layer;
//want to check here whether the layerToDraw is valid
features.addLayer(layerToDraw);
});