ITheme::GetStyle, need a new parameter, "Layer"

Topics: General Topics
Aug 18, 2006 at 10:48 PM

I looked into the code, and it could be easily added.

IStyle GetStyle(VectorLayer layer, FeatureDataRow attribute);

Because i need to know in which layer the theme is going to be applied. I know that i could assign differents GetStyle function to each of my layer, but here is my problem:

I offer to my user a way to customize their own layer. So i have a generic way to apply a style to a layer, wich depends of what the user has decided. So only one GetStyle, for all my layer.

I can't do it right now, because it's impossible to know on what layer this is requested for.

Maybe i miss something and i can do it without adding this parameters, if that's the case, thanks in letting me know how too ;)

Otherwise, it is a nice feature to add.

Thanks again, and keep up the good work. You release new source code frequently, and that is much appreciated!
Jun 9, 2007 at 10:02 AM
Did you find any work around for this?
Jun 30, 2007 at 10:45 AM
Can the Moderators make this as a WorkItem?
Jul 1, 2007 at 9:12 PM
There is no need. You can accomplish this by using anonymous methods.
Jul 2, 2007 at 11:01 AM
I tried to set the FeatureDataTable to the required layer but could not find a way!

How can you accomplish this by anonymous methods?
Jul 4, 2007 at 1:24 PM
For simple and non-reusable styles, use anonymous methods in this way:
VectorLayer mylayer = new VectorLayer("mylayer");
mylayer.Theme = new CustomTheme(delegate(FeatureDataRow dr) {
    IStyle style = new VectorStyle();
    // You can use "mylayer" and other variables in the outer scope here...
    return style;

For complex styles or for better reusability, I suggest you declare a class to contain additional options for your theme:
public class MyTheme
    private Layer _layer;
    public MyTheme(Layer layer)
        _layer = layer;
        // You could add more private fields 
        // and arguments to the constructor,
        // such as a Map object, default colors, etc.
    public IStyle GetStyle(FeatureDataRow dr)
        IStyle style = new VectorStyle();
        // Create the style using the private fields (in your case, _layer)
        return style;
Then use a GetStyleMethod delegate bounded to an instance of MyTheme.
VectorLayer mylayer = new VectorLayer("mylayer");
mylayer.Theme = new CustomTheme((new MyTheme(mylayer)).GetStyle);

Best regards,
Ricardo Stuven.
Jul 6, 2007 at 9:20 AM
Thats an excellent example. Thanks.