Arcade labeling

1199
6
11-09-2018 02:22 AM
José_CarlosPalma_García
New Contributor II

Hello,

I'm traying to label a feature service in a webmap. This feature service is a point layer with one meter division. I only want label the subdivisions each 5 metros and the start and the end point. I've test with "IIf" and "When", but I can't get it.

Thanks and regards

Bjorn Svensson

0 Kudos
6 Replies
BjornSvensson
Esri Regular Contributor

What does the data look like?
Does the data have attributes with that information?  For example, could you just display features where the attributes end in "0m" and "5m"?

0 Kudos
XanderBakker
Esri Esteemed Contributor

If your field "label" is numeric, you could use this:

if (label % 5 == 0) {
    return $feature["GEOMETRIA_"] + "-" + $feature["label"] + "m";
} else {
    return "";
}
‍‍‍‍‍

This will not label your end-point if the value is not a multiple of 5. You will need to indicate in another field when the value is the end point to do this, since Arcade is not able to read out the maximum value over a series of features.

José_CarlosPalma_García
New Contributor II

"Label" field contains measure each 1 meter. But I only want to label 0, numbers ending 0 and 5 and final measure (decimal number). Can I order "label text ending 0, ending 5 and decimal number"? "Label" is string...

0 Kudos
XanderBakker
Esri Esteemed Contributor

So, the "Label" field contains a string and the last value is a decimal number (stored as string). In that case to label the values ending on 0 or 5, you could still use the same sample, however, it is necessary to convert the string to a number using the Number function:

if (Number(label) % 5 == 0) {
    return $feature["GEOMETRIA_"] + "-" + $feature["label"] + "m";
} else {
    return "";
}

In case only the last value is a decimal stored as a string (what decimal sign are you using, a dot or a comma?), you could detect that and include that as an additional condition in the expression. To be able to know how to the data is stored, could you include a screenshot of your attribute table showing the values of the Label field?

José_CarlosPalma_García
New Contributor II

0 Kudos
XanderBakker
Esri Esteemed Contributor

One of the things you could do is this:

var geom = $feature["GEOMETRIA_"];
var label = $feature["label"];

if (Find(",", label) == -1) {
    if (Number(label) % 5 == 0) {
        return geom + "-" + label + "m";
    } else {
        return "";
    }
} else {
    return geom + "-" + label + "m";
}