Hello
I'm trying to add labels to a FeatureLayer with LabelClass on version 3.16 of the javascript API.
I'm just displaying countries with different colors and trying to add the country name as a label.
Unfortunately, some of the labels are placed at very strange places instead of in the center of the country.
I have provided two examples in the attached screenshots.
This is the code which I am using to add the labels:
var featureLayer = new FeatureLayer(featureLayerPath, {
outFields: ['iso_a3', 'iso_a2', 'name']
});
featureLayer.setRenderer(this.renderer); // the renderer is defined earlier and works
var labelSymbol = new this.esri.TextSymbol({
font: new this.esri.Font('10', this.esri.Font.STYLE_NORMAL, this.esri.Font.VARIANT_NORMAL,
this.esri.Font.WEIGHT_NORMAL, 'Helvetica'),
color: new this.esri.Color('#000000')
});
var lc = new this.esri.LabelClass({
labelExpressionInfo: {value: '{name}'},
labelPlacement: 'center-center'
});
lc.symbol = labelSymbol;
featureLayer.setLabelingInfo([lc]);
map.addLayer(featureLayer);
I have already tried all possible options for the labelPlacement property, but this doesn't change anything.
Does anyone have an idea what I might be doing wrong and how I could do it correctly?
I'm thankful for any help!