Labels of Lines are shown/hidden by zoom level

1357
13
02-24-2021 04:49 AM
GonzaloMuöoz
Occasional Contributor

Hi,

I'm using following JSON definition for graphics of type line:

StringBuilder labelBuilder = new StringBuilder();
labelBuilder.AppendLine("{");
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;\"},");
labelBuilder.AppendLine("\"labelPlacement\": \"esriServerLinePlacementCenterAlong\",");
labelBuilder.AppendLine("\"multiPart\": \"labelLargest\",");
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("}");

 

The problem I have is that even by setting the "allowOverlapOfLabel" value to allow, it is hiding the labels at some zoom levels. I add two screenshots attached from the same mapview making just zoom in and zoom out. I've found that this issue is happening only when the label expression is the same, changing them to have different expressions and then they are always visible as expected. Hope this helps.

 

Appart from this, previously I used this link which was very useful:

JSON label class properties—ArcGIS Runtime SDK for .NET | ArcGIS for Developers

But it does not exist anymore and now there's no information regarding JSON definitions of labels.

Regards

Gonzalo

0 Kudos
13 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

If you always want to place the label regardless of whether it will overlap other features or labels you can force placement by using "deconflictionStrategy":"dynamic".

You may also want to try increasing the priority value to 0 e.g. labelBuilder.AppendLine("\"priority\": 0 ,");

In a future release on the near term roadmap we plan to include a full API for setting labeling properties which will avoid the need to specify via JSON.

0 Kudos
GonzaloMuöoz
Occasional Contributor

Hi,

I'm sorry to say that setting deconflictionStrategy to dynamic is also hiding labels...

Any idea on how to fix this?

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

Apologies - copy/paste error - I meant "deconflictionStrategy":"none".

Using deconfliction strategy static or dynamic you may see some labels not placed due to conflicts with features / labels of higher priority. But a value of none will ensure all labels in that label class are placed regardless of overlaps. 

Thanks

0 Kudos
GonzaloMuöoz
Occasional Contributor

Hi,

even after adding this it's behaving it the same way, It seems there's a bug on this. Should I raise it officially?

Regards

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Have you got a small, standalone repro? 

That will make it easier to investigate further.  

0 Kudos
GonzaloMuöoz
Occasional Contributor

No sorry I do not have it. It should be easy to reproduce it. You just need two GraphicsOverlayCollection with  one graphic with geometry of type line. Then you just assign the labels definition that I put above and the error will be reproduced. Hope it can help to detect the error

0 Kudos
Esther_Pastor_Motrel
Esri Contributor

Hi Mike,

this is Esther Pastor, from Support of Esri Spain and Gonzalo (INdra Eurofighter) has open a case with this issue.

A sample has been attached.

As Gonzalo opened this thread about this behavior, I've thought there is a good idea to provide you the sample.

Thank you so much and best regards.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi Esther and Gonzalo, 

Thanks for the repro.

The additional values required are:

 

labelBuilder.AppendLine("\"allowOverlapOfFeatureBoundary\": \"allow\" ,");
labelBuilder.AppendLine("\"allowOverlapOfFeatureInterior\": \"allow\" ,");

 

Note I also removed the `multiPart` since this only relates to Polygons:

 

labelBuilder.AppendLine("\"multiPart\": \"labelLargest\",");

 

To give this set of options:

 

StringBuilder labelBuilder = new StringBuilder();
labelBuilder.AppendLine("{");
labelBuilder.AppendLine("\"allowOverrun\": true ,");
labelBuilder.AppendLine("\"deconflictionStrategy\": \"dynamic\" ,");
labelBuilder.AppendLine("\"removeDuplicates\": \"none\" ,");
labelBuilder.AppendLine("\"labelExpressionInfo\": {");
labelBuilder.AppendLine("\"expression\": \"return $feature.Name;\"},");
labelBuilder.AppendLine("\"labelPlacement\": \"esriServerLinePlacementCenterAlong\",");
labelBuilder.AppendLine("\"allowOverlapOfFeatureBoundary\": \"allow\" ,");
labelBuilder.AppendLine("\"allowOverlapOfFeatureInterior\": \"allow\" ,");
labelBuilder.AppendLine("\"symbol\": {");
labelBuilder.AppendLine("\"color\": [255,255,255,255],");
labelBuilder.AppendLine("\"haloColor\": [51,51,51,255],");
labelBuilder.AppendLine("\"haloSize\": 2,");
labelBuilder.AppendLine("\"font\": {\"size\": 13, \"weight\": \"bold\"},");
labelBuilder.AppendLine("\"type\": \"esriTS\"}");
labelBuilder.AppendLine("}");
return labelBuilder;

 

Which results in:

MichaelBranscomb_1-1616083872161.png

While testing, because the label text values were identical I appended a value to differentiate and separate from duplicate removal behavior.

Hopefully this solves your scenario?

Regarding the doc on the JSON properties, this has been temporarily removed pending a full developer API for labeling in an upcoming release of ArcGIS Runtime. 

Again, thanks for the simplified repro (and thanks to my colleague Peter for advice on labeling options).

0 Kudos
GonzaloMuöoz
Occasional Contributor

Hi,

Thanks for the answer. We don't want to remove any duplicate, we want to see all the labels all the time,thats why we put:

labelBuilder.AppendLine("\"removeDuplicates\": \"none\" ,");

As stated in one of my previous comments.

Regards

 

0 Kudos