简体   繁体   English

使用Google Maps API v3相交多边形和折线

[英]intersecting polygons and polylines, using google maps API v3

I have a polygon and polyline created dynamically. 我有一个动态创建的多边形和折线。 Now I need to check whether they both intersect each other or not. 现在,我需要检查它们是否彼此相交。

How do I achieve this? 我该如何实现? Googling hasn't provided any satisfactory results. 谷歌搜索没有提供令人满意的结果。

Thanks Daniel 谢谢丹尼尔

You need to iterate over each segment of the first polygon/polyline and check if it intersects each segment of the second polygon/polyline. 您需要遍历第一条多边形/折线的每个线段,并检查它是否与第二条多边形/折线的每个线段相交。 If one intersects, there the two geometries intersect. 如果一个相交,则两个几何相交。

If you don't need to take into account geodesic lines, you can take a look at the suggested implementations here: How do you detect where two line segments intersect? 如果不需要考虑测地线,则可以在此处查看建议的实现: 如何检测两个线段相交的位置? (there is also a Javascript implementation that may suit your needs: https://github.com/pgkelley4/line-segments-intersect/blob/master/js/line-segments-intersect.js ) (还有一个可能满足您需求的Javascript实现: https : //github.com/pgkelley4/line-segments-intersect/blob/master/js/line-segments-intersect.js

Look at Turf.js it provides you very simple lineIntersect method you pass it coordinates1, coordinates2 and it gives you the array of exact intersections. 看一下Turf.js,它为您提供了一个非常简单的lineIntersect方法,您lineIntersect传递了lineIntersect ,coordinates2,并且为您提供了精确交集的数组。 Turf.js lineIntersect documentation Turf.js lineIntersect文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM