Hello all,
my goal is to colorize certain Features of a polygon shape-file.
The "feature" class does not have backgroundcolor or something like this.
So my question is:
How can I colorize certain features of a shape file?
Daniel
Change Color of certain Features
Hi Daniel,
If you just want to colorize the filtered features, I guess the below styles should be fit for you:
ValueStyle : This class allows you to match a value with data in the feature to determine how to draw that feature. Here is an online sample:
wiki.thinkgeo.com/wiki/Map_S…_Countries
ClassBreakStyle : This class represents a style based on class break values(A range of values). wiki API
RegExStyle : This class allows you to draw features differently based on regular expression matching. wiki API
The above style will filter the feature based on its column value with a rule you specified.
Please let me know if you have any questions on how to use it.
Thanks,
Troy
Hello Troy,
Thank you for your answer.
I need something like this:
1.
Collection<feature> features =
new
Collection<feature>();
2.
3.
features = layer.QueryTools.GetFeaturesByColumnValue(
"TestColumn"
,
"42"
);
4.
5.
foreach
(var feature
in
features )
6.
{
7.
feature.BackgroundColor = GeoColor.StandardColors.Yellow;
8.
}
If this is not possible can you give me a code example how I can colorize certain features based on a specific column and value?
Edit: After some further testing with your valueStyle I came to another Problem that I can not use my DefaultStyle and the customStyle with the valueStyle.
layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle =
null
;
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle =
null
;
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle =
null
;
layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle =
null
;
ValueStyle valueStyle =
new
ValueStyle(column,
new
Collection<valueitem>() {
new
ValueItem(
"42"
,
AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Yellow, GeoColor.StandardColors.Black)) });
layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
Now my Feature has the right Color but the rest of my shape-file has dissappeared. How can I display my colored Feature AND the rest of the shape-file with the Color/styles it has before?
Edit2: Again more testing and now it seems to work properly. I just add my old AreaStyle to the CustomStyles. New functional code:
var areaStyle = layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.CloneDeep();
layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle =
null
;
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle =
null
;
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle =
null
;
layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle =
null
;
ValueStyle valueStyle =
new
ValueStyle(column,
new
Collection<valueitem>() {
new
ValueItem(
"42"
, AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Yellow, GeoColor.StandardColors.Black)) });
layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(areaStyle);
layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
Thank you for giving me the advice with the ValueStyle.
Daniel
Hello Daniel,
So good to hear you figure it out step by step and you are definitely on a correct way. :)
More queries don’t hesitate to let us know.
Thanks,
Troy