在 MapBox 中显示与折线的距离

Show distance from a polilyne in MapBox

我正在开发这个多边线代码,我需要完整地显示多边线距离,我该怎么做?

下面是我使用的代码:

https://drive.google.com/file/d/1eQg-hnOFuRWOPWUhg8Lqq38Lc6Pi9uJc/view?usp=sharing

您可以使用 Turf.js.

这样的库来计算 geojson

例如,turf/length 测量 lineString 的长度,如下所示。

const line = turf.lineString([
  [-53.08074, -25.766767],
  [-53.097358, -25.77123],
  [-53.117901, -25.798796],
  [-53.147227, -25.801503],
  [-53.187904, -25.812659],
  [-53.235429, -25.811208],
  [-53.276227, -25.802679],
  [-53.305865, -25.788242]
]);

const len = turf.length(line, { units: "kilometers" }); // 24.96224597809012