Label Layer

Sep 23, 2011 at 11:03 AM

I'm creating a label layer but it doesn't give output. It gives an error as no layer to render and highlights to PictureBox1.Image=_sharpMap.GetMap(); statement .Please suggest whats wrong in it .The code is below:-

SharpMap.Layers.VectorLayer _statelayer = new SharpMap.Layers.VectorLayer(_datanamestate);

 

 

_statelayer.DataSource =new SharpMap.Data.Providers.ShapeFile(_datapathstate);

 

 

_statelayer.Style.Fill =Brushes.LightCyan;

 

 

_statelayer.Style.EnableOutline =

true ;

_statelayer.Style.Outline =

Pens .DodgerBlue;

_sharpMap.Layers.Add(_statelayer);

 

SharpMap.Layers.

LabelLayer _labellayer = new SharpMap.Layers.LabelLayer("StateName");

_labellayer.DataSource = _statelayer.DataSource;_labellayer.LabelColumn =

"NAME" ;

_labellayer.Style.CollisionDetection =

true ;

_labellayer.Style.CollisionBuffer =

new SizeF (10, 10);

_labellayer.MultipartGeometryBehaviour = SharpMap.Layers.

LabelLayer.MultipartGeometryBehaviourEnum .Largest;

_labellayer.Style.Font =

new Font(FontFamily .GenericSansSerif, 8);

_sharpMap.Layers.Add(_labellayer);

 

 

_sharpMap.ZoomToExtents();

RefreshMap();

 

 

// MessageBox.Show(_sharpMap.Zoom.ToString());

 

}

 

 

private void RefreshMap()

{

_sharpMap =

new SharpMap.Map ();

pictureBox1.Visible =

true ;

pictureBox1.Image = _sharpMap.GetMap();

}