maplibre / maplibre-gl-directions

A plugin to show routing directions on a MapLibre GL JS map
https://maplibre.org/maplibre-gl-directions/
MIT License
72 stars 16 forks source link

Incorrectly-built routes for the cases when there are multiple waypoints in the input data with the same coordinates #209

Closed smellyshovel closed 1 year ago

smellyshovel commented 1 year ago

To put it all short:

With the existing implementation, everything works just fine as long as none of the coordinates are repeated in the input waypoints data:

        [7.137154, 49.319755], // 1
        [7.148604, 49.315962], // 2
        [7.149873, 49.319595],
        [7.140321, 49.30794],
        [7.153934, 49.317662],
        [7.144149, 49.310097], // 3
        [7.13242, 49.31679],
        [7.146392, 49.317763], // 4
        [7.156454, 49.322832], // 5
        [7.143664, 49.313397], // 6

        // [7.137154, 49.319755], // 1
        // [7.146392, 49.317763], // 4
        // [7.137154, 49.319755], // 1
        // [7.148604, 49.315962], // 2
        // [7.144149, 49.310097], // 3
        // [7.143664, 49.313397], // 6
        // [7.156454, 49.322832], // 5
        // [7.143664, 49.313397], // 6

Screenshot_20230831_153119

Total route geometry:

iw_lHk~pj@sCkIw@qFj@gUbAk@fJuN~AhAzAcF?yApGiCRgAYkCK}Hg@aDEsCVcBcEiA_BmEsBrD?`B`CtGpDfFAlHiCnFmB`CqFgJ?_AmAaC_EoC_C^`H~PtJpHzAcF?yApGiCRgA[}Cl@@^cA`AMp@|DzAvArBT`DhJfEfInIxKhEpL|CpFdFrMZHbEiD_B_C}D}Ic`@qy@wAmNe@YmA^oCKkD_CqFqAu@u@a@^cBkCx@eAXhAfB|CpFpAjD~BnCJ~@t@nAvLz@ExRla@j@lAwEtG{BxO}@dR@zHu@nMcCzHe@pPWLeBw@k@|DoEnDoENqBjAi@ye@_A}g@Ri]k@qEoAyCeA_A^qA`AcDKcBsAxAaBtDyFcEeBuC_HmRk@oDQ_Gy@oDgBgCiBk@IaDNo@fAi@C[y@{C}BiC|BhCz@hDmAfA@`EhBj@fBfCx@nDP~Fj@nD~GlRhApBtJpHzAcF?yApGiCRgA[}Cl@@^cA`AMp@|DzAvArBT`DhJfEfI`DjEkApEkGqF]LEr@

Reference Valhalla:

Screenshot_20230831_153257

Issues begin with uncommenting at least the 11th coordinate (which duplicates the first one):

        [7.137154, 49.319755], // 1
        [7.148604, 49.315962], // 2
        [7.149873, 49.319595],
        [7.140321, 49.30794],
        [7.153934, 49.317662],
        [7.144149, 49.310097], // 3
        [7.13242, 49.31679],
        [7.146392, 49.317763], // 4
        [7.156454, 49.322832], // 5
        [7.143664, 49.313397], // 6

        [7.137154, 49.319755], // 1
        // [7.146392, 49.317763], // 4
        // [7.137154, 49.319755], // 1
        // [7.148604, 49.315962], // 2
        // [7.144149, 49.310097], // 3
        // [7.143664, 49.313397], // 6
        // [7.156454, 49.322832], // 5
        // [7.143664, 49.313397], // 6

The built route looks the same

Screenshot_20230831_153607

Though the total route's geometry's different:

iw_lHk~pj@sCkIw@qFj@gUbAk@fJuN~AhAzAcF?yApGiCRgAYkCK}Hg@aDEsCVcBcEiA_BmEsBrD?`B`CtGpDfFAlHiCnFmB`CqFgJ?_AmAaC_EoC_C^`H~PtJpHzAcF?yApGiCRgA[}Cl@@^cA`AMp@|DzAvArBT`DhJfEfInIxKhEpL|CpFdFrMZHbEiD_B_C}D}Ic`@qy@wAmNe@YmA^oCKkD_CqFqAu@u@a@^cBkCx@eAXhAfB|CpFpAjD~BnCJ~@t@nAvLz@ExRla@j@lAwEtG{BxO}@dR@zHu@nMcCzHe@pPWLeBw@k@|DoEnDoENqBjAi@ye@_A}g@Ri]k@qEoAyCeA_A^qA`AcDKcBsAxAaBtDyFcEeBuC_HmRk@oDQ_Gy@oDgBgCiBk@IaDNo@fAi@C[y@{C}BiC|BhCz@hDmAfA@`EhBj@fBfCx@nDP~Fj@nD~GlRhApBtJpHzAcF?yApGiCRgA[}Cl@@^cA`AMp@|DzAvArBT`DhJfEfI`DjEkApEkGqF]LEr@Sh@L|F`CvPjF_A}@dR@zHu@nMcCzHe@pPWLeBw@k@|DoEnDoENqBjAwAm_AeFfAwCdDaA`@WqDsA_F

What it should look like (ref)

Screenshot_20230831_153754

If we uncomment all the waypoints, thus adding multiple duplicated waypoints, here's what the difference looks like:

Real: total mess with some weird straight lines here and there

Screenshot_20230831_154034

Ref

Screenshot_20230831_154139