在我的React应用程序中,我使用一些点绘制了一个多边形,然后我尝试找出鼠标当前位置是否在多边形内。我正在使用d3.polygonContains并将其传递给具有当前位置点的点阵列,但它总是返回false,尽管这些点在多边形内。
这是一个例子;
这是一个例子;
let points = [
[ 42.34624, -71.06024 ],
[ 42.33558, -71.06616 ],
[ 42.32632, -71.05835 ],
[ 42.32987, -71.05428 ],
[ 42.34732, -71.05432 ],
[ 42.34618, -71.05973 ],
[ 42.34624, -71.06024 ]
];
let testPoint = [
[42.33288, -71.05835]
];
alert(d3.polygonContains(points, testPoint));
alert(d3.polygonContains(points, (42.33288, -71.05835)));
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
有人能告诉我这里错在哪里吗??
let testPoint = [42.33288, -71.05835];
andalert(d3.polygonContains(points, [42.33288, -71.05835]));
- user5734311d3.polygonContains
的第一个参数文档远非清晰明了。 - Gerardo Furtado