Skip to content

Styling multiple related layers using variables #19

@pnorman

Description

@pnorman

I have a large number of layers which mix very similar properties in different ways. e.g.

layer(:road_base_casing, :source=>:spirit, :source_layer=>:roads) {
    filter foo
    line_width A
    line_color M
    line_cap round
}

layer(:road_tunnel_casing, :source=>:spirit, :source_layer=>:roads) {
    filter foo & X
    line_width A
    line_color N
}

layer(:road_base_fill, :source=>:spirit, :source_layer=>:roads) {
    filter foo
    line_width B
    line_color N
}

layer(:road_casing, :source=>:spirit, :source_layer=>:roads) {
    filter foo & !X & !Y
    line_width A
    line_color M
}

In reality, all those variables are fairly complicated expressions using interpolates, matches, etc

I don't want to attempt something this complex with cascading but instead want to use variables. I have an example of how to use variables for numbers, colors, and other simple values.

I don't know how to assign part of an expression or conditional to a variable to reuse it in multiple definitions. I tried

ROAD_FILTER = (highway.in('motorway', 'trunk', 'primary', 'secondary', 'tertiary',
    'unclassified', 'residential', 'living_street') |
    ((highway == 'service') & (((minor == nil) & (zoom() >= 14)) | (zoom() >= 15))))

but it doesn't know what to do with the highway.in and gives

(eval):1:in `block in <top (required)>': undefined method `in' for nil:NilClass (NoMethodError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions