Select to view content in your preferred language

advanced label expression in Arcgis server doesn't label

4270
6
02-11-2013 06:50 AM
soniadickerson1
Regular Contributor
I'd like to use the following advanced label expression for a layer in a map service.  This javascript function works in arcmap, but does not label the features when its published as a map service.  In the publishing preview window the labels do appear, but not in the finished service. 

function FindLabel ( [NPC_CATEGORY_ID] )
{

idArray=["231","371","372","375","376"];
codeArray=["WPn53","WMs83","WMs92","WPn53","WPn53"];
var labelValue = [NPC_CATEGORY_ID];

for (var i=0,l=idArray.length; i<l; i++)
{
   if  (idArray ==  [NPC_CATEGORY_ID] ){
     labelValue = codeArray;
  }
}

return labelValue;


}


Although, it doesn't present a solution that I could use, the following thread is similar:
http://forums.arcgis.com/threads/70413-Handling-NULL-Dates-in-Labels?highlight=label


If you have any thoughts on this one, please let me know.
Thanks greatly,
Sonia
Tags (2)
0 Kudos
6 Replies
JasonGreenlaw
Regular Contributor
It's possible that JavaScript is not supported in ArcGIS Server (though I can't find any documentation to confirm that). 

Perhaps try changing the parser to Python and rewrite it.  Here's what a more efficient version would look like in Python:


def FindLabel( [NPC_CATEGORY_ID] ):
    npcId = [NPC_CATEGORY_ID]
    idCodes = {
        "231": "WPn53",
        "371": "WMs83",
        "372": "WMs92",
        "375": "WPn53",
        "376": "WPn53"
    }
    if npcId in idCodes:
        return idCodes[npcId]
    return npcId


or, here's what your original function looks like in Python without modification:

def FindLabel( [NPC_CATEGORY_ID] ):
    idArray = ["231","371","372","375","376"]
    codeArray = ["WPn53","WMs83","WMs92","WPn53","WPn53"]
    labelValue = [NPC_CATEGORY_ID]
    for i in range(len(idArray)):
        if idArray == [NPC_CATEGORY_ID]:
            labelValue = codeArray
    return labelValue
0 Kudos
JasonLevine
Deactivated User
I am having a similar problem when using python to create an advanced label expression in my service.  My labels draw in my service, however, when looking at the properties in the rest endpoint, the "Labeling Info" comes up as null, even though the "Has Labels" property is true:
[ATTACH=CONFIG]23776[/ATTACH]
First I tried this with the advanced box checked:
[ATTACH=CONFIG]23777[/ATTACH]
Then I tried writing it in one line without the advanced box checked:
[ATTACH=CONFIG]23778[/ATTACH]

Both work in the map, but the Labeling Info property is still null.  Is this a known issue? Should I try something different?

Thanks,
Jason
0 Kudos
JasonLevine
Deactivated User
I realized I could make this even simpler by removing the if statement (which I don't need):
[ATTACH=CONFIG]23828[/ATTACH]
I'm now using a very simple python string replace function:
Replace([Name],"Chp","CHP")


Still, nothing shows up for Labeling Info at the rest endpoint:
[ATTACH=CONFIG]23829[/ATTACH]

Why is something as simple as this causing an error in ArcGIS Server (10.1)?  I thought it was supposed to support python?

Thanks,
Jason
0 Kudos
TanuHoque
Esri Regular Contributor
LabelingInfo in a mapservice's layer's resources (on REST) always returns null when advanced-expression is used to define labels.

dynamic map service's export call will draw them correctly though using the advanced labeling expression that you set in the source map, it is just that LabelingInfo will always be null (when advanced expression is used).
0 Kudos
JasonLevine
Deactivated User
LabelingInfo in a mapservice's layer's resources (on REST) always returns null when advanced-expression is used to define labels.

dynamic map service's export call will draw them correctly though using the advanced labeling expression that you set in the source map, it is just that LabelingInfo will always be null (when advanced expression is used).


Thanks for this information.  Why would the entire LabelingInfo object come up null just because an advanced expression is used? I'm trying to develop a label toggle feature into my table of contents panel and need to know the label min and max scales for each layer.  For me, the expression used is irrelevant.  Is there any other way to get at the information I need while still using an advanced label expression?

Thanks,
Jason
0 Kudos
AndersKarlgren
New Contributor
I also have a problem with labels not showing after publishing my service. All works fine and the labels shows up in the "Preview for Arc GIS Server" in the "Service Editor". Anyone found a solution to this?

Regards

/Anders
0 Kudos