This project has moved and is read-only. For the latest updates, please go here.

CustomTheme doesn't work

Topics: General Topics
Mar 19, 2007 at 8:47 PM

I try to apply the CustomTheme example ( ) but it doesn't work. I get a NullReferenceException.

my code :

SharpMap.Map map = new SharpMap.Map(new Size(800, 800));
SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
layCountries.DataSource = new SharpMap.Data.Providers.ShapeFile("countries.shp", true);

SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle);
layCountries.Theme = myTheme;


map.MaximumZoom = 360;
map.BackColor = Color.LightBlue;
map.Zoom = 360;
map.Center = new SharpMap.Geometries.Point(0, 0);

pictureBox1.Image = map.GetMap();

the exception happens on the last line

Thank you for your help

Mar 20, 2007 at 6:16 AM
Have you included in your code the style delegate private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row) that is presented in that page?

George J.

Mar 20, 2007 at 10:36 AM
Edited Mar 20, 2007 at 12:34 PM
I tried to debug and I noticed I get the exception only when the GetCountryStyle method return null. For example, if I replace

return null


style.Fill = Brushes.Violet;
return style;

I doesn't get the exception.
Mar 20, 2007 at 5:07 PM
Yes, I got the same error.

A temporary work-arround is to return the transparent color when you want no color to be applied. I use this as the default statement:

        style.Fill = new SolidBrush(Color.Transparent);

The bug seems to be in the rendering engine - it does not check if the theme is null, and it tries to render with the color from the null theme. Perhaps it should be documented as bug...

George J.