Multiple Routes Using Same Layer

4 posts / 0 new
Last post
sayzawn
Multiple Routes Using Same Layer

I'm using jQuery and data attributes to change the start and end locations of a route when a button is clicked. Currently my map is loading into a modal dialog. Is it possible use the same map to show different routes? For example, if I had 5 different buttons which corresponded to 5 separate routes, could I click one button, show that route, and if clicking another button, hide the first route, showing the second?


MQBrianCoakley
If you create another L
If you create another L.mapquest.directions().route() the first one should be removed by default. It shouldn't be related to jQuery or modals.

sayzawn
I see, so simply add a new

I see, so simply add a new layer for each route. I have a list of different addresses continuously updating from my db so the number of layers I would need is not known. I figured there might be a way to use the same layer or maybe create a new layer as needed on the fly.


MQBrianCoakley
If you're using the default
If you're using the default route function, it creates a new route ribbon layer each time. If you want to use the directions api directly in the background, a single route ribbon can be altered as updates take place. Create a polyline and the points can get updated using setLatLngs as needed.