我尝试使用truf并绘制路线,我得到的是与路线一起的水平线。我不知道还能做什么,因为它对其他类型的路线有效。
for (let i = 0; i < lineDistance; i += steps) {
const segment = turf.along(route.features[0], i);
arc.push(segment.geometry.coordinates);
}
上面的代码是我如何计算弧在地图上绘制的。
路由坐标有两个检查点/路由点,如图所示。LA(美国)和东京(日本)。
const route = {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': routePoints
}
}
]
};
参考文献:https://maplibre.org/maplibre-gl-js-docs/example/animate-point-along-route/
https://codepen.io/hasanac/pen/JjLmZqd (似乎是东城市的问题,西的城市问题)
发布于 2022-06-03 19:59:20
将"i“改为"1”,而不是"0“,则弧将正确计算。
for (let i = 1; i < lineDistance; i += steps) {
const segment = turf.along(route.features[0], i);
arc.push(segment.geometry.coordinates);
}
解释..。在计算横跨太平洋的弧线时,路线上的第一点是“错误的”,因此它绕地球绕到第二点( bug?)。
通过将每个段打印到console.log(),发现了这一点,并注意到第一个点(i=0)与其他点非常不同。
for (let i = 0; i < lineDistance; i += steps) {
const segment = turf.along(route.features[0], i);
console.log(segment.geometry.coordinates);
arc.push(segment.geometry.coordinates);
}
https://stackoverflow.com/questions/71556411
复制相似问题