Apply text, graphic to center point (vector layer) without replacing the polygon

Topics: SharpMap Project, SharpMap v0.9 / v1.x, Web Controls
Mar 21, 2008 at 7:24 AM
Edited Mar 21, 2008 at 7:32 AM
Hi,
After gone thru all the demo files, I wonder is there anyway to apply text, graphics (as in PieCharts.aspx sample) to the center point without replacing the polygon itself since the polygon already have style applied to it such as fill color, the outline and such?

I tried to apply Bins and piecharts style methods in 1 page.

private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
{

SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();

switch (row"NAME".ToString().ToLower())
{
case "denmark": //If country name is Danmark, fill it with green
style.Fill = new SolidBrush(Color.Red);
style.Symbol = GetPieChart(row);
return style;
case "united states": //If country name is USA, fill it with Blue and add a red outline
style.Fill = new SolidBrush(Color.Blue);
style.Outline = Pens.Red;
style.Symbol = GetPieChart(row);
return style;
case "china": //If country name is China, fill it with red
style.Fill = new SolidBrush(Color.Green);
style.Symbol = GetPieChart(row);
return style;
case "timor-leste":
style.Fill = new SolidBrush(Color.Purple);
style.Outline = Pens.Black;
style.Symbol = GetPieChart(row);
return style;
default:
break;
}
return style;

}

private static Bitmap GetPieChart(SharpMap.Data.FeatureDataRow row)
{
SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();

// Replace polygon with a center point (this is where we place the symbol
row.Geometry = row.Geometry.GetBoundingBox().GetCentroid();

// Just for the example I use random values
int size = 16;
System.Drawing.Bitmap b = new Bitmap(size, size);
Graphics g = Graphics.FromImage(b);

// Draw String
g.DrawString("X", new Font(FontFamily.GenericSansSerif, 7), Brushes.DeepPink, new System.Drawing.Point(0, 0));

return b;
}

Please advice.

Thank you.
Developer
Mar 21, 2008 at 9:19 AM
Edited Mar 21, 2008 at 10:07 AM
How about one layer for the polygons and a label layer (with the same datasource) on top of it?

Paul.
Mar 21, 2008 at 9:43 AM
Yes.. it works..

Thank you.