百度地图 判断一个标注点是否在多边形区域里
/** * 计算一个点是否在多边形里 * @param {Object} pt 标注点 * @param {Object} poly 多边形数组 */ function isInsidePolygon(pt, poly){ for (var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) ((poly[i].lat <= pt.lat && pt.lat < poly[j].lat) || (poly[j].lat <= pt.lat && pt.lat < poly[i].lat)) && (pt.lng < (poly[j].lng - poly[i].lng) * (pt.lat - poly[i].lat) / (poly[j].lat - poly[i].lat) + poly[i].lng) && (c = !c); return c; }