javascript - Intersection point of two lines in leaflet -
i want intersection point of 2 polylines in leaflet. have 2 lines 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);
i can bounds , latlongs of endpoints of these lines. can't contiguous array of latlongs of line. there way ?
if don't program logic, there small , easy use library called turf provides several geoprocessing algorithms. can use 1 of algorithms independent of rest of library.
the lineintersects module want.
var intersection = turf.lineintersect(polyline1.togeojson(), polyline2.togeojson()); var intersectioncoord = intersection.features[0].geometry.coordinates;
also can check the source code of module inspiration.
Comments
Post a Comment