This project has moved. For the latest updates, please go here.

Label Layer Style

Topics: SharpMap v0.9 / v1.x
Oct 25, 2011 at 9:50 PM

Hi, is it possible to assign diferent label style to label layer depending on map's zoom level?

I have my label layer style set like this:

	   LabelUV.DataSource = layerUV.DataSource;
            LabelUV.Enabled = true;
            LabelUV.LabelColumn = "NRO_UV";
            LabelUV.Style = new LabelStyle();
            LabelUV.Style.ForeColor = Color.DimGray;
            LabelUV.Style.Font = new Font(FontFamily.GenericSerif, 16, FontStyle.Bold);
            LabelUV.MaxVisible = _zLevel2 + _limite;
            LabelUV.MinVisible = _zLevel4 - _limite;
            LabelUV.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
            LabelUV.Style.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Middle;
            LabelUV.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.CommonCenter;
            LabelUV.SRID = _srid;
I want to set label font size bigger when zooming in and smaller when zooming out.
Oct 26, 2011 at 3:37 AM
Edited Oct 26, 2011 at 3:58 AM

Hi carjona,

Sharpmap not seem to support that .

Maybe you have to create a CustomLabelTheme and add some code to labellayer to render CustomLabelTheme

Like CustomTheme add delegate methods like:

public SharpMap.Styles.IStyle GetStyle(SharpMap.Map map) 
	SharpMap.Styles.IStyle style = _getStyleDelegate(map); 
	if (style != null
	return style; 
	else return _DefaultStyle; 


Oct 26, 2011 at 8:34 AM

I think trieuvy is right.

I thought of adding some MinFontSize and MaxFontSize property to LabelStyle, but since you need to get the attribute data anyhow a CustomTheme does not impose to much overhead I suppose.

What you need to do, is setup assign the Map to your CustomTheme, the GetStyle(FeatureDataRow row) you compare modify the style according to the Zoom factor

Maybe the ITheme interface would need a OnRendering(Map map) and maybe a OnRendered(Map map) function to avoid setting up a customtheme with the underlying map (which can be hard do serialize)

Hth FObermaier