I am trying to add a KML layer to ESRI javascript project. That part is easy enough.

I want the KML file to appear, but do not want any infowindow to display for items within that KML. All that I want is the kml image on the map as shown below.

Correct Display

I had it working as I described using the following dojo.connect code... but then read that this method is deprecated, so I am trying to make an I made the changes to support a kml.on("load"...) style event.

With the dojo connect function the kml layer appears without the ability to click on that layer and have an infowindow display. This is the result that I want to achieve by using the kml.on event function.

However, once I changed my code from this:

dojo.connect(kml, 'onLoad', function(lyr) {    
  var layers = lyr.getLayers();    
  dojo.forEach(layers, function(lyr) {    


kml.on("load", function(lyr) {  
  var layers = lyr.getLayers();  
  array.forEach(layers, function(lyr) {  

This new kml.on code is now causing the entire kml shape to no longer display in the map. As shown in the image below.

Failed To Load KML at All

Any Ideas?

  • This is solved. Needed to use lyr.layer.getLayers() and then setInfoTemplate to null on each of those layers.
    – EJH
    Commented Feb 22, 2016 at 18:06

1 Answer 1


This was solved by using lyr.layer.getLayers() instead of lyr.getLayers(); and then setInfoTemplate to null on each of those layers.

   //On loading the kml file
   kml.on("load", function(lyr){
      //Extract all of the layers from within the KML 
      var layers = lyr.layer.getLayers();
      //For each of those layers, 
      //1. Set click event to re-center the map to original point
      //2. Set the infoTemplate for each layer to null
      // That way whenever the kml layer is clicked there is no infowindow
      // to display to the users.
      array.forEach(layers, function(l) {
        l.on("click", centerMap);
  • 2
    can you please comment (explain) your code so that non-coders would be able to understand the code better (and more likely get up votes) thanks
    – Mapperz
    Commented Feb 22, 2016 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.