in modules/edit-modes/src/lib/split-polygon-mode.ts [101:142]
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
const tentativeFeature = this.getTentativeGuide(props);
const selectedGeometry = this.getSelectedGeometry(props);
if (!selectedGeometry) {
// eslint-disable-next-line no-console,no-undef
console.warn('A polygon must be selected for splitting');
return;
}
const clickSequence = this.getClickSequence();
if (tentativeFeature && tentativeFeature.geometry.type === 'LineString') {
clickSequence.push(
tentativeFeature.geometry.coordinates[tentativeFeature.geometry.coordinates.length - 1]
);
} else {
this.addClickSequence(event);
}
const pt: Point = {
type: 'Point',
coordinates: clickSequence[clickSequence.length - 1],
};
// @ts-expect-error turf types diff
const isPointInPolygon = booleanPointInPolygon(pt, selectedGeometry);
if (clickSequence.length > 1 && tentativeFeature && !isPointInPolygon) {
this.resetClickSequence();
// @ts-expect-error narrow type
const isLineInterectingWithPolygon = lineIntersect(tentativeFeature, selectedGeometry);
if (isLineInterectingWithPolygon.features.length === 0) {
return;
}
const editAction = this.splitPolygon(tentativeFeature, props);
if (editAction) {
props.onEdit(editAction);
}
}
}