perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.06k stars 347 forks source link

All alternative routes have same color #689

Closed rishav-karanjit closed 1 year ago

rishav-karanjit commented 1 year ago

According to the documentation, L.Routing.Control class have a option altLineOptions. For some reason, altLineOptions is a list of styles. I expected each alternative route to having a separate color from the list in altLineOptions. But, all alternative route have the style that is in the last item of the list.

Example:

I have given the following in altLineOptions:

altLineOptions: {
          styles: [
              {color: 'red', opacity: 0.15, weight: 2},
              {color: 'green', opacity: 0.8, weight: 6},
              {color: 'white', opacity: 0.8, weight: 6},
              {color: 'white', opacity: 0.8, weight: 6},
              {color: 'blue', opacity: 0.5, weight: 2}
          ]
      },

But all alt line option has the same style as the last item in the list. I have used graphhopper routing backend. image

rishav-karanjit commented 1 year ago

I have done a lot of projects using leaflets. If it's fine, I want to solve this issue by myself. Can I be assigned to this issue?

curtisy1 commented 1 year ago

Thank you for the detailed issue description with example and being willing to help! It's greatly appreciated.

First off, I agree with everything you said. The option is a little confusing at the moment and should probably be changed to an implementation that is a little more intuitive.

That being said, I think this needs some further discussion on how to approach this. Off the top of my head, these questions would need to be sorted out first:

I think the reason behind the current way of doing things is the third point. The polylines are added above each other, so you have the option to create some kind of shadow together with your polyline. However, I think the defaults can be done with just a single option and polyline, so it should be fine to change this.

I assigned the issue to you. As mentioned, please use the typescript branch as your working base, so I can get this merged into the next release.

Thank you!

curtisy1 commented 1 year ago

For reference, here's a comparison of using combined styles for one route, compared to just one style (left is the current default, right is possible new styles). I think this is not too big of a change though, so it should be fine. Plus the behavior can be overridden as well

rishav-karanjit commented 1 year ago

I think the current approach is fine. If number of styles and number alternative routes does not match, the option would be more less intuitive.