此例为坐标是否在四边形内,如果是6边型请在判断iSum增加3,
    定理:从目标点出发引一条射线,看这条射线和多边形所有边的交点数目。如果有奇数个交点,则说明在内部,如果有偶数个交点,则说明在外部。

    1. export function IsPtInPoly(ALon, ALat, APoints) {
    2. var iSum = 0,
    3. iCount;
    4. var dLon1, dLon2, dLat1, dLat2, dLon;
    5. if (APoints.length < 3) return false;
    6. iCount = APoints.length;
    7. for (var i = 0; i < iCount; i++) {
    8. if (i == iCount - 1) {
    9. dLon1 = APoints[i].lng;
    10. dLat1 = APoints[i].lat;
    11. dLon2 = APoints[0].lng;
    12. dLat2 = APoints[0].lat;
    13. } else {
    14. dLon1 = APoints[i].lng;
    15. dLat1 = APoints[i].lat;
    16. dLon2 = APoints[i + 1].lng;
    17. dLat2 = APoints[i + 1].lat;
    18. }
    19. //以下语句判断A点是否在边的两端点的水平平行线之间,在则可能有交点,开始判断交点是否在左射线上
    20. if (((ALat >= dLat1) && (ALat < dLat2)) || ((ALat >= dLat2) && (ALat < dLat1))) {
    21. if (Math.abs(dLat1 - dLat2) > 0) {
    22. //得到 A点向左射线与边的交点的x坐标:
    23. dLon = dLon1 - ((dLon1 - dLon2) * (dLat1 - ALat)) / (dLat1 - dLat2);
    24. if (dLon < ALon)
    25. iSum++;
    26. }
    27. }
    28. }
    29. console.log(iSum%2)
    30. if (iSum % 2 == 0)
    31. return false;
    32. else if(iSum % 2==2)
    33. return false;
    34. return true;
    35. }