CustomTheme doesn't work

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

I try to apply the CustomTheme example ( http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=CustomTheme&referringTitle=Styling%20based%20on%20feature%20data ) 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.Layers.Add(layCountries);

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

Julien
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
Yes.
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

by

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:

    default:
        style.Fill = new SolidBrush(Color.Transparent);
        break;
 

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...


HTH,
George J.