function conditionCallback(evt) {
  // Check modifiers
  if (!noModifierKeys(evt)) {
    return false;
  }
  // This function is called before onDrawStart, so first time there is no drawFeature as no point has been allowed
  // Second time there will be two points (first click and second click)
  // Third time there will be three points for line and four points for poly as a poly is auto closed.
  // When using touch, the current point is a copy of the previous, as it has not been moved yet. Clicked position comes in the event.
  // when using mouse, the current point is updated continously on mousemove, so it is the same as the click event
  // If this function returns true, the action is allowed and the clicked point is added t the draw.
  // If it returns false, the click is regarded as never happened, which will affect the possibility to stop drawing as well.
  if (!drawFeature) {
    // First call. Here we could check event to see if it is possible to start a new geometry here (overlapping rules, holes, multipolygon self overlap etc)
    return true;
  }

  const isTouch = evt.originalEvent.pointerType === 'touch';
  let coords;
  let minPointsToClose = 3;
  // Strangely enough, we don't get what has actually been drawn in the event. Pick up pointer to sketch from our own state
  // The sketch feature is what is drawn on the screen, not the actual feature, so It can only be poly, line or point. No multi-variant as
  // draw interaction can't make them.
  if (drawFeature.getGeometry().getType() === 'Polygon') {
    // OL adds a closing vertex when more than two points. Remove it in validation
    const polyCoords = drawFeature.getGeometry().getCoordinates()[0];
    const arrayend = polyCoords.length > 2 ? -1 : polyCoords.length;
    coords = polyCoords.slice(0, arrayend);
  }
  if (drawFeature.getGeometry().getType() === 'LineString') {
    minPointsToClose = 2;
    coords = drawFeature.getGeometry().getCoordinates().slice();
  }
  if (coords) {
    if (isTouch) {
      // Touch has a duplicate vertex as placeholder for clicked coordinate. Remove that and add the clicked coordinate, as it is not included in geom for touch
      coords.pop();
      coords.push(evt.coordinate);
    }

    // When trying to self auto close there can be two identical coords in the end if clicked on the exact same pixel. Allow that and make finishCondition fail instead of checking if we will succeed
    // This has the drawback that it is not possible to finish with an invalid last point that will be removed anyway.
    // Otherwise we have to implement the same clickTolerance as draw to distinguish between a new point and auto close or always try to autoclose and save that
    // result as a state to check in finishCondition.
    // If we got here we have at least two coords, so indexing -2 is safe
    if (coords[coords.length - 1][0] === coords[coords.length - 2][0] && coords[coords.length - 1][1] === coords[coords.length - 2][1]) {
      if (coords.length <= minPointsToClose) {
        // Cant' put second point on first, and finishCondition will not be called on too few points
        return false;
      }
      // No need to validate, it was valid before and no new point is added, we just for sure will try to finish.
      return true;
    }
    // Validate only last added segment
    return !topology.isSelfIntersecting(new LineString(coords), true);
  }

  return true;
}
/**
 * Called by OL on mouse down to check if a vertex should be added
 * @param {any} evt The MapBrowserEvent as received by Draw
 * @returns true if the point should be added, false otherwise
 */
