Select to view content in your preferred language

Label Priority (JSON) not working

3503
8
01-20-2021 04:24 AM
GonzaloMuöoz
Regular Contributor

Hi,

I'm using the Label's Priority of the JSON in order to priorise between differente GraphicsOverlay but it's not working. Is it a known bug? I'm using it this way:

 

StringBuilder labelBuilder = new StringBuilder();
labelBuilder.AppendLine("{");
// Define a labeling expression that will show the Name attribute value
labelBuilder.AppendLine("\"allowOverrun\": true ,");
labelBuilder.AppendLine("\"allowOverlapOfLabel\": \"allow\" ,");
labelBuilder.AppendLine("\"allowOverlapOfFeatureBoundary\": \"allow\" ,");
labelBuilder.AppendLine("\"allowOverlapOfFeatureInterior\": \"allow\" ,");
labelBuilder.AppendLine("\"priority\": 25 ,");
labelBuilder.AppendLine("\"labelExpressionInfo\": {");
labelBuilder.AppendLine("\"expression\": \"return $feature.Name;\"},");
// Align label horizontally
labelBuilder.AppendLine("\"labelPlacement\": \"esriServerPointLabelPlacementCenterRight\",");
labelBuilder.AppendLine("\"multiPart\": \"labelLargest\",");
// Set the style for the text symbol
labelBuilder.AppendLine("\"symbol\": {");
labelBuilder.AppendLine("\"color\": [255,255,255,255],");
labelBuilder.AppendLine("\"haloColor\": [51,51,51,255],");
labelBuilder.AppendLine("\"haloSize\": 1.5,");
labelBuilder.AppendLine("\"font\": {\"size\": 10, \"weight\": \"bold\"},");
labelBuilder.AppendLine("\"type\": \"esriTS\"}");
labelBuilder.AppendLine("}");

Thanks

0 Kudos
8 Replies
dotMorten_esri
Esri Notable Contributor

What are the label expressions you use on each graphics overlay? How are you assigning them to the overlays?

0 Kudos
GonzaloMuöoz
Regular Contributor

HI Morten,

for low priority graphicsoverlay I use the one on my initial comment. For high priority graphicsoverlay I use the following:

labelBuilder.AppendLine("{");
// Define a labeling expression that will show the Name attribute value
labelBuilder.AppendLine("\"allowOverrun\": true ,");
labelBuilder.AppendLine("\"allowOverlapOfLabel\": \"allow\" ,");
labelBuilder.AppendLine("\"allowOverlapOfFeatureBoundary\": \"allow\" ,");
labelBuilder.AppendLine("\"allowOverlapOfFeatureInterior\": \"allow\" ,");
labelBuilder.AppendLine("\"priority\": 0,");
labelBuilder.AppendLine("\"labelExpressionInfo\": {");
labelBuilder.AppendLine("\"expression\": \"return $feature.Name;\"},");
// Align label horizontally
labelBuilder.AppendLine("\"labelPlacement\": \"esriServerPointLabelPlacementCenterRight\",");
labelBuilder.AppendLine("\"multiPart\": \"labelLargest\",");
labelBuilder.AppendLine("\"offsetDistance\": \"-10\",");
// Set the style for the text symbol
labelBuilder.AppendLine("\"symbol\": {");
labelBuilder.AppendLine("\"color\": [255,255,255,255],");
labelBuilder.AppendLine("\"haloColor\": [51,51,51,255],");
labelBuilder.AppendLine("\"haloSize\": 1.5,");
labelBuilder.AppendLine("\"font\": {\"size\": 10, \"weight\": \"bold\"},");
labelBuilder.AppendLine("\"type\": \"esriTS\"}");

labelBuilder.AppendLine("}");

 

Then I add them to each graphics overlay depending on the priority by adding them to the LabelDefinitions object of them:

LabelDefinitions.Add(LabelDefinition.FromJson(JsonCode));

Being JsonCode a string with the definition of the label (the one attached up)

Thanks,REgards

 

 

0 Kudos
PeterDimitrov1
Esri Contributor

Hi GonzaloMuöoz, 

Can you confirm if you are seeing this in 2D or 3D? 

Thanks

0 Kudos
GonzaloMuöoz
Regular Contributor

Hi PeterDimitrov1,

2D.

Thanks

0 Kudos
PeterDimitrov1
Esri Contributor

Hi,

I noticed that in both of your label definitions you set the property "allow label overlap" to allow. 
This will allow labels to overlap and will fully disregard any label deconfliction, producing the results you see / priority being ignored.

If you set "allow overlap of label" to "exclude", this will prevent labels from overlapping and you will see correct behaviour.

Following from the above information ,it is also worth to note that the default deconfliction strategy applied to labels is static, unless specified otherwise.

In the case where overlap of labels is not allowed, static deconfliction would mean that the lower priority label will not be drawn / removed in order to prioritize anything with higher priority. You can also try dynamic deconfliction, and simply put, labels will try to "move out of the way".

Static deconfliction, no overlap:

static, no overlap.png

Dynamic deconfliction, no overlap:
dynamic no overlap.PNG

Useful info on deconfliction and other JSON properties here: https://developers.arcgis.com/net/wpf/guide/json-label-class-properties.htm

Thanks.

0 Kudos
GonzaloMuöoz
Regular Contributor

Hi,

Thanks for the answer. 

Our client wants exactly that, show all the labels even if they overlap but give them priority of visibility based on the graphicsoverlay it belongs. I suppose that this is not possible right now, will this functionality be available in the future?

Regards.Gonzalo

0 Kudos
PeterDimitrov1
Esri Contributor

Hi Gonzalo, 

This is not something that we support at the moment. I have raised your idea with my team as a potential enhancement to our product for future releases, however your case will be made stronger if it also went through the official channels.

We have a forum ideas panel , which you can find here - https://community.esri.com/t5/custom/page/page-id/arcgis-ideas#custom-tiled-node-navigation

Kind Regards, 
Peter Dimitrov
MichaelBranscomb
Esri Frequent Contributor

Hi,

Thanks for your feedback on this issue. Support for showing all labels regardless of overlap, and accounting for label class priority in the 2D map view was added in version 100.12. 

 

Thanks