ThinkGeo.com    |     Documentation    |     Premium Support

Changing Style From Default to Custom

How can I cange the styles for a layer dynamically from what was originally set as a Default style to a custom style and back again?


This is for switching thematic reports on and off.


 


 //Initally Set

MapLayer.ZoomLevelSet.CustomZoomLevels[0].DefaultAreaStyle = AreaStyles.Country1;

//Now I want the layer to use custom style

classBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, AreaStyles.Grass1));

classBreakStyle.ClassBreaks.Add(new ClassBreak(00, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[0]))));

classBreakStyle.ClassBreaks.Add(new ClassBreak(10, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[1]))));

classBreakStyle.ClassBreaks.Add(new ClassBreak(20, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[2]))));

classBreakStyle.ClassBreaks.Add(new ClassBreak(30, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[3]))));

classBreakStyle.ClassBreaks.Add(new ClassBreak(40, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[4]))));

classBreakStyle.ClassBreaks.Add(new ClassBreak(50, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[5]))));



MapLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); 



Hi Jeremy,



DefaultStyle and CustomStyles can not apply together, it’s not allowed. You can add them into the custom styles and switch easily by the following code. 



I noticed that you are using CustomZoomLevels[0]; do you have a CustomZoomLevels definition? Is you us both CustomeZoomLevelSet and DefaultZoomLevelSet, map also throws the exception. Please be aware of it.private void SwitchStyles(FeatureLayer layer, bool isDefaultStyleEnabled)
{
    layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();

    if (isDefaultStyleEnabled)
    {
        layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.Country1);
    }
    else
    {
        classBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, AreaStyles.Grass1));
        classBreakStyle.ClassBreaks.Add(new ClassBreak(00, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[0]))));
        classBreakStyle.ClassBreaks.Add(new ClassBreak(10, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[1]))));
        classBreakStyle.ClassBreaks.Add(new ClassBreak(20, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[2]))));
        classBreakStyle.ClassBreaks.Add(new ClassBreak(30, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[3]))));
        classBreakStyle.ClassBreaks.Add(new ClassBreak(40, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[4]))));
        classBreakStyle.ClassBreaks.Add(new ClassBreak(50, new AreaStyle(new GeoPen(GeoColor.FromArgb(255, 0, 50, 0)), new GeoSolidBrush(colorsInFamily[5]))));
        layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle);
    }

    layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
}


If you have any questions please let me know.



Thanks,

Howard



All my levels are custom zoom levels. I just had the default one in there as example code.



Jeremy, 
  
 Could you tell me how is the code above working? 
  
 If you have any questions please let me know. 
  
 Thanks, 
 Howard