Select to view content in your preferred language

Label don't show After Define LabelDefinition for ArcGISMapImageSublayer

2306
10
07-24-2017 06:29 PM
xiaoguangyan
Emerging Contributor

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
10 Replies
NagmaYasmin
Esri Contributor

Hi Yan,

Since you are using ArcGISMapImageLayer, you need to define the label expression in json format. Please see the documentation link :

"Labels for map image sublayers (ArcGISMapImageLayer) can be defined in much the same way as labels for feature layers and graphics overlays. The main difference is that labels for map image layers are rendered by the server and not in your client app. You must therefore use ArcGIS Server REST API syntax to define your label expressions, rather than the Arcade syntax you can use with feature layers and graphics overlays."

Label map features—ArcGIS Runtime SDK for .NET (WPF) | ArcGIS for Developers 

Hope that helps

Nagma

0 Kudos
xiaoguangyan
Emerging Contributor

Hi Nagma

I have noticed that the difference between map image layers and feature layer, I use the  ArcGIS Server REST API syntax to define my Json, but labels still don't show

0 Kudos
JenniferNery
Esri Regular Contributor

I tried your label JSON and it seems valid. Does 'name' attribute exist on the service? You also might be missing LabelsEnabled=true.

I updated the JSON a bit to fit the service in this sample.

            MyMapView.Map = new Map(Basemap.CreateTopographic());
            var layer = new ArcGISMapImageLayer(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer"));
            layer.Loaded += (s, e) =>
              {
                  var subLayer = (ArcGISMapImageSublayer)layer.Sublayers[2];
                  subLayer.LabelsEnabled = true;
                  subLayer.LabelDefinitions.Add(LabelDefinition.FromJson(("{\"labelExpression\": \"[state_name]\",\"labelPlacement\": \"esriServerPolygonPlacementAlwaysHorizontal\",\"symbol\": {\"color\": [255,0,255,123],\"font\": {\"size\": 16},\"type\": \"esriTS\"}}")));
              };
            MyMapView.Map.OperationalLayers.Add(layer);
xiaoguangyan
Emerging Contributor

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
MichaelBranscomb
Esri Frequent Contributor

Hi,

Yes, that's correct - your service must allow per layer modification, exposed in the capabilities as "Can Modify Layer" / "canModifyLayer".

The modification of ArcGISMapImageSublayers uses the DynamicLayer capability of the MapServer endpoint - for more info see ArcGIS REST API 

Cheers

Mike

0 Kudos
xiaoguangyan
Emerging Contributor

Hi

I use the ArcGISmapimagelayer with Can Modify Layer=True , but the labels show in messy code like pic below 

0 Kudos
NagmaYasmin
Esri Contributor

Hi Yan,

I believe you are trying to display the labels in Chinese characters. If that is the case, labels displayed in Chinese language isn't supported yet, that's my understanding.

Best,

Nagma

0 Kudos
xiaoguangyan
Emerging Contributor

Hi, Nagma

I do want to display the labels in Chinese characters, I am sorry to hear that labels displayed in Chinese language isn't supported yet.

0 Kudos
HTKSHI
by
Deactivated User

font tag set font_family which support Chinese characters

e.g:

"{\"labelExpression\": \"[state_name]\",\"labelPlacement\": \"esriServerPolygonPlacementAlwaysHorizontal\",\"symbol\": {\"color\": [255,0,255,123],\"font\": {\"size\": 16,\"family\":\"Microsoft YaHei\"},\"type\": \"esriTS\"}}"

0 Kudos