How to migrate v0.9 custom themes to v2.0beta1?

Topics: General Topics, SharpMap v2.0, WinForms Controls
Dec 3, 2007 at 1:47 PM
Hi together,

I need help to migrate the following v0.9 code to actual version. I'm a little stupid to get it worked.
/// <summary>
/// Gets the style for each element in the country layer
/// </summary>
/// <param name="row">Element description</param>
/// <returns></returns>
private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
//private SharpMap.Styles.VectorStyle GetCountryStyle(string name)
{
SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
//string iNameStr = row"NAME".ToString().ToLower();
string iNameStr = row2.ToString().ToLower();
string iGroupStr = row3.ToString().ToLower();
switch (iNameStr)
{
case "denmark": // If county name is Danmark, fill it with green
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Green);
return style;
case "united states": // If county name is USA, fill it with blue and add a red outline
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Blue);
style.Outline = new SharpMap.Styles.StylePen(SharpMap.Styles.StyleColor.Red, 1.0);
return style;
case "china": // If county name is China, fill it with red
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Red);
return style;
default:
break;
}
// if country name starts with 'S' make it yellow
if (row"NAME".ToString().StartsWith("S"))
{
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Yellow);
return style;
}
// If geometry is a (multi)polygon and the area of polygon is less than 30, make it cyan
else if (row.Geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon) &&
(row.Geometry as SharpMap.Geometries.MultiPolygon).Area < 30 ||
row.Geometry.GetType() == typeof(SharpMap.Geometries.Polygon) &&
(row.Geometry as SharpMap.Geometries.Polygon).Area < 30)
{
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Cyan);
return style;
}
else // None of the above -> use the default style
return style;
}

And later somewhere in the code as event handler
/// <summary>
/// Gets the style for each element in the country layer
/// </summary>
/// <param name="row">Element description</param>
/// <returns></returns>
private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
//private SharpMap.Styles.VectorStyle GetCountryStyle(string name)
{
SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
//string iNameStr = row"NAME".ToString().ToLower();
string iNameStr = row2.ToString().ToLower();
string iGroupStr = row3.ToString().ToLower();
switch (iNameStr)
{
case "denmark": // If county name is Danmark, fill it with green
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Green);
return style;
case "united states": // If county name is USA, fill it with blue and add a red outline
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Blue);
style.Outline = new SharpMap.Styles.StylePen(SharpMap.Styles.StyleColor.Red, 1.0);
return style;
case "china": // If county name is China, fill it with red
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Red);
return style;
default:
break;
}
// if country name starts with 'S' make it yellow
if (row"NAME".ToString().StartsWith("S"))
{
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Yellow);
return style;
}
// If geometry is a (multi)polygon and the area of polygon is less than 30, make it cyan
else if (row.Geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon) &&
(row.Geometry as SharpMap.Geometries.MultiPolygon).Area < 30 ||
row.Geometry.GetType() == typeof(SharpMap.Geometries.Polygon) &&
(row.Geometry as SharpMap.Geometries.Polygon).Area < 30)
{
style.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Cyan);
return style;
}
else // None of the above -> use the default style
return style;
}

Before v2.0 it was a delegate, but now Layer has Style property, which can't be used for delegates and accordingly the old v.09 can get worked. Moreover I don't understand, how to provide feature thematics not for layers but for loaded features (which can be added after theme is created and instaleld for the map).

Thanks for a help in advice.