AnsweredAssumed Answered

Labels with KML Polygons

Question asked by SamuelHenderson on Sep 10, 2014
Latest reply on Sep 10, 2014 by SamuelHenderson

Hi All,

 

I'm using a kml file that was generated by ArcMap.  I'd like to have the polygons in the KML labeled with a value from a field.  What's the best way to do this?  I've followed the sample for labeling things here: https://developers.arcgis.com/javascript/jssamples/layers_label.html and replaced the FeatureLayer with a featureLayer returned from kml.getLayers().  The following Javascript doesn't generate any errors, but unfortunately the labels are still not present.

 

function LoadKMZ(kmlURL) {     
     var kml = new KMLLayer(kmlURL, { id: "kml" });
     kml.setOpacity(0.5);
     map.addLayer(kml);            
     kml.on("load", function () {
          console.log("KML Loaded");
          var layers = kml.getLayers();
          var fl = layers[0];  // There is only 1 FeatureLayer in the KML
                
          var censusLabel = new TextSymbol().setColor("#666");
          censusLabel.font.setSize("14pt");
          censusLabel.font.setFamily("arial");
          censusLabelRenderer = new SimpleRenderer(censusLabel);
          var labels = new LabelLayer({ id: "labels" });
          labels.addFeatureLayer(fl, censusLabelRenderer, "{" + "LABELNAME"+ "}");
          // add the label layer to the map
          map.addLayer(labels);
     });
}

 

When the polygons are clicked in the Map a balloon window with the attribute data pops up.  The name I would like to appear in the label layer is a field of this attribute data... but I think what is happening is that on like 15 of the above code when I'm adding the feature layer to my label layer it's not finding the field name.  It's odd that it doesn't give an error.

Outcomes