I was trying out some label definitions in Android on a GraphicsOverlay
static final String labelPolygon = "{" + "\"labelExpressionInfo\": {" + // Define a labeling expression that will show the address attribute value "\"expression\": \"return $feature.geometryName;\"}," + "\"labelPlacement\": \"esriServerPolygonPlacementAlwaysHorizontal\"," + // Align labels horizontally "\"where\": \"$feature.geometryType='Polygon'\"}," + "\"symbol\": {" + // Use a black bold text symbol "\"color\": [0,0,0,255]," + "\"haloColor\": [255,255,255,96]," + "\"haloSize\": 2," + "\"font\": {\"size\": 10}," + "\"type\": \"esriTS\"}" + "}"; static final String labelPolyline = "{" + "\"labelExpressionInfo\": {" + // Define a labeling expression that will show the address attribute value "\"expression\": \"return $feature.geometryName;\"}," + "\"where\": \"$feature.geometryType='Polyline'\"}," + "\"labelPlacement\": \"esriServerLinePlacementAboveAlong\"," + // Align labels horizontally "\"symbol\": {" + // Use a black bold text symbol "\"color\": [0,0,0,255]," + "\"haloColor\": [255,255,255,96]," + "\"haloSize\": 2," + "\"font\": {\"size\": 10}," + "\"type\": \"esriTS\"}" + "}"; static final String labelPoint = "{" + "\"labelExpressionInfo\": {" + // Define a labeling expression that will show the address attribute value "\"expression\": \"return $feature.geometryName;\"}," + "\"where\": \"$feature.geometryType='Point'\"}," + "\"labelPlacement\": \"esriServerPointLabelPlacementBelowCenter\"," + // Align labels horizontally "\"symbol\": {" + // Use a black bold text symbol "\"color\": [0,0,0,255]," + "\"haloColor\": [255,255,255,96]," + "\"haloSize\": 2," + "\"font\": {\"size\": 10}," + "\"type\": \"esriTS\"}" + "}"; I thought perhaps that since they have a rule for polygon, polyline, and point, that they would That wasn't the case, and I got too many labels. I get one below and above a point symbol. I tried adding "where" clause to restrict the polygon labels to polygons and so forth. Then all labels dissappear. I have found little to no guidance on what syntax should be followed in a where clause. I don't even know if it is SQL or an Arcade Expression.
In Arcade you have the TypeOf that will allow you to detect these types: Array, Date, String, Boolean, Number, Dictionary, Feature, Point, Polygon, Polyline, Multipoint, Extent, Function, Unrecognized Type
So then what would be the complete syntax?
Any example?
"\"where\": \"TypeOf($feature.geometry)='Polyline'\"}," +
No luck.
Tried:
"\"where\": \"TypeOf($feature)=='Polyline'\"}," + Tried:"\"where\": \"TypeOf($feature)==Polyline\"}," +
Sorry to be dense, but to do this, I will need an exact example.
I am not a programmer, but what I understand is that you are trying to construct the json for the labelExpressionInfo. If I manually set the label expression in a web map, with this (just to see if it can detect the type of geometry in the label expression):
if (TypeOf(Geometry($feature)) == 'Polygon') {
return "A Polygon";
} else if (TypeOf(Geometry($feature)) == 'Polyline') {
return "A Polyline";
} else if (TypeOf(Geometry($feature)) == 'Point') {
return "A Point";
} else {
return "Unknown";
}
... it will create this json section:
"labelExpressionInfo": {
"expression": "if (TypeOf(Geometry($feature)) == 'Polygon') {\n return \"A Polygon\";\n} else if (TypeOf(Geometry($feature)) == 'Polyline') {\n return \"A Polyline\";\n} else if (TypeOf(Geometry($feature)) == 'Point') {\n return \"A Point\";\n} else {\n return \"Unknown\"\n}"
}