Skip to content

Improve bucket configuration in style #276

Closed

Description

@mourner

Currently, bucket config looks like this:

"buckets": {
    "park": {
        "datasource": "mapbox streets",
        "layer": "landuse", "field": "class", "value": "park",
        "type": "fill"
    },
    "wood": {
        "datasource": "mapbox streets",
        "layer": "landuse", "field": "class", "value": "wood",
        "type": "fill"
    },
    "school": {
        "datasource": "mapbox streets",
        "layer": "landuse", "field": "class", "value": "school",
        "type": "fill"
    },
    "tunnel_large": {
        "datasource": "mapbox streets",
        "layer": "tunnel", "field": "class", "value": ["motorway", "main"],
        "type": "line"
    },
    "tunnel_regular": {
        "datasource": "mapbox streets",
        "layer": "tunnel", "field": "class", "value": ["street", "street_limited"],
        "type": "line"
    },
    "tunnel_rail": {
        "datasource": "mapbox streets",
        "layer": "tunnel", "field": "class", "value": ["minor_rail", "major_rail"],
        "type": "line"
    },
    "embassy_poi": {
        "datasource": "mapbox streets",
        "layer": "poi_label", "field": "maki", "value": "embassy",
        "type": "point"
    },
    "park_poi": {
        "datasource": "mapbox streets",
        "layer": "poi_label", "field": "maki", "value": "park",
        "type": "point"
    },
    "restaurant_poi": {
        "datasource": "mapbox streets",
        "layer": "poi_label", "field": "maki", "value": "restaurant",
        "type": "point"
    },
    "country_label": {
        "datasource": "mapbox streets",
        "layer": "country_label",
        "feature_type": "point",
        "type": "text",
        "text_field": "name",
        "path": "horizontal",
        "font": "Open Sans, Jomolhari, Siyam Rupali, Alef, Arial Unicode MS",
        "fontSize": 16
    },
    "place_label": {
        "datasource": "mapbox streets",
        "layer": "place_label",
        "feature_type": "point",
        "type": "text",
        "text_field": "name",
        "path": "horizontal",
        "font": "Open Sans, Jomolhari, Siyam Rupali, Alef, Arial Unicode MS",
        "fontSize": 18
    },
    "road_label": {
        "datasource": "mapbox streets",
        "layer": "road_label",
        "feature_type": "line",
        "type": "text",
        "text_field": "name",
        "path": "curve",
        "font": "Open Sans, Jomolhari, Siyam Rupali, Alef, Arial Unicode MS",
        "fontSize": 12
    }
}

Notice patterns here? There's A LOT of repetition. This clutter makes reading/editing styles hard for designers, and makes doing style manipulation in code harder too. The size also plays a role. As we scale the styles (e.g. add more pois, features, etc.), the problem will be more and more prominent.

Here's my proposal that makes the config much more readable and simple while defining the same buckets:

"datasources": {
    "mapbox streets": {
        "landuse" {
            "defaults": {
                "layer": "landuse",
                "type": "fill",
                "field": "class"
            },
            "park":   {"value": "park"},
            "wood":   {"value": "wood"},
            "school": {"value": "school"}
        },
        "poi": {
            "defaults": {
                "layer": "poi_label",
                "type": "point",
                "field": "maki"
            },
            "embassy":    {"value": "embassy"},
            "park":       {"value": "park"},
            "restaurant": {"value": "restaurant"}
        },
        "label": {
            "defaults": {
                "type": "text",
                "text_field": "name",
                "feature_type": "point",
                "path": "horizontal",
                "font": "Open Sans, Jomolhari, Siyam Rupali, Alef, Arial Unicode MS"
            },
            "country": {
                "layer": "country_label",
                "fontSize": 16
            },
            "place": {
                "layer": "place_label",
                "fontSize": 18
            },
            "road": {
                "layer": "road_label",
                "feature_type": "line",
                "path": "curve",
                "fontSize": 12
            }
        }
    }
}

