Select to view content in your preferred language

Labels not displaying in Map Viewer although Arcade expression tests successfully

538
2
09-01-2023 11:03 AM
Labels (2)
JPrescott
New Contributor II

In ArcGIS Portal an Arcade labeling expression is testing successfully in the Arcade editor (returns expected value in the Results tab), but the feature in the Map Viewer/Visualization does not display.  All features in this layer remain unlabeled.

2023-09-01_10-43-42.jpg

 

2023-09-01_10-49-01.jpg

 

The full arcade expression is below.  This same expression works within ArcGIS Pro (features are labeled) .

////////////////////////////////////////
// label order: 1-MaxFeatID if joined, 2-IDPK if not joined, 3-MaximoID (if Metro returns last 5 chars with prefix "*" or "HYD" if hydrant/hyd valve, if not Metro returns full MaxID), 4-FeatureName
//////////
var commodity = 'water'
var assettype = 'hydrant'

var field_typeassetnum = assettype + '_assetnum'
var field_typefeatid = assettype + '_featureid'
var field_locations = 'locations_location'
var field_nodeidpk = commodity + 'utilitynodeidpk'
var field_featureidpk = commodity + 'utilityfeatureidpk'
var field_max = 'maximoassetidfk'
var field_maxloc = 'maximolocationidfk'

var feat_text = Text($feature)
var portal_tf = when(Find('editor', feat_text) != -1, True, False)
Console('portal_tf: '+portal_tf)

if(portal_tf == False){
    Expects($feature, 'maximoassetidfk', 'waterutilitynodeidpk', 'waterutilityfeatureidpk', 'locations_location', 'maximolocationidfk', 'capbank_assetnum', 'condcltr_assetnum', 'ctrlvalve_assetnum', 'dynprotdev_assetnum', 'electmeter_assetnum', 'encl_assetnum', 'expjoint_assetnum', 'generator_assetnum', 'gtows_assetnum', 'hydrant_assetnum', 'inst_assetnum', 'line_assetnum', 'mechmeter_assetnum', 'motor_assetnum', 'pipe_assetnum', 'pump_assetnum', 'receptacle_assetnum', 'relvalve_assetnum', 'shorepwr_assetnum', 'statprodev_assetnum', 'supstructure_assetnum', 'surfstructure_assetnum', 'switch_assetnum', 'sysvalve_assetnum', 'tank_assetnum', 'ugstructure_assetnum', 'voltreg_assetnum', 'well_assetnum', 'xfmr_assetnum', 'capbank_featureid', 'condcltr_featureid', 'ctrlvalve_featureid', 'dynprotdev_featureid', 'electmeter_featureid', 'encl_featureid', 'expjoint_featureid', 'generator_featureid', 'gtows_featureid', 'hydrant_featureid', 'inst_featureid', 'line_featureid', 'mechmeter_featureid', 'motor_featureid', 'pipe_featureid', 'pump_featureid', 'receptacle_featureid', 'relvalve_featureid', 'shorepwr_featureid', 'statprodev_featureid', 'supstructure_featureid', 'surfstructure_featureid', 'switch_featureid', 'sysvalve_featureid', 'tank_featureid', 'ugstructure_featureid', 'voltreg_featureid', 'well_featureid', 'xfmr_featureid')
}

Console(Text($feature))

var idpk = When(Haskey($feature, field_nodeidpk), $feature[field_nodeidpk], Haskey($feature, field_featureidpk), $feature[field_featureidpk], '')
var typeassetnum = When(Haskey($feature, field_typeassetnum), $feature[field_typeassetnum], Haskey($feature, field_maxloc), $feature[field_maxloc], '')
var typefeatid = When(Haskey($feature, field_typefeatid), $feature[field_typefeatid], Haskey($feature, field_locations), $feature[field_locations], '')
var maxid = When(Haskey($feature, field_max), $feature[field_max], '')

Console(iif(Haskey($feature, field_nodeidpk)||Haskey($feature, field_featureidpk), 'haskey - idpk', 'DOES NOT haskey - idpk'))
Console(iif(Haskey($feature, field_typeassetnum)||Haskey($feature, field_maxloc), 'haskey - typeassetnum or maxloc', 'DOES NOT haskey - typeassetnum or maxloc'))
Console(iif(Haskey($feature, field_typefeatid)||Haskey($feature, field_locations), 'haskey - typefeatid or locations', 'DOES NOT haskey - typefeatid or locations'))
Console(iif(Haskey($feature, field_max), 'haskey - maxid', 'DOES NOT haskey - maxid'))

// //
// if(Haskey($feature, field_max)){
//     Console('haskey - maxid')
//     var maxid = $feature[field_max]
// }
// else
// {
//     Console('DOES NOT haskey - maxid')
//     var maxid = ''
// }
// //////////

var site = $feature.installationid 
var fn = $feature.featurename 

// QC variables
site = when(!IsEmpty(site), Trim(site), '')
idpk = when(!IsEmpty(idpk), Trim(idpk), '') 
maxid = when(!IsEmpty(maxid), Trim(maxid), '') 
fn = when(!IsEmpty(fn), Trim(fn), '') 
typeassetnum = when(!IsEmpty(typeassetnum), Trim(typeassetnum), '') 
typefeatid = when(!IsEmpty(typefeatid), Trim(typefeatid), '') 

// display variables (QC labeling)
//return('site:'+site+'\nfn:'+fn+'\ntypeassetnum:'+typeassetnum+'\ntypefeatid:'+typefeatid+'\nidpk:'+idpk+'\nmaxid:'+maxid)

// metro=NBPL, NBC, NBSD, NAFEC 
var uic = when(Count(site) > 5, Left(site, 6), site) 
var metro = ['N63406', 'N00246', 'N00245', 'N60042'] 
var metro_tf = Boolean(IndexOf(metro, uic)+1) 

var badvals = ['ABANDONED', 'Vault', 'Hand Hole', 'Junction Box', 'Pull Box', 'Handhole', 'Manhole', 'New', 'NEW', 'NA', 'Null', 'unk', 'Unk', 'UNK', 'Unknown', 'UNKNOWN', '99999', 'Awaiting Maximo Record', 'TBD', 'LEMOOR-U89', 'Airfield Light', 'DropInlet', '068111M', '088111M', 'PORHUE-U73', 'POIMUG-S31', 'POIMUG-S5', 'CHILAK-S72', 'LEMOOR-U13', '32052', 'Parking Lot Light', 'Street Light', '280060', '2-07516SL', 'Security Light', 'BASNI27 TAXI LIGHT', 'LEMOOR-U80', 'CurbInlet', 'CHILAK-S12', 'Private', '200753', 'UMA254000224', '2-08301PL', '068111MAREA12', 'CatchBasin', 'R84714', 'Unk', 'R126016', 'CurbCut', 'BASNIS17  LIGHTING', 'R84642', '200534', '066311MAREA01', 'R56663', 'R72084', 'R126248', 'CHILAK-S14', '068111MAREA02', '068111MPIER07', 'UMA254000222', 'R126084', 'R84709', '068111MPIER13', '068111MPIER02', 'CHILAK-41252', '068111MPIER03', '068111MPIER04', 'R126242', '068111MPIER08', 'R116581', '068111MPIER05', '068111MPIER10', 'Traffic Light', 'R146796', '068111MPIER12', '086311MAREA01', 'POIMUG-200327', 'R84691', 'LTG-SEC', 'R126507', 'R126514', 'R84673', 'NBC-N-12', 'UMA254000226', 'IID', '068111MPIER01', '068111MPIER06', 'NBSD-PW-SA-PR10', '118311MAREA03', 'Asset creation required', 'R84695', '289062', '118311MAREA02', '118311MAREA01', 'R126177', 'Riser', 'R116524', 'R126520', 'Walkway Light', '0', 'CHILAK-U19', '086311MAREA06', 'R83758', 'R84677', 'Recreation Field Light', 'R126189', 'PipeInlet', '<Null>', 'NOT IN MAXIMO', 'UMA339000429', 'UMA260000011', 'R143822', '086311MAREA06-SDG&E', 'POIMUG-SS', 'UMA254000225', '025128STAC-01', 'Abn', 'No', 'R126178', 'R126183', 'R126190', '086311MAREA07', 'CHILAK-02755', 'R116520', 'R45432', '086311MAREA05', 'Asset creation needed', 'NASSCO', 'NEEDNEW_WASDUPE', 'location needed', 'N/A', 'UNKNOWN', 'BoxInlet', 'Other', '+', 'WELL'] 

