Programmatically close/hide/delete Google Maps tooltips

1k views Asked by At

I have a map page that uses Google Maps Javascript APIs v3 and geoxml3 parser for parsing server-generated KML documents.

When I refresh the map with a new KML I want to "clean" the map before displaying the new file.

My code currently works as follows:

//Init parser
var myParser = new geoXML3.parser({map: me.map});

//On map refresh
if (myParser.docs[0] != undefined)
{
    Ext.each(myParser.docs, function(doc){
        Ext.each(doc.gpolygons, function(gpolygon){
            gpolygon.setMap(null);
        });
        Ext.each(doc.placemarks, function(placemark){
            if (placemark.polygon != undefined) placemark.polygon.setMap(null);
            if (placemark.marker != undefined) placemark.marker.setMap(null);
        });
    });
}

That successfully cleans polygons and placemarks. But if I click on a polygon before cleaning the map, the tooltip remains. Here is a screenshot

Screenshot of map

Where you see placemark "004_ALBINO" there was a polygon that was cleaned up after refreshing the map. The other tooltip "400" was shown before refreshing the map, and was not cleaned - at least it has a valid polygon below itself.

How can I close the tooltips when I update the map?

1

There are 1 answers

0
geocodezip On

This should close any infowindows owned by geoxml3 (should handle both cases, singleInfowindow or an infowindow per object). You shouldn't need to call .setMap(null) on both all the members of the gpolygons array and all the placemark.polygon objects, those are two different ways of doing the same thing.

//Init parser
var myParser = new geoXML3.parser({map: me.map});

//On map refresh
if (myParser.docs[0] != undefined)
{
    Ext.each(myParser.docs, function(doc){
        Ext.each(doc.placemarks, function(placemark){
            if (placemark.polygon != undefined) {
              placemark.polygon.setMap(null);
              placemark.polygon.infoWindow.close();
            }
            if (placemark.marker != undefined) {
              placemark.marker.setMap(null);
              placemark.marker.infoWindow.close();
            }
        });
    });
}