Monday, February 08, 2010

clearOverlays() in V3

There is no clearOverlays() in API v3. Some practices have been presented. I think this is the simpliest so far.

Push all the overlays in an array when created (as usual). Following code will clear both map and the array:

  while(overlays[0]){
   overlays.pop().setMap(null);
  }

pop() method of an array removes the last element of an array, and returns that element. 'while' keeps that happening as long as there are elements in the array. When overlays[0] does not exist anymore, the mission is completed and code will proceed.

Applied in the example of the previous post.

5 comments:

Unknown said...

thanks for your trick

Anonymous said...

Any suggestions on how to delete just one marker of many in v3 via a link in infowindow? I keep track by pushing marker into markers array, but can't seem to find the "index number" of the one I want to delete
Thanks

jluch82 said...

awesome! thanks

froggingbob said...

Thank-you sir! This saved me a lot of strenuous, tedious and downright useless coding and searching.

Anonymous said...

Thanks!!!