Accessing KML tags in a Google Maps overlay through Javascript?

I have a KML file overlay on an embedded Google map using a GGeoXml object. I would like to have access to certain marks in the KML file from Javascript (for example, to highlight the selected polygon on the map in response to user action).

Ideally, what I would like to do is something like this (pseudocode):

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

Unfortunately, the Google Maps API does not seem to expose tags or other internal KML overlay elements. Anyone have any thoughts on how I can do this? I don't know anything about how overlays are implemented internally, but there seems to be a hack that would allow me to do this.

I also use jQuery FWIW.

+3
source share
4 answers

Have you watched GeoXML ?

+3
source

This does not seem to be a simple solution to this problem, since Google does not provide an answer in the API. The only method I found to access individual tags is to “capture” them when they are added to the map. To do this, you need to install the addoverlay listener on the map object. Something like that:

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

However, I could not figure out how to get the tag identifier from the marker object. Therefore, the only way I was able to access certain labels was to loop through the array and map markers to my data based on the coordinates. This is not a real elegant solution, but it was the only way I was able to get it to work.

+2

, :

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);
    });

...

0

Kml. placeark.

0
source

Source: https://habr.com/ru/post/1698380/


All Articles