MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / isPointInPoly

Method isPointInPoly

src/openlayers/overlay/Label.js:953–960  ·  view source on GitHub ↗

* @function Label.prototype.isPointInPoly * @description 判断一个点是否在多边形里面(射线法)。 * @param {Object} pt - 需要判定的点对象,该对象含有属性 x(横坐标),属性 y(纵坐标)。 * @param {Array. } poly - 多边形节点数组。例如一个四边形:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y":1}]。 * @returns {boolean} 点

(pt, poly)

Source from the content-addressed store, hash-verified

951 * @returns {boolean} 点是否在多边形内。
952 */
953 isPointInPoly(pt, poly) {
954 for (var isIn = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) {
955 ((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y)) &&
956 (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x) &&
957 (isIn = !isIn);
958 }
959 return isIn;
960 }
961
962
963 canvasFunctionInternal_(extent, resolution, pixelRatio, size, projection) { // eslint-disable-line no-unused-vars

Callers 6

GraphSpec.jsFile · 0.45
LabelThemeLayer.jsFile · 0.45
GraphThemeLayer.jsFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected