Mapbox-gl-js: how can i use fill-color,fill-pattern expressions at the same time ?

Created on 19 Jul 2019  路  3Comments  路  Source: mapbox/mapbox-gl-js

I want to set some features to use fill-color by expression, and some features use fill-pattern

the fill layer, when I use expressions to determine the style of the face, fill-color, fill-pattern will be abnormal, like this:

map.setPaintProperty("layerId","fill-pattern",
["case",["==",1,["get","num"]],"imageId", ["literal",null] ]
);
map.setPaintProperty("layerId","fill-color",
["case",["==",2,["get","num"]], "red" , "black" ]
)

browser will throw errors: Expected string but found null instead;

Most helpful comment

So I'm having the same issue -- I see the documentation says that fill-pattern will remove fill-color but I wish we could either set fill-pattern to null, and have the color come through, or set both (e.g. a transparent pattern on top of a fill)

Also @cdhuangyong I'd love to know what exactly you did!

All 3 comments

I solved it! If fill-pattern uses an expression, when the value of the expression is null, I create my own canvas to draw a solid-color picture instead.

Glad you figured out a solution @cdhuangyong

So I'm having the same issue -- I see the documentation says that fill-pattern will remove fill-color but I wish we could either set fill-pattern to null, and have the color come through, or set both (e.g. a transparent pattern on top of a fill)

Also @cdhuangyong I'd love to know what exactly you did!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iamdenny picture iamdenny  路  3Comments

aendrew picture aendrew  路  3Comments

PBrockmann picture PBrockmann  路  3Comments

muesliq picture muesliq  路  3Comments

stevage picture stevage  路  3Comments