Select to view content in your preferred language

labeling rendering

748
7
Jump to solution
06-28-2023 04:45 AM
Labels (1)
MarcelSt-Germain
Frequent Contributor

Hi,

I wonder if I'm the only one with this problem.  I have a few layers with the same field to parse, with the same script to make the labeling (copy and paste many time between the ones with the right result and the one not parsing correctly.

You can see, in the picture below the result.  Remember, it's the same script copied from the lateral buoy (in bleu) and paste on the special purpose one (white-orange).  The display of (Priv.) in 4 pt, gray an italic is parse wright in the lateral but, instead show the coding in the special purpose.

It's the same STATUT field with the same type text.  Some Idea why it parse the parameters on all, I haven't find an other exemple, my layers with the same script except this one.

MarcelStGermain_0-1687952309191.png

 

0 Kudos
2 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You don't need to change the data. Change line 82 to this:

name1= Replace([NAME],"&","&")  

 You'll have to do the same if you have any labels with the other special character (<).

View solution in original post

0 Kudos
KenBuja
MVP Esteemed Contributor

This is one way to write it in Arcade. This uses the When function and template literals

var arrStatus = Split($feature.STATUS,",");
var arrOut= []
for (var i in arrStatus){
  var tmpStr = Number(Trim(arrStatus[i]));
  console(tmpStr)
  When(tmpStr == 2, push(arrOut,'Occa.'),
       tmpStr == 3, push(arrOut,'Recom.'),
       tmpStr == 4, push(arrOut,'Not in use / Hors service'),
       tmpStr == 5, push(arrOut,'Intermitent / Intermittent'),
       tmpStr == 6, push(arrOut,'Reserved / Réservé'),
       tmpStr == 7, push(arrOut,'Temp.'),
       tmpStr == 8, push(arrOut,'Priv.'),
       tmpStr == 9, push(arrOut,'Manda.'),
       tmpStr == 11, push(arrOut,'Exting. / Éteint'),
       tmpStr == 12, push(arrOut,'Illu.'),
       tmpStr == 13, push(arrOut,'Histo.'),
       tmpStr == 14, push(arrOut,'Publ.'),
       tmpStr == 15, push(arrOut,'Sync.'),
       tmpStr == 16, push(arrOut,'Watched / Surveillé'),
       tmpStr == 17, push(arrOut,'Un-Watched / Sans surveillance'),
       tmpStr == 18, push(arrOut,'Doubtful / Douteux'),
       push(arrOut, ""))
}
var var_st = Concatenate(arrOut," ");
if (!IsEmpty(Trim(var_st))) var var_st =`<ITA><FNT name = 'Constantia' size= '4'><CLR red = '78' green = '78' blue = '78'>(${var_st})</CLR></FNT></ITA>`
var name = Replace($feature.NAME, '&', "&amp;");
return `${name} ${var_st}`

 

View solution in original post

0 Kudos
7 Replies
KenBuja
MVP Esteemed Contributor

Those particular labels have a special character (&) which caused problems with formatting tags. From the documentation:

The ampersand (&) and angle bracket (<) are special characters and are not valid in your text if formatting tags are used. Use the equivalent character codes &amp; and &lt; instead.

If you have special characters embedded in the values of the label field, you can replace them dynamically using a simple label script.

Label Expression - Arcade
"<BOL>" + replace($feature.Notes, "&", "&amp;") + "</BOL>"
Label Expression - VBScript
Function FindLabel ([LABELFIELD])
  NewString = Replace([LABELFIELD],"&","&amp;")  
  FindLabel = "<ITA>" & NewString & "</ITA>"
End Function
0 Kudos
MarcelSt-Germain
Frequent Contributor

What I doesn't understand is my script is exactly the same in each of my layer parsing Name and Status.

So why two rendering.  I know the rule for formatting tags and they are the same.  Can't find the problem since it's always the same script.  If you pinpoint the problem I will appreciate.

The expression is said valid. Here my script in VB. I try to convert this script in arcade or python to see if the problem stick but I can't manage the case.

NameStatut.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Can you add that script using the code sample instead of a picture? It's very hard to see it and impossible to copy a section of it to show you where the problem is.

If you look closely at the label in question, it contains the text "Kings Harbor Units 7 & 8 Discharge Buoy". You have to replace the & in the Name field in your code

0 Kudos
MarcelSt-Germain
Frequent Contributor

