perliedman / leaflet-routing-machine

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

Change route line color #63

Closed paulobraga closed 9 years ago

paulobraga commented 9 years ago

Hello,

I would like to change the route line color to blue, the default is red, how can I do?

my code looks like:


 var router = new L.Routing.OSRM({serviceUrl: 'http://localhost:5000/viaroute'});
            var waypoints = [];
           // I fill the waypoints array dinamically
            L.Routing.control({
                router: router,
                waypoints: waypoints,
                //geocoder: L.Control.Geocoder.nominatim(),
                routeWhileDragging: true
            }).addTo(map);
perliedman commented 9 years ago

Hi, check out the options for L.Routing.Line. You want to change the styles option.

To do this from the control, change its lineOptions. You can see an example with code here: http://www.liedman.net/leaflet-routing-machine/styling.html

DiegoJohan commented 9 years ago

Hi, the url http://www.liedman.net/leaflet-routing-machine/styling.html not work, but I found this page http://trustdarkness.com/wordpress/leaflet-routing-machine-custom-icons-and-custom-lines/ It works.

bye

HugoHeneault commented 8 years ago

For future people looking for a fast solution, based on @DiegoJohan link:

Find out the solution!

L.Routing.control({
   waypoints: waypoints,
   lineOptions: {
      styles: [{color: 'white', opacity: 1, weight: 5}]
   }
}).addTo(this.map)
MayurKasar321 commented 7 years ago

I am printing route on map but i need doted line so plz tell about doted style

perliedman commented 7 years ago

@MayurDynamo LRM uses Leaflet's standard options for styling lines. You likely want to use the dasharray option.

MayurKasar321 commented 7 years ago

Thank you a got this solution. My problem is solved

Ramyapriya24 commented 6 years ago

How to change the route line color in leaflet when it is already added to map

anviloro commented 4 years ago

you can try a dirty solution, by changing the style on the routesfound event, on('routesfound', (e) => { if (e !== undefined && e.routes !== undefined && e.routes.length > 0){ e.sourceTarget.options.lineOptions.styles[0].color = "blue";
} }

btw amazing control, thanks!

BenLaKnet commented 2 years ago

Hi,

I want to change route color when I click on Start or End marker, how is it possible ? https://www.lamaraudiere.com/d4ua/cartographie.php

hugohernani commented 2 years ago

I saw you managed to change the route color, @BenLaKnet . Can you tell how you did that?

BenLaKnet commented 2 years ago

Hi,

I create a new issue: https://github.com/perliedman/leaflet-routing-machine/issues/654

ujangaripin24 commented 1 year ago

thx this help me!!!