问题描述
我想在传单中得到两条折线的交点.我有以下两行:-
I want to get the intersection point of two polylines in leaflet.I have two lines as given below :-
var latlng1 = L.latLng(-7.9375, 4.46354);
var latlng2 = L.latLng(-7.96875, 16.11979);
var latlongs1 = [ latlng1, latlng2 ];
var polyline1 = L.polyline(latlongs1, {
color : 'red'
}).addTo(map);
var latlng3 = L.latLng(-3.5625, 9.31719);
var latlng4 = L.latLng(-12.125, 9.50469);
var latlongs2 = [ latlng3, latlng4 ];
var polyline2 = L.polyline(latlongs2, {
color : 'blue'
}).addTo(map);
我可以得到这些线的端点的边界和经度.我无法获得所有线的latlong的连续数组.有什么办法可以做到这一点?
I can get the bounds and latlongs of the endpoints of these lines. I can't get the contiguous array of all latlongs of line. Is there any way to get that ?
推荐答案
如果您不想对所有逻辑进行编码,则有一个小型且易于使用的库,名为草皮,其中提供了几种地理处理算法.您甚至可以只使用一种算法,而该算法大多独立于库的其余部分.
If you don't want to code all the logic, there is a small and easy to use library called Turf that provides several geoprocessing algorithms. You can even use just one of the algorithms mostly independent of the rest of the library.
lineIntersects 模块完全可以满足您的需求.
The lineIntersects module does exactly what you want.
var intersection = turf.lineIntersect(polyline1.toGeoJSON(), polyline2.toGeoJSON());
var intersectionCoord = intersection.features[0].geometry.coordinates;
您还可以检查源代码模块以获取灵感.
Also you can check the source code of the module for inspiration.
这篇关于传单中两条线的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!