CanvasMap
Getting Started Tutorials 3D Reference

Giving Each Feature a Unique Style

The geographic map of Africa example example shows how to change the style for each feature in a layer. This done by simply creating a unique color for each feature. You can use RGB colors for this but cartographers tend to give each feature a different "hue" instead. The code below uses the CSS HSL function to create unique styles for each feature. Try changing the Saturation and Lightness which go from 0 to 100% to see different color effects.

	// add a unique color to each country in Africa
var Saturation=50.0; // change these values between 0 and 100 to change the intensity of the colors
var Lightness=80.0;
for (var i=0;i<60;i++)
{
var Hue=Math.random()*360; // creates a random hue for each country

AfricanCountryLayer.SetFeatureSetting("Style","fillStyle",i,"hsl("+Hue+","+Saturation+"%,"+Lightness+"%)");
}