here I needed to do the same thing

assume a master js object myMap that is a global refernce to all map
goodies eg
var myMap = {
  Icons: null,
  map: null, //new google.maps.Map
  bounds: null,   //new google.maps.LatLngBounds()
  geocoder: null, //new google.maps.Geocoder();
  trafficInfo: null,  //new google.maps.TrafficLayer();
  markerCluster:null, //new MarkerClusterer
  markerOverlays : [],  //array of marker we add to map
}

function clearOverlays(aOverlays) {
  if (aOverlays) {
    for (i in aOverlays) {
      aOverlays[i].setMap(null);
      if (aOverlays[i].infowindow)
        aOverlays[i].infowindow.close();
    }
  }
}
function getOverlays(id) {
var bFound = false;
  if (aOverlays) {
    for (i in aOverlays) {
      if (id == aOverlays[i].id) {
        bFound = true;
        break;
      } (id == aOverlays[i].id)
    } //for (i in aOverlays)

  if (getOverlays.arguments.length == 2) {
    if (bFound)
      return aOverlays[i];
    else
      return null;
  }
  else {
    if (bFound)
      return true;
    else
      return false;
  } //(getOverlays.arguments.length == 2

  } //if (aOverlays)
} //getOverlays(id)

function setInfowindow(marker,sInfo) {
var infowindow = new google.maps.InfoWindow({
content: sInfo
});

//you can add as many listener to a marker as you want
google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(ecMap.map,marker);
  //$("#tabs").tabs();   //can use with special css jquery ui
});

google.maps.event.addListener(marker, 'click', function() {
 // alert(marker.id);
});

return infowindow
} //setInfowindow(marker,sInfo)
function getMarker(map,latlng,id,sIcon,sTitle,sLabel, sInfo) {
  var shape = {
      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
      type: 'poly'
  };
    var lMarker = new google.maps.Marker({
      id: id ,   //all gObject/arrays allow ad hoc string or object
assigments
      infowindow :  null;
      position: latlng,
      visible:true,
      shape: shape,
      icon: sIcon, //"A",  if sIcon is blank the markes wont show on
the map except the 1st Icon
      label: sLabel ,
      title: sTitle //show as tool tip

    });

    lmarker.infowindow = setInfowindow(lmarker, sInfo);
  return lMarker;
}

  var marker = getMarker(myMap.map,latlng,id,sIcon,title,label. sInfo)
  myMap.bounds.extend(latlng); // extend the bounds to include the new
point how to marker.getLatLng()
  myMap.map.fitBounds(myMap.bounds); //causes a stack over in ie7-8 if
latlng.lat=NaN, latlng=NaN
  myMap.markerOverlays.push(marker);

then you can so stuff like

if you know the id you assigned to the marker
marker  = getOverlays("12345',true)
      if (marker.infowindow)
        marker .infowindow.close();

or if you want to close all infowindows
clearOverlays(myMap.markerOverlays)

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to google-maps-js-api...@googlegroups.com.
To unsubscribe from this group, send email to 
google-maps-js-api-v3+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to