This project has moved and is read-only. For the latest updates, please go here.

LabelLayer with own Datasouce

Topics: SharpMap v0.9 / v1.x, WinForms Controls
May 30, 2016 at 11:17 AM
Hello guys,

I habe a problem to create a LabelLayer with an own DataSource. All LaybelLayer examples I could find here or on google are demonstrated with an .sh File loaded as a Datasource. Like this one:
SharpMap.Data.Providers.ShapeFile(Server.MapPath(@"~\App_data\countries.shp"), true);
On my project, we are getting our data from an KML file. So far everything is working (Points/Linestrings, Styling, ...) but I cant figure out how the LabelLayer is working.

My code looks like:
//create feature datatable with labelname, angle and position
FeatureDataTable fdt = new FeatureDataTable();
            fdt.Columns.Add(new DataColumn("Name"));
            fdt.Columns.Add(new DataColumn("Angle"));
            fdt.Columns.Add(new DataColumn("PosX"));
            fdt.Columns.Add(new DataColumn("PosY"));

//load KML file and create for every entry a row in the featuredatatable
FeatureDataRow fdr = fdt.NewRow();
                    fdr.ItemArray = new object[] { name, angle, p.Coordinate.Longitude, p.Coordinate.Latitude };

After creating the datatable I create the LabeLayer like this:
SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer(layername);
            layLabel.DataSource = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);
            layLabel.Enabled = true;
            layLabel.LabelColumn = "Name";
            layLabel.RotationColumn = "Angle";
            layLabel.LabelPositionDelegate = delegate (SharpMap.Data.FeatureDataRow fdr)
                    { return new GeoAPI.Geometries.Coordinate(Convert.ToDouble(fdr["PosX"]), Convert.ToDouble(fdr["PosY"]));};
            layLabel.Style = new SharpMap.Styles.LabelStyle();
            layLabel.Style.CollisionDetection = true;
            layLabel.Style.CollisionBuffer = new SizeF(20, 20);
            layLabel.Style.ForeColor = Color.White;
            layLabel.Style.Font = new Font(FontFamily.GenericSerif, 8);
            layLabel.MaxVisible = 90;
            layLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
I set the Column Name for the Label Text [Name] and for the Angle [Angle] as well as the delegate function to calculate the position.

But when I load the Progam, the feature dataTable gets filled, but no Label is showing. I checked the SourceCode I found online for the LayerLabel Class and I think I did everything right. Anyone an Idea?
May 30, 2016 at 1:38 PM
You are sure that the coordinate systems are matching?