idpk = when(Boolean(IndexOf(badvals, idpk)+1), '', idpk) 
maxid = when(Boolean(IndexOf(badvals, maxid)+1), '', maxid) 
fn = when(Boolean(IndexOf(badvals, fn)+1), '', fn) 

fn = when(Count(fn) > 20, trim(Right(fn, 20)), fn) 

if (metro_tf == True) 
    { 
    var maxidvalid = when(!IsEmpty(typeassetnum), True, False) 
    var typefeatidvalid = when(!IsEmpty(typefeatid) && maxid != typefeatid, True, False) 
    idpk = when(maxidvalid == True && typefeatidvalid == True, typefeatid, idpk) 
    var hyd = when(Find('HYD', maxid) != -1, True, False) 
    if (hyd == True) 
        { 
        var hydptct = when(hyd == True, Count(Split(maxid, 'HYD')), 0) 
        var hydpt1 = when(hyd == True && hydptct == 2, trim(Split(maxid, 'HYD')[0]), '') 
        var hydpt2 = when(hyd == True && hydptct == 2, trim(Split(maxid, 'HYD')[1]), '') 
        maxid = when(hydptct == 2 && hydpt2 != '', Concatenate(['HYD', hydpt2]), 
                 hydptct == 2 && hydpt2 == '', maxid, 
                     maxid 
                 )    
        } 
    else 
        {maxid = when(Count(maxid) >= 5, "*"+trim(Right(maxid, 5)), maxid)}  
    Console(when(!IsEmpty(idpk), idpk, IsEmpty(idpk) && !IsEmpty(fn), fn, IsEmpty(idpk) && IsEmpty(fn), maxid, ''))
    return when(!IsEmpty(idpk), idpk, IsEmpty(idpk) && !IsEmpty(fn), fn, IsEmpty(idpk) && IsEmpty(fn), maxid, '') 
   } 

   if (metro_tf == False) 
   { 
   var maxidvalid = when(!IsEmpty(typeassetnum), True, False) 
   var typefeatidvalid = when(!IsEmpty(typefeatid), True, False) 
   idpk = when(maxidvalid == True && typefeatidvalid == True, typefeatid, idpk) 
   //return when(!IsEmpty(idpk), idpk, IsEmpty(idpk) && !IsEmpty(fn), fn, IsEmpty(idpk) && IsEmpty(fn), maxid, '') 
   Console(when(!IsEmpty(idpk), idpk, IsEmpty(idpk) && !IsEmpty(maxid), maxid, IsEmpty(idpk) && IsEmpty(maxid) && !IsEmpty(fn), fn, ''))
   return when(!IsEmpty(idpk), idpk, IsEmpty(idpk) && !IsEmpty(maxid), maxid, IsEmpty(idpk) && IsEmpty(maxid) && !IsEmpty(fn), fn, '') 
  } 

  Console() output in the messages tab, which mirror the Return statements, also shows the correct label value.

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

Even though the code will work in the test, the HasKey function will return the false value in the Labeling Profile. So a simple test like this will return 'Yes' in the console, but 'No' in the map.

var idpk = When(Haskey($feature, 'Field_ID'), 'Yes', 'No');
return idpk

HasKey.png

The Popup profile does have access to this function, so if I add that expression to the popup, it shows up as Yes.

HasKey1.png

Now the weird thing is, if I zoom in and out a couple of times, suddenly the labels are getting changed to "Yes"

HasKey2.png

I did another test by creating a new map with the same data and only adding the label expression, but not the popup expression. If I zoomed in and out enough times, the labels changed to "Yes".

When I save the map and open it again, the labels are showing up as "Yes".

0 Kudos
KenBuja
MVP Esteemed Contributor

I did one more test. I added a new layer and use the same label expression, with the labels showing "No" as expected. However, without zooming, I save the map and reopened it. Now the label say "Yes".

So try saving your map and seeing if the labels come up when you reopen it.

0 Kudos