简体   繁体   中英

how to mapbox-gl expressions unique ID style settings

I have a question about what is wrong with the Mapbox-gl vector tile style configuration.

I want to express 5 colors uniquely for the ID column.

example Data structure

id : 0 => 2 data
id : 1 => 7 data
id : 2 => 10 data
...

The value of this ID is not known. Can I give a unique color by setting a column name?

The results I want to say above are red for ID 0, yellow for ID 1, and blue for ID 3. For example, I don't know if the value of the ID column is an integer or a string. I want to give unique color automatically.

Suppose you have set ID in the data-side as feature's property so the style can get its ID as template string like {ID} .

You can use style expression as below:

somePaintProperty = [
    "case", // similar with switch ~ case
    ["==", ["get", "ID"], 0], // when the value of ID property equals to 0,
    "red", // then, colors red
    ["==", ["get", "ID"], 1],
    "yellow",
    ...
    "black", // else(default), black
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM