LabelClass where clause not working

1463
11
02-01-2021 02:34 PM
JimBambrough
New Contributor II

This works:

 

where: "status = PENDING"

 

I am trying to apply a condition to my LabelClass as follows... the where clause does not seem to be working

 

      labelClass = {
        symbol: {
          type: 'text',  // autocasts as new TextSymbol()
          color: 'black',
          font: {  // autocast as new Font()
            family: 'Material Icons',
          }
        },
        labelPlacement: 'center-center',
        labelExpressionInfo: {
          expression: '"\u2714"'
        },
        where: "status in ('PENDING', 'DRY_RUN')"
      }; 

 

 

 

Tags (1)
0 Kudos
11 Replies
by Anonymous User
Not applicable

What happens if you go long form? 

status = 'PENDING' OR status = 'DRY_RUN'
0 Kudos
JimBambrough
New Contributor II

Yes, I tried that also. In fact, I've tried most every variation I could think of:

 

where: "status = PENDING or status = DRY_RUN"
where: "status = PENDING OR status = DRY_RUN"
where: "status = PENDING || status = DRY_RUN"
where: "status in ('PENDING', 'DRY_RUN')"
where: "status IN ('PENDING', 'DRY_RUN')"
where: "status IN (PENDING, DRY_RUN)"
where: "status = 'PENDING' or status = 'DRY_RUN'"
where: "status = PENDING |DRY_RUN"
where: "status in PENDING |DRY_RUN"

 

0 Kudos
MatthewDriscoll
MVP Alum

Try

"status == 'PENDING' || status == 'DRY_RUN'"

"(status = 'PENDING') || (status = 'DRY_RUN')"

0 Kudos
KenBuja
MVP Esteemed Contributor

There are some strange things going on with the "where" expression. Looking at this sample (and adding in your labelExpressionInfo), I've tried a few different versions. It looks like it doesn't like spaces in the clause.

 

where: "MARKER_ACTIVITY IN ('Picnicking','Sledding/Tubing')" - returns check marks
where: "MARKER_ACTIVITY IN ('Picnicking', 'Sledding/Tubing')" - doesn't return check marks
where: "(MARKER_ACTIVITY = 'Sledding/Tubing') or (MARKER_ACTIVITY = 'Picnicking')" - doesn't return check marks
where: "(MARKER_ACTIVITY = 'Sledding/Tubing')||(MARKER_ACTIVITY = 'Picnicking')" - doesn't return check marks
where: "(MARKER_ACTIVITY = 'Sledding/Tubing') || (MARKER_ACTIVITY = 'Picnicking')" - doesn't return check marks
where: "MARKER_ACTIVITY = 'Sledding/Tubing'" - returns check marks
where: "MARKER_ACTIVITY = 'Intermediate Parent Group'" - doesn't return check marks
where: "MARKER_ACTIVITY like 'Intermediate%'" - returns check marks

 

 

DavidColey
Frequent Contributor

Hi Ken - I got this to work ok in CodePen:

          labelExpressionInfo: {
            expression: "$feature.MARKER_ACTIVITY"
          },
          where: "MARKER_ACTIVITY IN ('Campground Camping', 'Sledding/Tubing')"
        };

regardless of a space (or not) following the comma',' after Campground Camping.

Basically mimics this from the api:

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

labelClass.where = "MARKER_ACTIVITY IN ('Picnicking', 'Group Camping')";

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Yes, it does work using this expression

 

labelExpressionInfo: {
  //expression: '"\u2714"'
  expression: "$feature.MARKER_ACTIVITY"
},
where: "MARKER_ACTIVITY IN ('Campground Camping', 'Sledding/Tubing')"

 

However, it doesn't work when using '"\u2714"'

0 Kudos
DavidColey
Frequent Contributor

Correct, that part is on Jim here.  I'm not sure where his layer is coming from....

0 Kudos
JimBambrough
New Contributor II

Since I did get one simple use case working, I just created 2 LabelClasses and applied them. So in tandem they achieved what I was going for. I ran out of time trying to figure out the where clause. Here is my solution:

 

      labelBase = {
        symbol: {
          type: 'text',  // autocasts as new TextSymbol()
          color: 'black',
          font: {  // autocast as new Font()
            family: 'Material Icons',
            size: size
          }
        },
        labelPlacement: 'center-center',
        labelExpressionInfo: {
          expression: '"\u2714"'
        }
      };

      labelClassDryRun = Object.assign({}, labelBase);
      labelClassDryRun.where = "status = DRY_RUN";

      labelClassServiced = Object.assign({}, labelBase);
      labelClassServiced.where = "status = SERVICED";     
      ......
      labelingInfo: [labelClassServiced, labelClassDryRun, labelInfo] 
0 Kudos
KenBuja
MVP Esteemed Contributor

Did you check whether this (removing the space after the comma) worked?

where: "status in ('PENDING','DRY_RUN')"

 

0 Kudos