Skip to content

Optimize style structure config #279

Closed

Description

@mourner

One more idea about optimizing style config in future format revisions. Currently structure config looks like this:

"structure": [
{
    "name": "background",
    "bucket": "background"
},
{
    "name": "satellite",
    "bucket": "satellite"
},
{
    "name": "park",
    "bucket": "park"
},
{
    "name": "wood",
    "bucket": "wood",
},
{
    "name": "water",
    "bucket": "water",
},
{
    "name": "waterway",
    "bucket": "waterway",
},
{
    "name": "roads",
    "layers": [
    {
        "name": "tunnel_large_casing",
        "bucket": "tunnel_large",
    },
    {
        "name": "tunnel_regular_casing",
        "bucket": "tunnel_regular",
    },
    {
        "name": "tunnel_large",
        "bucket": "tunnel_large",
    },
    ...

What's the goal of structure config? Set rendering order for buckets, rendering some of the buckets several times (e.g. road casings and roads). Considering this, we can simplify the config dramatically by making it an array of bucket names with occasional custom postfixes thrown in for referencing by class styles. The same sample:

"structure": [
    "background",
    "satellite",
    "park",
    "wood",
    "water",
    "waterway",
    {"roads": [
        "tunnel_large:casing",
        "tunnel_regular:casing",
        "tunnel_large",

This change will make fiddling with z-oder and adding new layers a lot easier. If we introduce bucket groups as discussed in #276, we can ditch groups in structure config and leave it to bucket config.

Activity

  1. kkaefer commented on Feb 10, 2014

    @kkaefer
    Member

    The purpose of structure is to define the order the buckets are drawn in, and the class applied to a bucket. E.g. you can use the same bucket multiple times (as with the road layers) and draw the same data with multiple different styles. name actually refers to the class name. Separating them with : is possible, but then we'd have to spell out the class name, rather than just using the suffix. Otherwise we're going to introduce too much magic behavior.

    Going to a flat array probably won't happen. The bucket groups you propose are conceptually different from what the groups in the structure array do: In here, we are grouping multiple buckets to be rendered to a framebuffer before they are globally composited onto the main canvas. During compositing, you can then specify texture effects (like blur, colorization, opacity, etc.).

  2. mourner commented on Feb 10, 2014

    @mourner
    MemberAuthor

    @kkaefer yeah, we would refer to them the same way when styling (e.g. "tunnel_large:casing": { ... }), no magic. The purpose is just to remove unnecessary repetition in the structure config, as structure class names refer to bucket names 100% of the time.

    Didn't know about compositing, I see that in the code now — makes sense.

  3. kkaefer commented on Feb 10, 2014

    @kkaefer
    Member

    as structure class names refer to bucket names 100% of the time

    No, they don't. In the sample stylesheet, you can see that a structure element refers to a bucket object and a class name, but there is no 1:1 matching between buckets and class names.

  4. mourner commented on Feb 10, 2014

    @mourner
    MemberAuthor

    @kkaefer they do with the exception of _casing classes, which why I suggested introducing postfixes like :casing. In terms of referring from styles, there's no difference between tunnel_large_casing and tunnel_large:casing (they're just strings), but with the latter, we can imply tunnel_large bucket instead of having such a verbose config. That's what I meant in the initial post.

  5. kkaefer commented on Feb 10, 2014

    @kkaefer
    Member

    Sure, that works in /this/ case, but you can't make a general rule from this special case from the fact that they only differ by _casing in our stylesheet; that is just coincidence.

  6. mourner commented on Feb 10, 2014

    @mourner
    MemberAuthor

    @kkaefer as far as I understand, what class names we choose is just a convention. Each class still has exactly one associated bucket. So whether we reflect that in class name and let developers differentiate with postfixes when needed (and imply when not), or leave as is, is a matter of convention. I'm just following Convention over configuration principle here. Details like this may look insignificant, but they're important if we're planning on winning over a lot of developers, judging from my experience building Leaflet community.

    Convention over configuration (also known as coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing flexibility.
    The phrase essentially means a developer only needs to specify unconventional aspects of the application. For example, if there's a class Sale in the model, the corresponding table in the database is called “sales” by default. It is only if one deviates from this convention, such as calling the table “products_sold”, that one needs to write code regarding these names.
    When the convention implemented by the tool matches the desired behavior, it behaves as expected without having to write configuration files. Only when the desired behavior deviates from the implemented convention is explicit configuration required.

  7. nickidlugash commented on Feb 25, 2014

    @nickidlugash

    Is this being actively worked on? I don't really know what I'm doing so I'm probably misusing the config all over the place, but here's a note on how I've been using it that seems different from what's being described above:

    I rearranged the auto styling so that most of the road style classes (name) have three buckets associated with each of them. E.g, the street class has the buckets bridge_street, road_street, and tunnel_street associate with it. These need to be separate buckets because of their drawing order, but they are styled exactly the same.

  8. mourner commented on Mar 28, 2014

    @mourner
    MemberAuthor

    Closing in favor of #356

  9. added a commit that references this issue on Oct 24, 2016
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