Select to view content in your preferred language

javascript 4.6 and labeling FeatureLayer

2761
16
Jump to solution
01-09-2018 02:59 PM
CynthiaKozma
Frequent Contributor

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.

0 Kudos
16 Replies
MichaelLodes2
Regular Contributor

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

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

WWalker
Occasional Contributor

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

};

0 Kudos
Noah-Sager
Esri Regular Contributor

Hi William. Currently, the `where` property only has limited support. We are hoping to expand it's usage at the next release.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-LabelClass.html#wh...

For now, I would recommend using Arcade for the labeling logic in the labelExpression or labelExpressionInfo.

-Noah

0 Kudos
WWalker
Occasional Contributor

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.

0 Kudos
WWalker
Occasional Contributor

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.

CynthiaKozma
Frequent Contributor

That's it!  I used the MapImageLayer instead, and I got my labels.  If that is what it takes for now.  Thank you!

0 Kudos