This project has moved. For the latest updates, please go here.

Example 2: Styling the layer with UniqueValueRenderer

PLEASE NOTE: For this sample to work, you (currently) have to compile the sharpmap solution yourself

In this step we will style the map with different color dependent on attribute value

Update your maploading code and assign a Theme (UniqueValuesTheme)

//Create the layer
SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
//Assign the data source
vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Path_TO_Data\states_ugl.shp", true);

//Create the style for Land
SharpMap.Styles.VectorStyle landStyle = new SharpMap.Styles.VectorStyle();
landStyle.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(232, 232, 232));

//Create the style for Water
SharpMap.Styles.VectorStyle waterStyle = new SharpMap.Styles.VectorStyle();
waterStyle.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(198,198,255));

//Create the theme items
Dictionary<string, SharpMap.Styles.IStyle> styles = new Dictionary<string,SharpMap.Styles.IStyle>();
styles.Add("land", landStyle);
styles.Add("water", waterStyle);

//Assign the theme
vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme<string>("class", styles, landStyle);

//Add layer to map
mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;

You should now have a map that looks something like this


Last edited Jan 8, 2015 at 8:05 AM by FObermaier, version 7