function testGeoPolygonPoint(geopolygon, point) {
  if (!testRectPoint(geopolygon.boundingRect(), point)) {
    return false;
  }
  const { x, y } = point;
  const numPolygons = geopolygon.numPolygons;
  let inside = false;
  let vertices;
  let n;
  let l;
  let j;
  let i;
  let tx;
  for (n = 0; n < numPolygons; n++) {
    vertices = geopolygon.vertices[n];
    for (i = -1, l = vertices.length, j = l - 1; ++i < l; j = i) {
      if (vertices[i].x === x && vertices[i].y === y) {
        // polygon vertice
        return true;
      }
      if (vertices[i].y === vertices[j].y && vertices[i].y === y && (x - vertices[i].x) * (x - vertices[j].x) <= 0) {
        // on horizontal edge of polygon
        return true;
      }
      if ((vertices[i].y < y && y <= vertices[j].y) || (vertices[j].y < y && y <= vertices[i].y)) {
        tx = ((vertices[j].x - vertices[i].x) * (y - vertices[i].y)) / (vertices[j].y - vertices[i].y) + vertices[i].x;
        if (x === tx) {
          // on polygon edge
          return true;
        }
        if (x < tx) {
          inside = !inside;
        }
      }
    }
  }
  return inside;
}
/**
 * Test if a GeoPolygon contains a Point. If so, returns true and false otherwise.
 * @private
 * @param {object} geopolygon
 * @param {Array} geopolygon.vertices - Array of of arrays of vertices
 * @param {object} point
 * @param {number} point.x - x-coordinate
 * @param {number} point.y - y-coordinate
 * @return {boolean} true if polygon conatins point
 */
Test if a GeoPolygon contains a Point. If so, returns true and false otherwise.
Test if a GeoPolygon contains a Point . If so returns true and false otherwise .
function testGeoPolygonPoint(geopolygon, point) {
  if (!testRectPoint(geopolygon.boundingRect(), point)) {
    return false;
  }
  const { x, y } = point;
  const numPolygons = geopolygon.numPolygons;
  let inside = false;
  let vertices;
  let n;
  let l;
  let j;
  let i;
  let tx;
  for (n = 0; n < numPolygons; n++) {
    vertices = geopolygon.vertices[n];
    for (i = -1, l = vertices.length, j = l - 1; ++i < l; j = i) {
      if (vertices[i].x === x && vertices[i].y === y) {
        return true;
      }
      if (vertices[i].y === vertices[j].y && vertices[i].y === y && (x - vertices[i].x) * (x - vertices[j].x) <= 0) {
        return true;
      }
      if ((vertices[i].y < y && y <= vertices[j].y) || (vertices[j].y < y && y <= vertices[i].y)) {
        tx = ((vertices[j].x - vertices[i].x) * (y - vertices[i].y)) / (vertices[j].y - vertices[i].y) + vertices[i].x;
        if (x === tx) {
          return true;
        }
        if (x < tx) {
          inside = !inside;
        }
      }
    }
  }
  return inside;
}
function testGeoPolygonPoint ( geopolygon , point ) { if ( ! testRectPoint ( geopolygon . boundingRect ( ) , point ) ) { return false ; } const { x , y } = point ; const numPolygons = geopolygon . numPolygons ; let inside = false ; let vertices ; let n ; let l ; let j ; let i ; let tx ; for ( n = 0 ; n < numPolygons ; n ++ ) { vertices = geopolygon . vertices [ n ] ; for ( i = - 1 , l = vertices . length , j = l - 1 ; ++ i < l ; j = i ) { if ( vertices [ i ] . x === x && vertices [ i ] . y === y ) { return true ; } if ( vertices [ i ] . y === vertices [ j ] . y && vertices [ i ] . y === y && ( x - vertices [ i ] . x ) * ( x - vertices [ j ] . x ) <= 0 ) { return true ; } if ( ( vertices [ i ] . y < y && y <= vertices [ j ] . y ) || ( vertices [ j ] . y < y && y <= vertices [ i ] . y ) ) { tx = ( ( vertices [ j ] . x - vertices [ i ] . x ) * ( y - vertices [ i ] . y ) ) / ( vertices [ j ] . y - vertices [ i ] . y ) + vertices [ i ] . x ; if ( x === tx ) { return true ; } if ( x < tx ) { inside = ! inside ; } } } } return inside ; }
Test if a GeoPolygon contains a Point.
Test if a GeoPolygon contains a Point .
// polygon vertice // on horizontal edge of polygon // on polygon edge