CartoDB / mobile-carto-libs

Internal dependencies for CARTO Mobile SDK
BSD 3-Clause "New" or "Revised" License
4 stars 5 forks source link

if test with properties #20

Closed farfromrefug closed 2 years ago

farfromrefug commented 2 years ago

I know we had that discussion before but to be honest i am not sure i understand.

Today i can do :

[id='4'] {
}

And

['nuti::selected_id'='4'] {
}

but not

['nuti::selected_id'=id] {
}

Is there really no way to make the last one work? It would be so useful

mtehver commented 2 years ago

This is a pretty fundamental limitation of CSS syntax (not just CartoCSS) and changing that would really break backward-compatibility. With selectors you are limited to [FIELD op CONSTANT] syntax. For example, the following selector is counter intuitive:

['nuti::selected_id'=id] {
  ...
}

it actually means the following expression: [nuti::selected_id]=='id'. The only workaround is to use conditions in property expressions (line-fill: [nuti::selected_id] == [id] ? red : blue).

farfromrefug commented 2 years ago

@mtehver ok did not know it was a CSS thing. I know the work around and i am using it already. Was hopping we could find a better way. And if i was to write [id=[nuti::selected_id]]. In a sense [nuti::selected_id] could be seen as a constand as not being a field ;) But i understand. I really see it as big "inconvenience" especially when handling "selected" object. something like this:

['nuti::selected_id'=id] {
            back/line-width: @bicycle_line_width + 4;
            line-color: #60A5F4;
            line-width: h + 2;
            marker-placement: line;
            marker-type:arrow;
            marker-line-width:0;
            marker-opacity:0.6;
            marker-width: @bicycle_line_width;
            marker-height: @bicycle_line_width;
            marker-fill: #B3CEFF;
            [class=pedestrian] {
                back/line-width: @pedestrian_line_width+ 4;
                marker-width: @pedestrian_line_width;
                marker-height: @pedestrian_line_width;
            }
        }

becomes really hard to write with the workaround. I wish we could find a way. It would help so much

farfromrefug commented 2 years ago

I can confirm this is fixed with the when condition! Such a crazy framework!!!