KML infowindow - Can I close it with code?

447 views
Skip to first unread message

Joseph Elfelt

unread,
Mar 23, 2011, 11:09:10 PM3/23/11
to Google Maps JavaScript API v3
When a map is displaying a KML file and the viewer clicks on a KML
line/marker/etc typically an infowindow opens and displays some
stuff. Is there a way to close that infowindow with code?

James McGill

unread,
Mar 23, 2011, 11:16:46 PM3/23/11
to google-map...@googlegroups.com, Joseph Elfelt
Toggling suppressInfoWindows should hide it.

> --
> 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-map...@googlegroups.com.
> To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>

Joseph Elfelt

unread,
Mar 23, 2011, 11:46:40 PM3/23/11
to Google Maps JavaScript API v3
Hmmm...to toggle suppressInfoWindows it seems like I would have to
reload the KML file since that is when the KML option settings are
relevant.

Anyone know of a way to use some version of infowindow.close() so that
the KML infowindow is closed?

Joseph Elfelt

unread,
Mar 23, 2011, 11:50:26 PM3/23/11
to Google Maps JavaScript API v3
I got it.

mykml.setMap();
mykml.setMap(mymap);

geoco...@gmail.com

unread,
Mar 24, 2011, 12:46:18 AM3/24/11
to Google Maps JavaScript API v3
The other option is to create the infowindow yourself.

var infowindow = new google.maps.InfoWindow({});

Add a click event listener to the KmlLayer and use the
google.maps.KmlMouseEvent.featureData.infoWindowHtml
to set its content on a click event.

then infowindow.close() will work...

The way you found is probably better if that is all you need to do.

-- Larry

James McGill

unread,
Mar 24, 2011, 1:55:10 AM3/24/11
to google-map...@googlegroups.com, geoco...@gmail.com
layer.setOptions({suppressInfoWindows: true});
layer.setOptions({suppressInfoWindows: false});

Avoids an additional HTTP fetch.

Joseph Elfelt

unread,
Mar 24, 2011, 8:06:30 AM3/24/11
to Google Maps JavaScript API v3
James,

I would like your approach to work but it does not close the KML
infowindow.
As a result of some searching, I noticed in another thread that Chad
opined:

"Certain options can be set only be set initially. Which options are
this way and which aren't have yet to be formally documented. I would
guess that disableDefaultUI can only be set during map
initialization."

Perhaps suppressInfoWindows is one of the options that can only be set
initially.

Larry,

Thanks for your idea. I have not fiddled yet with making my own
infowindows for KML clicks, but the need is bound to arise.

JFrancis

unread,
Mar 24, 2011, 9:35:25 AM3/24/11
to Google Maps JavaScript API v3
What about not responding to the mouse click at all?

var myKmlURL = 'http://www.myWebSIte.com/datafiles/myKmlFile.kml';
var myKmlOptions = {
clickable: 0 //KML polygon does NOT respond to mouse clicks
};
myKmlLayer = new google.maps.KmlLayer(myKmlURL, myKmlOptions);
myKmlLayer.setMap(map);

-- JF

Joseph Elfelt

unread,
Mar 24, 2011, 10:22:38 AM3/24/11
to Google Maps JavaScript API v3


On Mar 24, 6:35 am, JFrancis <jfran...@mge.com> wrote:
> What about not responding to the mouse click at all?

In this case I want the user to be able to open the KML infowindow by
clicking the KML.
Then if the user rightclicks the map (to display a context menu) I
wanted to close the KML infowindow with code.
Reply all
Reply to author
Forward
0 new messages