1

I explain you my problem, I must display some polygons in a map and I must to be capable to call a javascript method when I click on the link present in the window info of one of them.

No problem when I use directly with the google api, you'll find below the result and the code :

http://jsfiddle.net/9fzy3/embedded/result/

var contentString = "You can add thi zone : <a href=\"#\" onclick=\"alert('Your zone has been added !')\">add</a>";
var infowindow = new google.maps.InfoWindow({
      content: contentString
});
function initializeGoogleMaps() {
        var polygonCenter = new google.maps.LatLng( -74.43013763427734,45.95257568359375),
        placeholder = document.getElementById("print_map"),
        mapOptions = {
                center: polygonCenter,
                mapTypeControl:false,
                mapTypeId: google.maps.MapTypeId.ROADMAP
        },
        map = new google.maps.Map( placeholder, mapOptions ),
        kmlLayer = new google.maps.KmlLayer({
                    url: "http://xxxxxxx/910413303.kml"
        });

        google.maps.event.addListener(kmlLayer, 'click', function(evt) {
            infowindow.setPosition(evt.latLng)
           infowindow.open(map);
         });

        kmlLayer.setMap(map);
}

But I would like to know, if it's possible to have the same behavior only in using a kml file.

For me I think it's not possible but I would like to have your opinion. Because I'm forced to use only a kml file.

I think the better solution to resolve my problem, it's maybe to parse the kml file with the geoxml3 api and after use the parsed elements directly with the api.

Thank in advance for your advices.

user2049200
  • 127
  • 2
  • 10
  • You have a problem with your KmlLayer infowindow, [fixed fiddle](http://jsfiddle.net/9fzy3/) – geocodezip Apr 30 '14 at 05:38
  • Thanks for help and your improvement. But I would like to know if it's possible to done something directly in the kml without the addlistener javascript (I think maybe with the description balise or something else). – user2049200 Apr 30 '14 at 13:49

1 Answers1

0

Your KML can have have a default infowindow - check the construction of Placemarks to get started: The name/description should show in v3.

Additionally you can use ExtendedData and a template for more structured infowindows if you don't want to hardcode everything in the description.

jlivni
  • 4,759
  • 1
  • 19
  • 30