0

I'm trying to draw intersection point of two lines, but visually it is not correct intersection point. Is there any idea?

I'm using openlayers as map.

// draw two lines on the map: 

const lineFeature1 = new ol.Feature({
geometry: new ol.geom.LineString(ol.proj.transform([startPoint1, endPoint1], 'EPSG:4326', 'EPSG:3857')),
});
const lineFeature2 = new ol.Feature({
geometry: new ol.geom.LineString(ol.proj.transform([startPoint2, endPoint2], 'EPSG:4326', 'EPSG:3857')),

layerSource.addFeature(lineFeature1);
layerSource.addFeature(lineFeature2);

// calculate intersectionPoint:

line1 = turf.lineString([startPoint1, endPoint1])
line2 = turf.lineString([startPoint2, endPoint2])

const intersectionPoint = turf.lineIntersect(line1, line2)
const intersectionCoords = turf.getCoords(intersect.features[0])`
const point = ol.proj.transform(intersectionCoords, 'EPSG:4326', 'EPSG:3857');
const marker = new ol.Feature(new ol.geom.Point(point));

The same problem you can see also here: https://turfjs.org/docs/#lineIntersect

Here is a screenshot of the problem

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Use the same coordinate system to calculate the intersect that you wish to view it https://codesandbox.io/s/turf-forked-x1ry9y?file=/main.js – Mike May 18 '23 at 13:13

0 Answers0