Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
Turf.js along method is giving wrong results

I tried to use truf js and plot the route and i am getting horizontal line along with route. I dont know what else to do as it works for other types of routes.

for (let i = 0; i < lineDistance; i += steps) {
    const segment = turf.along(route.features[0], i);
    arc.push(segment.geometry.coordinates);
}

above code is how i calculate arc to plot on map.

The route coordinates has two checkpoints/routepoints as showing in diagram. LA(USA) and Tokyo (Japan).

const route = {
                'type': 'FeatureCollection',
                'features': [
                    {
                        'type': 'Feature',
                        'geometry': {
                            'type': 'LineString',
                            'coordinates': routePoints
                        }
                    }
                ]
            };

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Change "i" to start at "1" instead of "0" and the arc will calculate properly.

for (let i = 1; i < lineDistance; i += steps) {
    const segment = turf.along(route.features[0], i);
    arc.push(segment.geometry.coordinates);
}

Explanation... The first point along the route is "wrong" when calculating an arc across the pacific, so it wraps around the earth for the 2nd point (a bug?).

Discovered this by printing each segment to the console.log() and noticed the first point (i=0) is very different from the other points.

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);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda