我需要在距另一条线一定距离处的多段线上找到点的坐标。
这与Turf.js的沿着()方法类似,不同之处在于沿着()从折线起点开始计算。
所以我正在寻找angular(),但从折线上的给定点开始。
您需要一些步骤来实现所需的功能。
这里是建议的代码:
// original polyline
var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
// split point (second vertex, [-84, 36])
var splitter = line.geometry.coordinates[1];
// split the original polyline
var split = turf.lineSplit(line, splitter);
// prep the first portion (reverse the coordinates)
var part1 = split.features[0];
part1.geometry.coordinates = part1.geometry.coordinates.reverse();
// the second portion
var part2 = split.features[1];
然后您可以使用
var distance = 0.5; //unit: meters
turf.along(part1, distance, {units: 'meters'});
或
turf.along(part2, distance, {units: 'meters'});
var line = turf.lineString([
[-83, 30],
[-84, 36],
[-78, 41]
]);
var splitter = turf.point(line.geometry.coordinates[1]);
var split = turf.lineSplit(line, splitter);
var part1 = split.features[0];
var part2 = split.features[1];
// part 1
var distance = 0.5;
var p2 = turf.along(part1, 0.5, {
units: 'meters'
});
console.log("P2 (x,y) on part1: " + p2.geometry.coordinates);
// part 1
console.log("Original list of (x,y) of part2: " + part1.geometry.coordinates);
part1.geometry.coordinates = part1.geometry.coordinates.reverse();
console.log("List of (x,y) of part2: " + part1.geometry.coordinates);
<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>