I am new to javascript, but I am trying to put together a fairly simple application with v4.6. I have a contour layer that I am adding with new FeatureLayer(), but I am having a hard time getting it to label with elevation. I have tried using a Map Service hosted on our server, as well as, a hosted Feature Layer on AGOL (where the contours are already labeled in both). No luck with either. I have read that you can't label a 2D map, does this mean that it is virtually impossible to label the contours?? Is there any work around? A label would be so much better than a pop-up. Thanks for the help.
Solved! Go to Solution.
Hi Robert,
I dont understand if labeling (for example with angle) is possible for a "hosted feature layer" on AGOL in 4.8. Could you tell me? (Sorry I am not able relate the word "FeatureServer service".)
Thank you,
Michael
Michael,
A hosted featurelayer will be a FeatureService. What is meant by FeatureService is "FeatureService" in the url Vs. MapService that you might have on your own ArcGIS Server.
I'm using 4.9 with a FeatureService on Server 10.5.1. I can render labels, but it seems that the 'where' property of the LabelClass does not work properly. Is this a known issue, or am I missing something? See below:
const classificationClass = {
labelExpressionInfo: {
expression: "$feature.SPACECLASS + TextFormatting.NewLine + $feature.SPACEID"
},
minScale: 100,
labelPlacement: "always-horizontal",
symbol: brnTxtSym, // defined elsewhere
where: "SPACECLASS = 'Office'" // <-----This does not work
};
Hi William. Currently, the `where` property only has limited support. We are hoping to expand it's usage at the next release.
For now, I would recommend using Arcade for the labeling logic in the labelExpression or labelExpressionInfo.
-Noah
I am using Arcade for the textual logic, however I would like to symbolize features based on attributes.
Similar to this example:
ArcGIS API for JavaScript Sandbox
But for whatever reason, my where clause (for a string type field) does not work.
If, for example, I change my where clause to "OBJECTID > 120", it works.
I found a partial solution. Text field comparisons do not require text to be wrapped in single quotes.
For instance, from the link Noah provided:
labelClass.where = "CITYNAME = 'Redlands'";
should be:
labelClass.where = "CITYNAME = Redlands";
EDIT: This does not seem to apply to strings with spaces - i.e. "CITYNAME = Redlands North" - does not work, with or without single quotes.
Another undocumented limitation.
That's it! I used the MapImageLayer instead, and I got my labels. If that is what it takes for now. Thank you!