传单中两条线的交点 [英] Intersection point of two lines in leaflet

查看:71
本文介绍了传单中两条线的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在传单中得到两条折线的交点.我有以下两行:-

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.

这篇关于传单中两条线的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