Hi, there - I am trying to add several KML layers, as well as a Legend Toggle and am repeatedly getting "Internal KML Parser Error" and only some of my layers are appearing on my map. All of my KMLs are publicly available, display properly in Google Earth, are under 10MB, and I'm using API 3.1. The layers that do appear work perfectly in the legend. I'm attempting to add upwards of 20 KML layers in total. My code is as follows (I apologize for not having the actual data, but it's proprietary):
var boundLayers = [];
var kml1 = new esri.layers.KMLLayer('publicURL',{id:'kml1'});
boundLayers.push({layer:kml1,title:'Layer 1'});
var kml2 = new esri.layers.KMLLayer('publicURL',{id:'kml2'});
boundLayers.push({layer:kml2,title:'Layer 2'});
var kml3 = new esri.layers.KMLLayer('publicURL',{id:'kml3'});
boundLayers.push({layer:kml3,title:'Layer 3'});
var kml4 = new esri.layers.KMLLayer('http://services.nationalmap.gov/ArcGIS/rest/services/nhd/MapServer',{id:'kml4'});
boundLayers.push({layer:kml4,title:'Layer4'});
dojo.connect(map,'onLoad',function(results){
if(legend){ legend.destroy(); }
var legend = new esri.dijit.Legend({
map:map,
layerInfos:boundLayers
},"legendBOUND");
legend.startup();
});
map.addLayers([kml1,kml2,kml3,kml4]);
dojo.connect(map,'onLoad',function(results){
//add check boxes
dojo.forEach(boundLayers,function(layer){
var layerNameB = layer.title;
var checkBoxB = new dijit.form.CheckBox({
name: "checkBoxB" + layer.layer.id,
value: layer.layer.id,
checked: layer.layer.visible,
onChange: function(evt) {
var blayer = map.getLayer(this.value);
if (blayer.visible) {
blayer.hide();
} else {
blayer.show();
}
this.checked = blayer.visible;
}
});
//add the check box and label to the toc
dojo.place(checkBoxB.domNode,dojo.byId("bounds"),"after");
var checkLabelB = dojo.create('label',{'for':checkBoxB.name, innerHTML:layerNameB},checkBoxB.domNode,"after");
dojo.place("<br />",checkLabelB,"after");
});
});
Any ideas?