Adding a labelLayer on the fly with fix TEXT values.

Topics: General Topics
Oct 10, 2006 at 5:06 PM

Is it possible to do that?

I tried to do something like this:

SharpMap.Layers.LabelLayer label = new SharpMap.Layers.LabelLayer("hazszam_felirat");
label.Style.ForeColor = Color.Black;
label.Style.Font = new Font("Arial CE", 12);
label.DataSource = SharpMap.Data.Providers.GeometryProvider();
label.Style.Offset = new PointF(20, 20);

Unfortunately I didn't find any label.Text property or something. I tried to dig deeper in the source code but I failed.

It would be great to do this: label.Text = "static text";

Thanks if you have any idea.

Oct 10, 2006 at 9:27 PM

You can simply use a delegate for applying a custom label.
        SharpMap.Layers.LabelLayer label = new SharpMap.Layers.LabelLayer("Label Layer");
        label.DataSource = myShapeLayer.DataSource;
        label.LabelStringDelegate = LabelDelegate;
private string LabelDelegate(SharpMap.Data.FeatureDataRow fdr)
        //Simple output, but you can filter by FeatureDataRow fdr
        return "foobar";

Oct 11, 2006 at 7:15 AM

I tried this before I asked you to help me.

I found that the GeometryProvider doesn't implement the following methods, and when I tried your code the program threw and exception based on the following code from GeometryProvider.cs

public void ExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
throw new NotSupportedException("Attribute data is not supported by the GeometryProvider.");

public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox box, FeatureDataSet ds)
throw new NotSupportedException("Attribute data is not supported by the GeometryProvider.");

Thanks if you can help.

Oct 11, 2006 at 8:58 AM
Actually I just wanna add a layer dinamically to the map with only one label with a fix Text. That's why I hava to use the GeometryProvider class.

And it seems it's not that easy...

Oct 11, 2006 at 10:04 AM
I found something!!

If I add add a Layer, like a VectorLayer, and then a LabelLayer with static text using the LabelStringDelegate method the program throw an exception.

But If I use just a LabelLayer everything is fine.

Does anyone have idea?

The exception caused by the unimplemented methods from the GeometryProvider. / ExecuteIntersectionQuery /

Oct 11, 2006 at 10:19 AM
This is my source code. It throws that exception what I told you:

SharpMap.Layers.VectorLayer streetLayer = new SharpMap.Layers.VectorLayer("streetsLayer");
streetLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(@"c:\Oliver\temp\map\Budapest-Eov-EsriShape\street_region.shp");
streetLayer.SRID = 23700;
streetLayer.Style.Fill = new System.Drawing.SolidBrush(Color.GreenYellow);
streetLayer.Style.Outline = new Pen(Color.Black);
streetLayer.Style.EnableOutline = true;

SharpMap.Layers.LabelLayer label = new SharpMap.Layers.LabelLayer("labelLayer");
SharpMap.Geometries.Point p = map.ImageToWorld(new PointF(100,100));
label.DataSource = new SharpMap.Data.Providers.GeometryProvider(p);
label.Style.Font = new Font("Arial", 12);
label.Style.ForeColor = Color.Black;
label.LabelStringDelegate = GetString;
label.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
label.SRID = 23700;


I have to figure out this problem somehow.


Oct 13, 2006 at 4:23 AM
I think you have to call .Open() on your two DataSource's before you can use them.