0

Currently working on a css style for one of my layers. My plan is to use an env var from the query string to drive some of the styling. I was going to use the env var as a flag string. Basically, if 'A' is in the string, that will trigger labels to show, if 'B' is in the string, icons will show, etc, but I'm running into an issue where it seems like the env var is causing my conditionals to evaluate incorrectly.

My style

/* @title label */
[strIndexOf(@style_flags, 'A') > -1] {
    label:          [strIndexOf(@style_flags, 'A')];
    font-family:    "Trebuchet MS Bold";
    font-fill:      white;
    font-style:     normal;
    font-size:      12; 
    halo-radius:    0.5;
    halo-color:     black;
}

I open the layer in geoserver's OL previewer, and append '&env=style_flags:A' to the end.

enter image description here

But when I change style_flags to 'B', I get this.

enter image description here

If strIndexOf(@style_flags, 'A') evaluates to -1, the rule should evaluate to false, and no label should show, right?

EDIT:

I was appending this '&env=flags:ABC' to the OL URL and using subsets of 'ABC' to test the toggle functionality. I played around with setting defaults on the env var, because it appeared that my flags var string wasn't overriding the default. I used labels to test if my variable was being read in, and it was, but it didn't seem to affect how the rules were evaluated.

my full style:

@mode "Flat";

/* @title 1-1000 */
[strIndexOf(@flags("C"), 'C') <> -1] [speed BETWEEN 1 AND 1000] {
    mark:       url('http://localhost:8080/geoserver/www/styles/images/arrow2.png');
    mark-size:  [speed*0.25];
    mark-rotation: [course];
}

/* @title Over 1000 */
[strIndexOf(@flags("C"), 'C') <> -1] [speed > 1000] {
    mark: url('http://localhost:8080/geoserver/www/styles/images/arrow2.png');
    mark-size:  125;
    mark-rotation: [course];
}

/* @title PLANE BLUE */
[strIndexOf(@flags("B"), 'B') <> -1] [type = 'PLANE'] [color like 'BLUE']{
    mark: url('http://localhost:8080/geoserver/www/styles/images/PLANE_BLUE.png');
}

/* @title PLANE RED */
[strIndexOf(@flags("B"), 'B') <> -1] [type = 'PLANE'] [color = 'RED']{
    mark: url('http://localhost:8080/geoserver/www/styles/images/PLANE_RED.png');
}

/* @title PLANE GREEN */
[strIndexOf(@flags("B"), 'B') <> -1] [type = 'PLANE'] [color = 'GREEN']{
    mark: url('http://localhost:8080/geoserver/www/styles/images/PLANE_GREEN.png');
}

/* @title CAR BLUE */
[strIndexOf(@flags("B"), 'B') <> -1] [type = 'CAR'] [color like 'BLUE']{
    mark: url('http://localhost:8080/geoserver/www/styles/images/CAR_BLUE.png');
}

/* @title CAR RED */
[strIndexOf(@flags("B"), 'B') <> -1] [type = 'CAR'] [color = 'RED']{
    mark: url('http://localhost:8080/geoserver/www/styles/images/CAR_RED.png');
}

/* @title CAR GREEN */
[strIndexOf(@flags("B"), 'B') <> -1] [type = 'CAR'] [color = 'GREEN']{
    mark: url('http://localhost:8080/geoserver/www/styles/images/CAR_GREEN.png');
}

/* @title SHIP BLUE */
[strIndexOf(@flags("B"), 'B') <> -1] [type = 'SHIP'] [color like 'BLUE']{
    mark: url('http://localhost:8080/geoserver/www/styles/images/SHIP_BLUE.png');
}

/* @title SHIP RED */
[strIndexOf(@flags("B"), 'B') <> -1] [type = 'SHIP'] [color = 'RED']{
    mark: url('http://localhost:8080/geoserver/www/styles/images/SHIP_RED.png');
}

/* @title SHIP GREEN */
[strIndexOf(@flags("B"), 'B') <> -1] [type = 'SHIP'] [color = 'GREEN']{
    mark: url('http://localhost:8080/geoserver/www/styles/images/SHIP_GREEN.png');
}


/* @title label */
[strIndexOf(@flags("A"), 'A') <> -1] {
    label:          [name];
    font-family:    "Trebuchet MS Bold";
    font-fill:      white;
    font-style:     normal;
    font-size:      12; 
    halo-radius:    0.5;
    halo-color:     black;
}
  • Is that the whole of your style or are there more rules? – Ian Turton Aug 31 '18 at 4:48
  • @IanTurton The style I was making had about 20 rules, but I was able to trim it down to this and keep the problem replicable. I'll edit the post with my full style. – Evan Aug 31 '18 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.