0

I am new to Google Maps, so I have most likely missed something very basic. I want to group several lines, way points, locations .. logically together, so that I can switch them on / off at once. I thought this is a layer or overlay, but I am still confused about the difference.

On Playground I found the traffic overlay example which is basically doing what I want to do. But what kind of overlay is right for me? And how will draw the line to a particular overlay?

A similar question Google Maps marker grouping is doing this by categories on the marker and more or less iterating through them to switch them on/off - is there no easier way?

I could, of course, keep all elements (lines, markers) of a group in an array and this array would represent my logical group. Is this the right way?

var path = waypointsToLatLngPath(myWaypoints); // generate path from waypoint
var line = new google.maps.Polyline({
    path: path,
    strokeColor: '#ff0000',
    strokeOpacity: 1.0,
    strokeWeight: 1
});
line.setMap(map);
Community
  • 1
  • 1
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
  • On http://code.google.com/apis/maps/documentation/javascript/overlays.html they keep the overlay elements in an array and set / unset (null) the corresponding map in order to accomplish this. – Horst Walter Jul 16 '11 at 13:12

1 Answers1

0

As said in Google Maps API v3: How to remove all markers? and in my comment above, with V3 the right approach seems to be to keep arrays of the overlay elements and remove them by setting map to null.

I have written a little JS "class" for wrapping these aspects, so I can easily switch on/off all overlays. In V2 there was map.clearOverlays(), but this seems to be gone.

Community
  • 1
  • 1
Horst Walter
  • 13,663
  • 32
  • 126
  • 228