how to add Routing layer as control layer similar to how Traffic layer works (so that it can be toggled)

2 posts / 0 new
Last post
anirusharma
how to add Routing layer as control layer similar to how Traffic layer works (so that it can be toggled)

Hi

I am using mapquest with leaflets.

When I execute this code , it works

 L.control.layers({
                                     'Map': mapLayer,
                                     'Hybrid': MQ.hybridLayer(),
                                     'Satellite': MQ.satelliteLayer(),
                                     'Dark': MQ.darkLayer(),
                                     'Light': MQ.lightLayer()
                                      }, {
                                     'Traffic Flow': MQ.trafficLayer({layers: ['flow']}),
                                     'Traffic Incidents': MQ.trafficLayer({layers: ['incidents']})
                                     }).addTo(map);
But when I use this code , it does not work

 L.control.layers({
                                     'Map': mapLayer,
                                     'Hybrid': MQ.hybridLayer(),
                                     'Satellite': MQ.satelliteLayer(),
                                     'Dark': MQ.darkLayer(),
                                     'Light': MQ.lightLayer()
                                       }, {
                                     'Route': MQ.routing.routeLayer({directions: dir,fitBounds: true,draggable: true,ribbonOptions: {draggable: true,ribbonDisplay: { color: '#0000FF', opacity: 0.3 },widths: [ 15, 15, 15, 15, 14, 13, 12, 12, 12, 11, 11, 11, 11, 12, 13, 14, 15 ]}}),
                                     'Traffic Flow': MQ.trafficLayer({layers: ['flow']}),
                                     'Traffic Incidents': MQ.trafficLayer({layers: ['incidents']})
                                     }).addTo(map);

Please note parameters passed to Route layer are correct, as when I add it using function map.addLayer then it works, but then there is no way that I can hide it, thats why I want it to work as overlay error, when I can deselect the checkbox and hide/show it as per my need,

Kdinly guide how to make it work inside L.control.layers

 

Thanks

Aniruddh

 


MQBrianCoakley
Have you tried L.control
Ok, this MIGHT be the last time I edit this post.   Here is how I did it, eventually. I have a layer control lc that I add the route to and then add it to the layer control lc and it seems to be doing what you've described.   mqrl = MQ.routing.routeLayer({directions: dir,fitBounds: true,draggable: true,ribbonOptions: {draggable: true,ribbonDisplay: { color: '#0000FF', opacity: 0.3 },widths: [ 15, 15, 15, 15, 14, 13, 12, 12, 12, 11, 11, 11, 11, 12, 13, 14, 15 ]}}); map.addLayer(mqrl); lc.addOverlay(mqrl, 'route');