Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger click event on a Google Maps KML placemark

I have a map that is loading in dynamic external KML with placemarks defined like so:

<Placemark id="MapZoneID_23443">
    <name>Name Here</name>
    <description>Text Here</description>
    <styleUrl>#ff8080ff</styleUrl>
    <Polygon>
        <outerBoundaryIs>
            <LinearRing>
                <coordinates>
                    ....
                </coordinates>
            </LinearRing>
        </outerBoundaryIs>
    </Polygon>
</Placemark>

What I'd like to do is have a link / dropdown / whatever that can be clicked or selected to basically trigger a click on $('#MapZoneID_23443') ... but I can't figure out how to trigger that click or if this is even possible. The maps can be quite complex, so I would prefer to not have to preload everything using JS gmaps markers. Thanks!

like image 746
jocull Avatar asked Feb 19 '13 19:02

jocull


2 Answers

It's not currently possible.

Star the issue on the bug tracker to both vote for it and follow it's progress: https://code.google.com/p/gmaps-api-issues/issues/detail?id=3006

like image 82
Chad Killingsworth Avatar answered Sep 27 '22 18:09

Chad Killingsworth


I have found a workaround.

Add this to your placemark in the <style> section

<BalloonStyle><text>TEXT</text></BalloonStyle>

You will be able to access this value after click in .js callback as

event.featureData.info_window_html

So, in your KML file

<Placemark id="MapZoneID_23443">
   <BalloonStyle><text>TEXT</text></BalloonStyle>
   ...
</Placemark>

And in javascript

google.maps.event.addListener(kmlLayer, 'click', function(event) {
  var content = event.featureData.info_window_html;
  console.log(content);
});
like image 26
x y Avatar answered Sep 27 '22 18:09

x y