Reputation: 905
My map app draws lines between a number of points. It is triggered by a play button, a pause button and a skip button to fast forward to the next location.
I create the route by working out lat longs that fall between the various points. This creates the microLineArray array. I also have a counter microIteration so I know where I am on the route.
I then draw the line between the 2 lat longs using the following in a loop
polyline.addLatLng(microLineArray[microIteration])
Everything works fine with the play, pause and fast forward. I now need to add reverse play and skip back function so I need to remove these lines.
First thinking was adding the above to an array using something like this.
added_lines.push(polyline.addLatLng(microLineArray[microIteration]));
this populates an array of all the plotted polylines, you can see a top level snapshot of this array value below.
All of the other answers I have found on here tell me to remove the layer with the polylines but I want to keep that layer and step backwards. How do I go about removing the lines from the map now?
Upvotes: 0
Views: 481
Reputation: 2991
Since you said you are tracking where you are on the route...why can't you splice off the index of the latLng that creates the line you don't want anymore with spliceLatLngs
? The docs are at http://leafletjs.com/reference.html#polyline-splicelatlngs. You only need the first two parameters, index + amount to remove(which I think in the scenario you are describing would always be 1).
Upvotes: 0