Color Class

Bing
 

Creating an instance of the Color class can be done in one of two ways. The first is to specify values for all the properties in the constructor. The second is to use the static method fromHex which parses a string Hex color value into a Bing Maps Color. The following code shows how these two methods can be used to create a Location objects.

Note: In addition to using the Color class to specify the color of a shape in Bing Maps, CSS3 color strings can also be used.

Color(a: number, r:number, g:number, b:number)

The Color class has four properties; a (alpha), r (red), g (green), b (blue) and are defined as follows.

NameTypeDescription
anumberThe opacity of the color. The range of valid values is a decimal value between 0 and 1. If a value between 1 and 255 is specified, as was done in Bing Maps V7, it will be divided by 255.
rnumberThe red value of the color. The range of valid values is 0 to 255.
gnumberThe green value of the color. The range of valid values is 0 to 255.
bnumberThe blue value of the color. The range of valid values is 0 to 255.

The Color class has the following methods available.

NameReturn TypeDescription
clone()ColorReturns a copy of the Color object.
getOpacity()numberReturns the opacity of the Color as a value between 0 (a=0) and 1 (a=255).
toHex()stringConverts the Color into a 6-digit hex string. Opacity is ignored. For example, a Color with values (255,0,0,0) is returned as hex string #000000.
toRgba()stringConverts the Color into a RGBA color string. For example: rgba(0, 255, 0, 0.5)

The Color class has the following static methods available.

NameReturn TypeDescription
clone(color: Color)ColorCreates a copy of the Color object.
fromHex(hex:string)ColorConverts the specified hex string to a Color.
var color = new Microsoft.Maps.Color(150, 0, 255, 0);

//From a string Hex color
var color = Microsoft.Maps.Color.fromHex('#00FF00');

Show: