标签:nic point span alert 解决 节点 col 内容 结构体
//定义点的结构体 function point(){ this.x=0; this.y=0; } //计算一个点是否在多边形里,参数:点,多边形数组
function PointInPoly(pt, poly) { for (var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) ((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y)) && (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x) && (c = !c); return c; } //调用 var pt=new point(); pt.x=34.32812720562833; pt.y=108.93115997314453; //这里的下x,y坐标是多边形的顺时针的拐角节点来排序的 var _poly=[{x:1.1,y:1.1},{x:3,y:1},{x:6,y:4},{x:2,y:10},{x:1.1,y:1.1}]; var xx=PointInPoly(pt,_poly); alert(xx);
简直nice,解决了困扰我好久的地图区域内容显示
JavaScript实现,判断一个点是否在多边形内(简直nice,希望能帮到你)
标签:nic point span alert 解决 节点 col 内容 结构体
原文地址:https://www.cnblogs.com/zy-simpleboy/p/14962739.html