Label don't show After Define LabelDefinition for ArcGISMapImageSublayer

1049
5
07-19-2017 02:06 AM
xiaoguangyan
New Contributor III

Hi, I Define LabelDefinition for ArcGISMapImageSublayer after the ArcGISMapImagelayer loaded, but the labels don't show, the field is to be labeld is "name"

private async void ArcGISMapImageLayer_LoadStatusChanged(object sender, LoadStatusEventArgs e)
{
var lyr = sender as ArcGISMapImageLayer;

if (e.Status == LoadStatus.Loaded)
{
var subLyr = lyr.Sublayers[1] as ArcGISMapImageSublayer;
await subLyr.LoadAsync();
subLyr.LabelDefinitions.Add(LabelDefinition.FromJson("{\"labelExpression\": \"[name]\",\"labelPlacement\": \"esriServerPolygonPlacementAlwaysHorizontal\",\"symbol\": {\"color\": [255,0,255,123],\"font\": {\"size\": 16},\"type\": \"esriTS\"}}"));

}

Tags (1)
0 Kudos
5 Replies
JensBuchta
Occasional Contributor

Is the FeatureLayer.LabelsEnabled Property  set to true?

0 Kudos
xiaoguangyan
New Contributor III

Hi, Jens

I try to set ArcGISMapImageSublayer.LabelsEnabled to true, but labels still don't show. 

0 Kudos
JenniferNery
Esri Regular Contributor

If LabelsEnabled is already true, maybe [name] attribute does not exist on that sublayer? If you remove the square brackets ([]), does the text `name` show as labels? You can try out this service and sample https://community.esri.com/thread/198759-label-dont-show-after-define-labeldefinition-for-arcgismapi... 

0 Kudos
xiaoguangyan
New Contributor III

Hi Jennifer

I have set LabelsEnabled=true, but I noticed that the service you test http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2 the "Can Modify Layer: true" , but mine is false, and I try another service with Can Modify Layer: false, the labels will don't show all the same. So I doubt that if the Can Modify Layer: true is necessary for LabelDefination of ArcGISMapImageSubLayer?

0 Kudos
MatveiStefarov
Esri Contributor

ArcGISMapImageLayer and ArcGISMapImageSublayer rely on dynamic layer functionality to customize labeling, which is only available when "Can Modify Layer" option is set to "true". You could also check yourLayer.ServiceInfo.SupportsDynamicLayers property of a loaded ArcGISMapImageLayer.

Service-defined labels can always be displayed, but dynamic layer support is necessary if you need clients to add / modify / hide labels on an ArcGISMapImageLayer or its sublayers.

0 Kudos