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.
||number||The 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.|
||number||The red value of the color. The range of valid values is 0 to 255.|
||number||The green value of the color. The range of valid values is 0 to 255.|
||number||The blue value of the color. The range of valid values is 0 to 255.|
The Color class has the following methods available.
||Color||Returns a copy of the Color object.|
||number||Returns the opacity of the Color as a value between 0 (a=0) and 1 (a=255).|
||string||Converts 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.|
||string||Converts the Color into a RGBA color string. For example: rgba(0, 255, 0, 0.5)|
The Color class has the following static methods available.
||Color||Creates a copy of the Color object.|
||Color||Converts 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');