I have following StringBuilder:
{
"allowOverlapOfLabel": "allow" ,
"allowOverlapOfFeatureBoundary": "allow" ,
"allowOverlapOfFeatureInterior": "allow" ,
"labelExpressionInfo": {
"expression": "return $feature.Name;"},
"labelPlacement": "esriServerPointLabelPlacementCenterRight",
"multiPart": "labelPerFeature",
"minScale": "return $feature.MinScale;",
"maxScale": 0,
"symbol": {
"color": [255,255,255,255],
"haloColor": [51,51,51,255],
"haloSize": 1.5,
"font": {"size": 10, "weight": "bold"},
"type": "esriTS"}
}
My problem is that when doing LabelDefinition.FromJson method with this string, I get an invalid character exception on minScale value.
MinScale attribute is a string defined in the attributes of each graphic and minScale key on the Json needs an integer. How can this conversion be done or how can I pass minScale value as a $feature value?
Thanks
Solved! Go to Solution.
Hi,
Only properties that are explicitly described as expressions, such as the `labelExpressionInfo.expression` or the `labelAngleInfo.angleExpressionInfo.expression` can (and must) contain an Arcade expression.
Cheers
Mike
Hey Gonzalo -
You might want to take a look at the approach (and code) described in this blog: https://community.esri.com/community/developers/native-app-developers/arcgis-runtime-sdk-for-net/blo....
In addition to making the code easier to work with and maintain, you have some control over how the values you're using are returned (int vs string, etc.).
Thad
UPDATE:
Sorry, after taking a closer look I see that the problem you're facing is getting the expression "return $Feature.MinScale" to provide an integer from the underlying string value.
I'm not sure, but it looks like the Arcade "Number" function might do the trick: Data Functions | ArcGIS for Developers
Hi Thad,
thanks for the answer. I'm trying your recommendation using Number expresion like this just to test how it works and if I can use it. This is how I'm using it::
labelBuilder.AppendLine("\"minScale\": Number('700000','######'),");
and I'm getting following exception:
"expecting NaN": Num : 303
What's the problem now?
I tested this a little on my end and I'm experiencing the same thing.
There's a nice tool here for testing Arcade expressions: ArcGIS Arcade | ArcGIS for Developers and the `Number` expressions I tried were returning valid values. When I tried it in my labeling JSON, however, I got mixed results.
If I tried it in the labeling expression it worked. For example:
"\"expression\": \" Number('1000000', '########') + ' meters';\"},"
But the same expression fails when used for `minScale`:
"\"minScale\": Number('1000000', '########'),"
I'm not sure if the expression is supposed to work outside of the actual label expression. I'll look into that further and let you know what I find.
Thad
Arcade expressions are indeed only supported for use in label or rotation expressions. Other label properties (like minimum scale) cannot interpret Arcade. As ArcGIS Pro enables more labeling properties to use expressions, ArcGIS Runtime will add support as well.
Do you know when this functionality will be added?
Any advance on this?
Hi,
Only properties that are explicitly described as expressions, such as the `labelExpressionInfo.expression` or the `labelAngleInfo.angleExpressionInfo.expression` can (and must) contain an Arcade expression.
Cheers
Mike