AnsweredAssumed Answered

Label Feature Layer created by Feature Collection

Question asked by soldous on Apr 26, 2017
Latest reply on Nov 16, 2017 by rscheitlin

Acording to this demonstration ArcGIS API for JavaScript Sandbox I try to set labels to Feature Layer. My Feature Layer is created by Feature Collection and when I have exactly the same code as in demonstration no labels are shown.

Can anyone help please?

Here is my code:

var map = this.map;
map.showLabels = true;
var devFeatureCollection = {
     "layerDefinition": null,
     "featureSet":{
          "features":[],
          "geometryType": "esriGeometryPoint"
     }
};
devFeatureCollection.layerDefinition = {
     "geometryType": "esriGeometryPoint",
     "objectIdField": "ObjectID",
     "spatialReference": {
           "wkid": 102067,
           "latestWkid": 102067
     },
     "drawingInfo": {
           "renderer": {
              "type": "simple",
              "symbol": {
                "type": "esriPMS",
                "url": "images/trafLight.png",
                "contentType": "image/png",
                "width": 10,
                "height": 20
              }
           }
     },
     "fields": [{
           "name": "ObjectID",
           "alias": "ObjectID",
           "type": "esriFieldTypeOID"
           }, {
           "name": "serialno",
           "alias": "ID zařízení",
           "type": "esriFieldTypeString"
           }, {
           "name": "street1",
           "alias": "Ulice_1",
           "type": "esriFieldTypeString"
           }, {
           "name": "street2",
           "alias": "Ulice_2",
           "type": "esriFieldTypeString"
          }]
};
devFeatureLayer = new FeatureLayer(devFeatureCollection, {
      id: 'devStates',
      infoTemplate: devPopupTemplate,
      outFields: ["*"]
});
// create a text symbol to define the style of labels
        var devLabel = new TextSymbol()
        devLabel.font.setSize("14pt");
        devLabel.font.setFamily("arial");

        //this is the very least of what should be set within the JSON 
        var json = {
          "labelExpressionInfo": {"value": "{serialno}"}
        };

        //create instance of LabelClass (note: multiple LabelClasses can be passed in as an array)
        var labelClass = new LabelClass(json);
        labelClass.symbol = devLabel; // symbol also can be set in LabelClass' json
        devFeatureLayer.setLabelingInfo(labelClass);

Outcomes