Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

Why can't a filter be in a ref layer? #316

Closed
schwanksta opened this issue Jul 17, 2015 · 2 comments
Closed

Why can't a filter be in a ref layer? #316

schwanksta opened this issue Jul 17, 2015 · 2 comments

Comments

@schwanksta
Copy link

Essentially I'd like to set up base style and alter the paint based on a property.

I figured I could set up a layer and use ref to create styles that inherit a base, kinda like Carto, where I can say

marker-allow-overlap: true;
marker-ignore-placement: true;
marker-fill: #000;
[day="MON"] { marker-fill: @mon }
[day="TUE"] { marker-fill: @tue }
...

So I tried this:

{
    "id": "signs",
    "type": "symbol",
    "source": "broom-signs",
    "source-layer": "data",
    "layout": {
      "icon-allow-overlap": true,
      "icon-ignore-placement": true,
      "icon-image": "circle.sdf"
    },
    "paint": {
        "icon-size":0.3,
        "icon-color": "#000"
    }
},
{
    "id": "mon-signs",
    "filter": ["==", "day", "MON"],
    "ref": "signs",
    "paint": {
        "icon-size":0.3,
        "icon-color": "@mon"
    }
}

However, I get "filter" is prohibited for ref layers.

Is there a way of accomplish this without setting up a full layer for each filter? Would filtering in a ref layer be possible?

Right now I'm going with just writing a loop to do it for me:

_.each(['mon', 'tue', 'wed', 'thur', 'fri'], function(day) {
    style.layers.push({
        "id": day + "-signs",
        "type": "symbol",
        "source": "broom-signs",
        "source-layer": "data",
        "filter": ["==", "day", day.toUpperCase()],
        "layout": {
          "icon-allow-overlap": true,
          "icon-ignore-placement": true,
          "icon-image": "circle.sdf"
        },
        "paint": {
            "icon-size":0.3,
            "icon-color": "@" + day
        }
    });
});

Thanks

@peterqliu
Copy link
Contributor

No, a ref layer necessarily inherits the filter of its referent; its purpose is less for ease of authoring, than rendering optimization. If you'd like to have a different marker for each day, you will need a new layer per day with its own filter, and own marker-fill color.

However, in the future, data driven styles may allow you to combine all those into one layer.

@schwanksta
Copy link
Author

That's what I assumed. Appreciate the response. And data-driven styles look great!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants