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);
Solved! Go to Solution.
Zdeněk,
FYI, I thought I would pass along the reason that my code changed worked and your was not working, now that I have figured it out. The issue is the use of the x and y field values as STRINGS in the new Point. You need to pass your X and Y as a number and not a string for it to work.
//This is attempting to pass the X and Y as strings
/var geometry = new Point({"x":"-605982.51","y":"-1162677.18","spatialReference":{"wkid":102067}});
//This is passing them as numbers
var geometry = new Point(-605982.51,-1162677.18, new SpatialReference({"wkid":102067}));
//This would work as well
var geometry = new Point({"x":-605982.51,"y":-1162677.18,"spatialReference":{"wkid":102067}});