Called by OL on mouse down to check if a vertex should be added
@param {any} evt The MapBrowserEvent as received by Draw
@returns true if the point should be added, false otherwise
Called by OL on mouse down to check if a vertex should be added @param { any } evt The MapBrowserEvent as received by Draw @returns true if the point should be added false otherwise
function conditionCallback(evt) {
  if (!noModifierKeys(evt)) {
    return false;
  }
  if (!drawFeature) {
    return true;
  }
  const isTouch = evt.originalEvent.pointerType === 'touch';
  let coords;
  let minPointsToClose = 3;
  if (drawFeature.getGeometry().getType() === 'Polygon') {
    const polyCoords = drawFeature.getGeometry().getCoordinates()[0];
    const arrayend = polyCoords.length > 2 ? -1 : polyCoords.length;
    coords = polyCoords.slice(0, arrayend);
  }
  if (drawFeature.getGeometry().getType() === 'LineString') {
    minPointsToClose = 2;
    coords = drawFeature.getGeometry().getCoordinates().slice();
  }
  if (coords) {
    if (isTouch) {
      coords.pop();
      coords.push(evt.coordinate);
    }
    if (coords[coords.length - 1][0] === coords[coords.length - 2][0] && coords[coords.length - 1][1] === coords[coords.length - 2][1]) {
      if (coords.length <= minPointsToClose) {
        return false;
      }
      return true;
    }
    return !topology.isSelfIntersecting(new LineString(coords), true);
  }
  return true;
}
function conditionCallback ( evt ) { if ( ! noModifierKeys ( evt ) ) { return false ; } if ( ! drawFeature ) { return true ; } const isTouch = evt . originalEvent . pointerType === 'touch' ; let coords ; let minPointsToClose = 3 ; if ( drawFeature . getGeometry ( ) . getType ( ) === 'Polygon' ) { const polyCoords = drawFeature . getGeometry ( ) . getCoordinates ( ) [ 0 ] ; const arrayend = polyCoords . length > 2 ? - 1 : polyCoords . length ; coords = polyCoords . slice ( 0 , arrayend ) ; } if ( drawFeature . getGeometry ( ) . getType ( ) === 'LineString' ) { minPointsToClose = 2 ; coords = drawFeature . getGeometry ( ) . getCoordinates ( ) . slice ( ) ; } if ( coords ) { if ( isTouch ) { coords . pop ( ) ; coords . push ( evt . coordinate ) ; } if ( coords [ coords . length - 1 ] [ 0 ] === coords [ coords . length - 2 ] [ 0 ] && coords [ coords . length - 1 ] [ 1 ] === coords [ coords . length - 2 ] [ 1 ] ) { if ( coords . length <= minPointsToClose ) { return false ; } return true ; } return ! topology . isSelfIntersecting ( new LineString ( coords ) , true ) ; } return true ; }
Called by OL on mouse down to check if a vertex should be added
 @param {any} evt The MapBrowserEvent as received by Draw
 @returns true if the point should be added, false otherwise
Called by OL on mouse down to check if a vertex should be added @param { any } evt The MapBrowserEvent as received by Draw @returns true if the point should be added false otherwise
// Check modifiers // This function is called before onDrawStart, so first time there is no drawFeature as no point has been allowed // Second time there will be two points (first click and second click) // Third time there will be three points for line and four points for poly as a poly is auto closed. // When using touch, the current point is a copy of the previous, as it has not been moved yet. Clicked position comes in the event. // when using mouse, the current point is updated continously on mousemove, so it is the same as the click event // If this function returns true, the action is allowed and the clicked point is added t the draw. // If it returns false, the click is regarded as never happened, which will affect the possibility to stop drawing as well. // First call. Here we could check event to see if it is possible to start a new geometry here (overlapping rules, holes, multipolygon self overlap etc) // Strangely enough, we don't get what has actually been drawn in the event. Pick up pointer to sketch from our own state // The sketch feature is what is drawn on the screen, not the actual feature, so It can only be poly, line or point. No multi-variant as // draw interaction can't make them. // OL adds a closing vertex when more than two points. Remove it in validation // Touch has a duplicate vertex as placeholder for clicked coordinate. Remove that and add the clicked coordinate, as it is not included in geom for touch // When trying to self auto close there can be two identical coords in the end if clicked on the exact same pixel. Allow that and make finishCondition fail instead of checking if we will succeed // This has the drawback that it is not possible to finish with an invalid last point that will be removed anyway. // Otherwise we have to implement the same clickTolerance as draw to distinguish between a new point and auto close or always try to autoclose and save that // result as a state to check in finishCondition. // If we got here we have at least two coords, so indexing -2 is safe // Cant' put second point on first, and finishCondition will not be called on too few points // No need to validate, it was valid before and no new point is added, we just for sure will try to finish. // Validate only last added segment