3
votes

I have a KML file overlay on an embedded Google Map using the GGeoXml object. I'd like to be able to access specific placemarks in the KML file from Javascript (for example to highlight a selected polygon on the map in response to user action).

Ideally what I'd like to do is something like this (pseudo-code):

 geoXml.getPlacemarkByName('Foo').focus();

Unforunately the Google Maps API doesn't seem to expose the placemarks or any other internals of the KML overlay. Does anyone have any thoughts as to how I might accomplish this? I don't know anything about how the overlays are implemented internally, but it seems like there might be a hack that would let me do this.

I'm also using jQuery FWIW.

4

4 Answers

3
votes
2
votes

There does not seem to be an easy solution to this problem since Google doesn't provide the answer in the API. The only method I have found to get access to individual placemarks is to "capture" them when they are added to the map. In order to do this you have to set an 'addoverlay' listener on the map object. Something like this:

GEvent.addListener(map, 'addoverlay', function(o) {
    kmlmarkers.push(o);
}

However, I couldn't figure out a way to get the id of the placemark out of the marker object. Therefore the only way I was able to access specific placemarks was to loop through the array and match the markers with my data based upon the coordinates. It's not a real elegant solution but is was the only way that I was able to make it work.

0
votes

You can figure that out by simply looking into the object as follows:

GEvent.addListener(map, 'addoverlay', function(obj)
{ if (!obj) {
        alert("Cannot describe a null object");
        return;
    }
    var str = "";

        for ( var prop in obj) {
            str += prop + " = " + obj[prop] + ",\n";
        }
        alert(str);
    });

That should help...

0
votes

Look at Kml Update. You will need a placeark ID.