2

I want to toggle visibility of group of polylines. In my file I can show/hide markers, but when I try to do the same with polylines it just show/hide the last created polyline. In the future I would like to categorize my polylines and toggle just polylines with one colour. But for now I'd be happy if somebody can help me with toggling all polylines. I think problem is in a loop. Here's my file: http://www.2shared.com/document/C01NN3u5/Polylines.html

Thank you guys.

kolis29
  • 115
  • 2
  • 3
  • 11

1 Answers1

4

Create an array for each polyline category. Push each polyline object into the adequate array. To toggle them off, loop through a specific array and call setMap(null) on each polyline.

Having an array myArray containing some polylines, you could do something like

for (var i=0; i<myArray.length; i++) {

    myArray[i].setMap(null);
}

Do the same if you need to toggle them on again using setMap(yourMapId)

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
  • Thank you, you really helped me. Here is my function showing/hiding polylines: function displayLines(){ var p; for (p = 0; p < polylines.length; p++) if(polylines[p].getMap(map)) { polylines[p].setMap(null); } else { polylines[p].setMap(map); } } – kolis29 Oct 18 '12 at 06:56
  • @MrUpsidown will you please answer this [Question](http://stackoverflow.com/questions/21455280/hide-polyline-from-a-to-b-using-in-google-map-api-v3) – Rahman Jan 30 '14 at 11:32