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

How to add my own label?

Topics: General Topics
May 31, 2007 at 2:27 AM
I want to add my own label on the map such as google map, can Sharpmap support to add own label?
I want to know it. If anyone knows,please tell me.Thank you!
I am looking forward to it.
Jun 1, 2007 at 1:15 PM
Here is a work around. I had to do this as posts like
Adding a labelLayer on the fly with fix TEXT values. could not create a label and throwing this exception:
"Attribute data is not supported by the GeometryProvider."

What I am doing is, creating a Bitmap with the string that I want, using DrawString and adding this to the layer as a symbol.

Here is the code:

SharpMap.Layers.VectorLayer SymbolsLayer = new SharpMap.Layers.VectorLayer("Symbol");
List<SharpMap.Geometries.Geometry> geometries = new List<SharpMap.Geometries.Geometry>();
geometries.Add(new SharpMap.Geometries.Point(p.X, p.Y));
SymbolsLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(geometries);
Bitmap labelbmp = new Bitmap(80, 20);
Graphics g = Graphics.FromImage(labelbmp);
g.DrawString("Some Text", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Red), 1, 1);
SymbolsLayer.Style.Symbol = labelbmp;

I am sure this is not a good method and there are limitations but atleast I am not getting any exceptions.
Jun 4, 2007 at 8:20 AM
List<SharpMap.Geometries.Geometry> geometries = new List<SharpMap.Geometries.Geometry>();

say List not define. what is the issue.
Jun 4, 2007 at 10:34 AM
Add this to the top of the code next to the other lines with "using...".

using System.Collections.Generic;