3

Is it possible to use attribute and zoom based condition to apply CSS style in GeoServer? I have a point layer, I would like to use attribute and zoom based condition to apply a colour style and sizes at different zoom levels. I have tried different code combinations but not been successful. Below is my latest attempt but the style is not applied.

* {
    label: [No];
    mark: symbol(circle);
   
      :mark {
     [@sd >0][@sd <=6000]{  mark-size: 50m;    font-size: 25;};
     [@sd > 6000] [@sd <= 12000]{    mark-size: 25px;    font-size: 25;};
     [@sd >12000] [@sd <= 24000]{    mark-size: 50px;    font-size: 25;};
     [@sd >24000] [@sd <= 48000]{    mark-size: 750px;    font-size: 25;};

    [Km > 245] [Km <= 295]  { fill: blue;};
    [Km > 295] [Km <= 345]  { fill: pink;};
    [Km > 345] [Km <= 395]  { fill: yellow;};
    [Km > 395]              { fill: orange;};
  }
}

2 Answers 2

5

Staying close to your current attempt, this seems to work:

* {
    label: [No];
    mark: symbol(circle);
   
    [@sd >0][@sd <=6000]{  mark-size: 50m;    font-size: 25;};
    [@sd > 6000] [@sd <= 12000]{    mark-size: 25px;    font-size: 25;};
    [@sd >12000] [@sd <= 24000]{    mark-size: 50px;    font-size: 25;};
    [@sd >24000] [@sd <= 48000]{    mark-size: 750px;    font-size: 25;};

    [Km > 245] [Km <= 295]  { :mark{ fill: blue} };
    [Km > 295] [Km <= 345]  { :mark{ mark-fill: pink }};
    [Km > 345] [Km <= 395]  { :mark{ mark-fill: yellow }};
    [Km > 395]              { :mark{ mark-fill: orange }};
  
}

That is, do not use the :mark pseudo-selector as a container for other rules.

That said, the style still seems a bit too much work... something similar seems simpler and would result in a more progressive display:

* {
    label: [No];
    font-size: 25;

    mark: symbol(circle);
    mark-size: Interpolate(@sd, 6000, 25, 120000, 50, 24000, 750);

    :mark [Km > 245] {
       fill: Categorize(Km, blue, 295, pink, 345, yellow, 395, orange);
    }   

  
}

(it's not clear what output you want for Km <= 245, the style currently produces gray fill below that value since the the mark driver property is still enabled)

2
  • The Km column contains numbers 247 : 423 which I want to use to categorize. Your answer has pointed me in the right direction, the manual/documentation.
    – mapperx
    Commented Mar 21, 2023 at 12:23
  • The interpolate does not accept units so I will modify the answer so that I can use units in the sizes.
    – mapperx
    Commented Mar 21, 2023 at 12:25
0

The answer posted by @Andrea Aime above was helpful and i have accepted it. Made a few modifications to suit my use case. The Interpolate function was not suitable because I wanted to add unit for the sizes. Below is my own working code.

* {
    label: [No];
    mark: symbol(circle);
    :mark  {
       fill: [categorize(Km ,  '#00FF00', 295, '#FFFACD', 345, '#F08080', 395, '#000000')];}
}
 [@sd >0][@sd <=6000]{
    mark-size: 50px;
    font-size: 25px;}
 [@sd > 6000] [@sd <= 12000]{
    mark-size: 25px;
    font-size: 25px;}
 [@sd >12000] [@sd <= 24000]{
    mark-size: 50px;
    font-size: 25px;}
 [@sd >24000] [@sd <= 48000]{
    mark-size: 75px;
    font-size: 25px;}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.