Labeling by arcade||Etiquetar mediante arcade

228
2
Jump to solution
06-07-2022 07:52 AM
JavierCMartínezPrieto
Occasional Contributor

good afternoon, everyone,
I have a webmap where I represent kilometer points every meter, I would like to be able to label those P.K every 5 meters and for that I need to use an expression in arcade, but I can't find the solution.
I am currently trying a conditional with the expression equal or default but I don't get what I am looking for.
Does anyone know what would be the expression to label those P.K every 5 meters?

Thanks to all of you who participate.

example code:


if (DefaultValue($feature.cngmetros, 0))
return Pkinicial
else (DefaultValue($feature.cngmetros, 5))
return PK5metros
else (DefaultValue($feature.cngmetros, ','))
return Pk5metros
else (DefaultValue($feature.cngmetros, '.'))
return Pk5metros

Greetings Javier

#############################ESPAÑOL##########################################

 

buenas tardes a todos ,
tengo un webmap donde represento puntos kilométricos cada metro, me gustaría poder etiquetar esos P.K cada 5 metros y para ello necesito utilizar un expresión en arcade, pero no encuentro la solución.
actualmente estoy intentando un condicional con la expresion equal o default pero no consigo lo que busco.
¿alguien sabe cual seria la expresion para etiquetar esos P.K cada 5 metros?

Gracias a todos lo que participeis.

ejemplo de codigo:


if (DefaultValue($feature.cngmetros, 0))
return Pkinicial
else (DefaultValue($feature.cngmetros, 5))
return PK5metros
else (DefaultValue($feature.cngmetros, ','))
return Pk5metros
else (DefaultValue($feature.cngmetros, '.'))
return Pk5metros

Saludos Javier

 

Javier C. Martinez Prieto
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

To find multiples of a number, you can use the modulo operator. X modulo Y means "divide X by Y and return the rest". If the modulo is zero, X is divisible by Y, so it's a multiple.

So you could do something like this:

var cngmetros = $feature.cngmetros
// if value is zero or divisible by 5
// % is the modulo operator in many languages
if(cngmetros == 0 || cngmetros % 5 == 0) {
    return cngmetros
}

Have a great day!
Johannes

View solution in original post

2 Replies
JillianStanford
Occasional Contributor III

Hi Javier,

I'm not sure that DefaultValue is the function that you want. It evaluates the first parameter and if it finds null or an empty string it returns the second parameter.

Are you wanting to return "Pkinicial" if the value of the cngmetros field is 0 and "Pk5metros" if the value of cngmetros is a multiple of 5?

JohannesLindner
MVP Frequent Contributor

To find multiples of a number, you can use the modulo operator. X modulo Y means "divide X by Y and return the rest". If the modulo is zero, X is divisible by Y, so it's a multiple.

So you could do something like this:

var cngmetros = $feature.cngmetros
// if value is zero or divisible by 5
// % is the modulo operator in many languages
if(cngmetros == 0 || cngmetros % 5 == 0) {
    return cngmetros
}

Have a great day!
Johannes