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

how to add a text layer

Oct 17, 2014 at 7:43 AM

I want to add some text to mark my polylines, and here's my code
            SharpMap.Layers.LabelLayer labellayer = new SharpMap.Layers.LabelLayer("labelLayer");
            GeoAPI.Geometries.Coordinate mapCoordinate = mapBoxCentre.Map.ImageToWorld(new PointF(100, 100));
            var factory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(4326);
            var point = factory.CreatePoint(mapCoordinate);
            List<GeoAPI.Geometries.IGeometry> pti = new List<GeoAPI.Geometries.IGeometry>();
            labellayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(pti);
            labellayer.Style.Font = new Font("Arial", 12);
            labellayer.Style.ForeColor = Color.Black;

            labellayer.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            labellayer.LabelStringDelegate = LabelDelegate;

    private string LabelDelegate(SharpMap.Data.FeatureDataRow fdr)
        //Simple output, but you can filter by FeatureDataRow fdr
        return "foobar";

but it does not work, can someone help me ? thx!
Oct 17, 2014 at 8:15 AM
Geometry provider does not work with labeling. Use GeometryFeatureProvider instead.
Oct 19, 2014 at 3:32 PM
it works, thx