Color
colorMethod used to set the color of the graphic.
IColor: string
colortype string.
- The color type can be written in rgb
rgb(200, 100, 100)、rgba(255, 0, 0, 1) - The color type can be written in hexadecimal
#ffffff、#000 - The color type can be the writing method of color name
red、yellow
color(color: IColor)
Layers can set color values directly.
layer.color('#f00');
color(field: string)
The colors of a layer can be mapped based on the data values accepted by the layer, accepting fields of incoming data as parameters.
layer.source([
{
lng: 120,
lat: 30,
c: '#f00',
},
]);
layer.color('c');
color(field: string, domain: IColor[])
colorMethod supports simple value mapping and will be based onfieldThe values extracted from the data passed into the layer are mapped todomainin the value range.
layer.color('type', ['#f00', '#0f0', '#00f']);
color(field: string, callback: () => IColor )
colorThe method supports the writing method of callback function, which will be based onfieldascallbackmethod parameters,callbackThe return value of the method is the actual color of the layer.
layer.color('type', (value) => {
switch (value) {
case 'water':
return '#f00';
case 'wood':
return '#0f0';
}
});