function finishConditionCallback() {
  // Only necessary to check polygons. Lines do not auto close, so all points are already checked.
  if (validateOnDraw && drawFeature && drawFeature.getGeometry().getType() === 'Polygon') {
    const coords = drawFeature.getGeometry().getCoordinates()[0];
    // remove second last coord. It is the last clicked position. If this function got called, OL deemed it close enough to either start or last point
    // to finish sketch and will not be a part of the final geometry, so remove it.
    const last = coords.pop();
    coords.pop();
    coords.push(last);
    const line = new LineString(coords);
    const isValid = !topology.isSelfIntersecting(line);

    if (!isValid) {
      // Topology can only be invalid if trying to auto close, but to not mess with the logic in Draw for clickTolerance,
      // we allow the click events and try to deal with it later.
      // The only way to become invalid here is because auto close, and if that failed remove last point as it will be double there.
      // Non auto close are blocked in conditionCallback.
      // Must schedule to make draw finish execution first.
      setTimeout(() => draw.removeLastPoint(), 0);
    }
    return isValid;
  }
  return true;
}
/**
 * Called by OL on mouse down to check if a sketch could be finished
 * @param {any} evt The MapBrowserEvent as received by Draw
 * @returns true if the feature can be completed , false otherwise
 */
Called by OL on mouse down to check if a sketch could be finished
@param {any} evt The MapBrowserEvent as received by Draw
@returns true if the feature can be completed , false otherwise
Called by OL on mouse down to check if a sketch could be finished @param { any } evt The MapBrowserEvent as received by Draw @returns true if the feature can be completed false otherwise
function finishConditionCallback() {
  if (validateOnDraw && drawFeature && drawFeature.getGeometry().getType() === 'Polygon') {
    const coords = drawFeature.getGeometry().getCoordinates()[0];
    const last = coords.pop();
    coords.pop();
    coords.push(last);
    const line = new LineString(coords);
    const isValid = !topology.isSelfIntersecting(line);
    if (!isValid) {
      setTimeout(() => draw.removeLastPoint(), 0);
    }
    return isValid;
  }
  return true;
}
function finishConditionCallback ( ) { if ( validateOnDraw && drawFeature && drawFeature . getGeometry ( ) . getType ( ) === 'Polygon' ) { const coords = drawFeature . getGeometry ( ) . getCoordinates ( ) [ 0 ] ; const last = coords . pop ( ) ; coords . pop ( ) ; coords . push ( last ) ; const line = new LineString ( coords ) ; const isValid = ! topology . isSelfIntersecting ( line ) ; if ( ! isValid ) { setTimeout ( ( ) => draw . removeLastPoint ( ) , 0 ) ; } return isValid ; } return true ; }
Called by OL on mouse down to check if a sketch could be finished
 @param {any} evt The MapBrowserEvent as received by Draw
 @returns true if the feature can be completed , false otherwise
Called by OL on mouse down to check if a sketch could be finished @param { any } evt The MapBrowserEvent as received by Draw @returns true if the feature can be completed false otherwise
// Only necessary to check polygons. Lines do not auto close, so all points are already checked. // remove second last coord. It is the last clicked position. If this function got called, OL deemed it close enough to either start or last point // to finish sketch and will not be a part of the final geometry, so remove it. // Topology can only be invalid if trying to auto close, but to not mess with the logic in Draw for clickTolerance, // we allow the click events and try to deal with it later. // The only way to become invalid here is because auto close, and if that failed remove last point as it will be double there. // Non auto close are blocked in conditionCallback. // Must schedule to make draw finish execution first.