Ok, haven't know this feature for the code so there it is since VB is not listed I use markdown.  Ok I think I understand for the &.  Unfortunately, we can't edit data, it's the Name.

Function FindLabel ( [NAME] , [STATUS]    )

     var =  [STATUS] 

     splitStr = Split(var, ",")

     For i = 0 To UBound(splitStr)

         tmpStr = Trim(splitStr(i))

      Select Case tmpStr

    Case " "
        splitStr(i) = ""
    Case ""
        splitStr(i) = ""    
    Case "0"
        splitStr(i) = ""
    
    Case "1"
        splitStr(i) = ""

    Case "2"
        splitStr(i) = "Occa."

    Case "3"
        splitStr(i) = "Recom."

    Case "4"
        splitStr(i) = "Not in use / Hors service "

    Case "5"
        splitStr(i) =  "Intermitent / Intermittent "

    Case "6"
        splitStr(i) = "Reserved / Réservé"

    Case "7"
        splitStr(i) = "Temp."

    Case "8"
        splitStr(i) = "Priv."

    Case "9"
        splitStr(i) = "Manda."

    Case "11"
        splitStr(i) = "Exting. / Éteint"

    Case "12"
        splitStr(i) = "Illu."

    Case "13"
        splitStr(i) = "Histo."

    Case "14"
        splitStr(i) = "Publ."

    Case "15"
        splitStr(i) = "Sync."

    Case "16"
        splitStr(i) = "Watched / Surveillé"

    Case "17"
        splitStr(i) = "Un-Watched / Sans surveillance"

    Case "18"
        splitStr(i) = "Doubtful / Douteux"

         End Select
 Next

      var_st = Join(splitStr, " ")
If (var_st <> "" And var_st <> " " ) Then

var_st1 ="<ITA><FNT name = 'Constantia' size= '4'><CLR red = '78' green = '78'  blue = '78'>" & "(" & var_st & ")"  & "</CLR></FNT></ITA>"

End If   

If ( [NAME] <>" " And [NAME] <> "") Then
name1 = [NAME] 
End If
FindLabel = name1  &"  "&  var_st1

End Function

 

0 Kudos
KenBuja
MVP Esteemed Contributor

You don't need to change the data. Change line 82 to this:

name1= Replace([NAME],"&","&amp;")  

 You'll have to do the same if you have any labels with the other special character (<).

0 Kudos
MarcelSt-Germain
Frequent Contributor

Thanks, I will try it and include it in all my script.  By the way, in arcade or python how can I replace the case statement.  I try but alway had error.

0 Kudos
KenBuja
MVP Esteemed Contributor

This is one way to write it in Arcade. This uses the When function and template literals

var arrStatus = Split($feature.STATUS,",");
var arrOut= []
for (var i in arrStatus){
  var tmpStr = Number(Trim(arrStatus[i]));
  console(tmpStr)
  When(tmpStr == 2, push(arrOut,'Occa.'),
       tmpStr == 3, push(arrOut,'Recom.'),
       tmpStr == 4, push(arrOut,'Not in use / Hors service'),
       tmpStr == 5, push(arrOut,'Intermitent / Intermittent'),
       tmpStr == 6, push(arrOut,'Reserved / Réservé'),
       tmpStr == 7, push(arrOut,'Temp.'),
       tmpStr == 8, push(arrOut,'Priv.'),
       tmpStr == 9, push(arrOut,'Manda.'),
       tmpStr == 11, push(arrOut,'Exting. / Éteint'),
       tmpStr == 12, push(arrOut,'Illu.'),
       tmpStr == 13, push(arrOut,'Histo.'),
       tmpStr == 14, push(arrOut,'Publ.'),
       tmpStr == 15, push(arrOut,'Sync.'),
       tmpStr == 16, push(arrOut,'Watched / Surveillé'),
       tmpStr == 17, push(arrOut,'Un-Watched / Sans surveillance'),
       tmpStr == 18, push(arrOut,'Doubtful / Douteux'),
       push(arrOut, ""))
}
var var_st = Concatenate(arrOut," ");
if (!IsEmpty(Trim(var_st))) var var_st =`<ITA><FNT name = 'Constantia' size= '4'><CLR red = '78' green = '78' blue = '78'>(${var_st})</CLR></FNT></ITA>`
var name = Replace($feature.NAME, '&', "&amp;");
return `${name} ${var_st}`

 

0 Kudos