admin管理员组

文章数量:1398811

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 acplish 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.

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 acplish 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.

Share Improve this question asked Oct 17, 2008 at 1:45 Herb CaudillHerb Caudill 50k40 gold badges127 silver badges178 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Have you looked at GeoXML?

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.

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...

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

本文标签: jqueryAccess KML placemarks in a Google Maps overlay via JavascriptStack Overflow