Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda