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

Using Rendering with CustomTheme

Topics: SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0
Dec 5, 2008 at 11:28 AM

Hi I’m implementing application that uses a custom thematic rendering based on the vector layer Theme, I find a way to hold the vector layer style through the GetStyleMethod , some thing like this




VectorLayer vectorLayer = new VectorLayer(“Shape_Nb_1”);

vectorLayer.DataSource = new ShapeFile(fileName, true);


CustomTheme myTheme = new CustomTheme(GetAreasStyle);

vectorLayer.Theme = myTheme;



private VectorStyle GetAreasStyle(SharpMap.Data.FeatureDataRow row)


VectorStyle style = new VectorStyle();

      style.Fill = Brushes.IndianRed;

return style ;



Until know it’s ok, but I need to know the vector layer name in side the GetAreasStyle method, ( in this case it’s (“Shape_Nb_1”).

how can I retrieve this information inside the GetAreasStyle method


thx for all kind of suggestion

Dec 5, 2008 at 1:09 PM
Hi case_tunisia, you may be able to do it with anonymous delegates  - these have the avantage that variables accessible in the method in which the anonymous delegate is defined are available within the delegate.

I dont have time this second to write a demo but maybe this will help (untried untested)

In your layerBuilding method..

CustomTheme myTheme = new CustomTheme(BuildMyStyle(vectorLayer.LayerName)); //buildMyStyle returns another method

//method which returns another method
GetStyleMethod BuildMyStyle(string layerName)
    return (GetStyleMethod ) delegate(FeatureDataRow fdr){ return CustomStyleBuilder(fdr, layerName);}

//method which returns a style but also takes layername as a property
VectorStyle CustomStyleBuilder(FeatureDataRow fdr, string layerName)
// do your thing
Dec 5, 2008 at 1:56 PM

Hi Johndiss, thank very much, it works very fine,

Here the fine code :

VectorLayer vectorLayer = new VectorLayer(ShapeName);

vectorLayer.DataSource = new ShapeFile(fileName, true);


CustomTheme myTheme = CustomTheme(BuildMyStyle(vectorLayer.LayerName));

vectorLayer.Theme = myTheme;




CustomTheme.GetStyleMethod BuildMyStyle(string layerName)


return (CustomTheme.GetStyleMethod) delegate(FeatureDataRow fdr) { return CustomStyleBuilder(fdr, layerName); };



VectorStyle CustomStyleBuilder(FeatureDataRow row, string layerName)


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



 // trt of the layer theme configuration based on layer name


return styles