Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fill color for vector tiles based on a property #98

Open
Jeffrey-Truong opened this issue Jul 27, 2022 · 1 comment
Open

How to fill color for vector tiles based on a property #98

Jeffrey-Truong opened this issue Jul 27, 2022 · 1 comment

Comments

@Jeffrey-Truong
Copy link

Hi I've been looking through the documentation and examples for filling Mapbox vector tiles.

I've noted in the example fill-layer-melbourne.R uses the "get" function to fill in the boundaries:

paint = list(
"fill-color" = c("get", "fillColor"),
"fill-opacity" = 0.7
)

This works well for imported shapefiles but I'm not able to find the correct syntax when I want to use my custom vector tiles in Mapbox. I've tested your example vector-layer-filled-polygons.R for one color with my custom vector tiles in Mapbox and works great but would like to extend that to have different colors for each polygon. This is my understanding of what the code would look like in Mapbox GL JS:

'paint': {
'fill-color': ['match', ['get', 'LHD_Name'],
'Sydney', 'red',
'South Western Sydney', 'blue',
'white']
}

What is the correct syntax for mapboxer to implement this type of visualisation?

Cheers

@Jeffrey-Truong
Copy link
Author

Jeffrey-Truong commented Jul 27, 2022

An update to say I found one way of doing it after looking at the documentation further regarding expressions. This works for me:

"paint" = list(
"fill-color" = list(
"case",
list("==", c("get", "LHN_Name"), "Sydney"), "red", # 'red' if 'LHD_Name == "Sydney"'
list("==", c("get", "LHN_Name"), "Western Sydney"), "blue", # 'blue' if 'LHD_Name == "Western Sydney"'
"yellow" # Defaults to 'yellow'
)

I haven't worked out how to use the match function/expression yet but this will suffice for now.

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

No branches or pull requests

1 participant