It introduces bucket groups — which may be referenced later to shave off even more repetition (e.g. referencing all poi layers in structure instead of listing every single one, as they'll probably have the same z-order). As buckets can be namespaced, we can simplify bucket names and reference them like this "poi.embassy" instead of adding prefixes.

When we have #275 and style versioning, it will be easy to migrate existing styles.

@ansis @edenh @kkaefer what do you think?

Activity

  1. kkaefer commented on Feb 7, 2014

    @kkaefer
    Member

    While I agree that our bucket configuration is very verbose right now, it's the price we pay for having fewer concepts (we already have way too many concepts in there). Right now, I'd like to not change the styling definition and go with what we have. While your suggestions cuts down the stylesheet code size, it adds more complexity while not giving style creators more flexibility.

    Instead, we should work on a bigger styling revision: Right now, we can only pull features from vector tile layer into a bucket. The vector tile layers are an artificial construct from Mapnik's view at datasources. However, it might make more sense to think of layers as "tags" and instead allow the style creator to specify a bucket that contains geometries from multiple vector tile layers, e.g. roads from the road layer and tunnels from the tunnel layer (which are roads too, just a different kind of roads, hinting that the separating by layers may not the most ideal one).

    Additionally, I've experimented with adding more feature filtering capabilities (Mapnik-style), so that you can write "filters" that select features by value, value ranges (think numbers), regex comparisons etc.. Basically, this would replicate something akin to what we expose in CartoCSS as [] filters.

    TL;DR: We should change the stylesheet, but if we break the format, we should do so radically and include the other features and conceptual changes we want.

  2. mourner commented on Feb 7, 2014

    @mourner
    MemberAuthor

    Agree with your points — lets do radical changes in one batch. Maintaining a separate style spec and versioning it will help with this (#275).

  3. edenh commented on Feb 7, 2014

    @edenh
    Contributor

    👍 👍 👍 to any improvements here. Filters sound very powerful.

  4. nickidlugash commented on Feb 25, 2014

    @nickidlugash

    This would be great. It's getting very unmanageable to create so many individual buckets as I'm trying to add subtlety to the auto styling. E.g. Would like to style cities labels by scalerank, other place labels by place type, road labels by road type, etc, but that would mean about x5 more buckets for each data layer. And tons of repetitive styling, since in most cases, I just want to change the values of one or two properties across the different types.

  5. ansis commented on Feb 25, 2014

    @ansis
    Contributor

    I think its worth thinking about writing a pre-processor to convert from a human friendly style into a renderer friendly representation.

    People need a higher level of abstraction for the problems mentioned above. But like @kkaefer said, we should avoid adding more concepts to the renderer itself. The renderer doesn't even have a concept of patterned outlines, which are achieved with two separate layers. The renderer shouldn't have a concept of halos. For the renderer, halos should probably be just two text layers with different faked weights.

    The goal is to eventually style these maps with a graphical application, but I don't think work on a pre-processor would be wasted. The work would be about figuring out what abstractions make sense for people. These abstractions would probably be the same ones represented graphically in the editor.

    We will end up adding higher level abstractions somewhere and it would be better to have them as a distinct json-->json step, even if it is bundled with the renderer.

  6. mourner commented on Feb 25, 2014

    @mourner
    MemberAuthor

    @ansis I didn't suggest adding any new renderer concepts. The proposed syntax translates directly into the current format. It doesn't really matter whether we call it a preprocessing step or process it directly when styling. And looks pretty easy to implement, so I think it's definitely worth it.

  7. ansis commented on Feb 25, 2014

    @ansis
    Contributor

    @mourner I didn't mean to imply that you were suggesting new renderer concepts

    What I was trying to say was that we should do this as a separate step, and that this step could maybe abstract things even further. I guess I could have said that way more succinctly :P

  8. mourner commented on Mar 28, 2014

    @mourner
    MemberAuthor

    Closing in favor of #356

  9. added a commit that references this issue on Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions