Label not display!!!

Topics: Algorithms, CompactFramework, Data Access, Español, General Topics, Italiano, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls, WinForms Controls
Jun 20, 2011 at 8:41 AM

I can display coordinate point as icon (png) on Map.But Label not display. 

Code:

 private SharpMap.Map InitializeMap(Size size)    

{

 Map map = new Map(size);

SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");       

layCountries.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\hchinh_region_reprojected.shp"), true);       

layCountries.Style.Fill = new SolidBrush(Color.White);       

layCountries.Style.Outline = System.Drawing.Pens.LightGray;       

layCountries.Style.EnableOutline = true;       

map.Layers.Add(layCountries);       

string connectionString = "Server=MANH-PC;uid=sa;pwd=123456;Database=DSS";       

DataTable dtCities = getCitiesDataSource();       

VectorLayer layCities = new VectorLayer("Cities");       

layCities.DataSource = new SharpMap.Data.Providers.MsSql(connectionString, "cities", "WKB_Geometry", "oid");       

DataTablePoint dtPoint = new SharpMap.Data.Providers.DataTablePoint(dtCities, "OID","Envelope_MinX", "Envelope_MinY");

 VectorLayer searchingLayer = new VectorLayer("VietNam", dtPoint);       

searchingLayer.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\ball.bmp")); //new System.Drawing.Bitmap(@"~\App_Data\here.PNG");       

searchingLayer.SRID = 4326;

//ADD layer Cities   

layCities.Style.SymbolScale = 0.8f;       

layCities.SRID = 4326;       

LabelLayer layCityLabel = new LabelLayer("City labels");       

layCityLabel.DataSource = layCities.DataSource;       

layCityLabel.Enabled = true;       

layCityLabel.LabelColumn = "NAME";      //this is a field in SQL.   

layCityLabel.MaxVisible = layLabel.MinVisible;       

layCityLabel.Style = new LabelStyle();       

layCityLabel.Style.ForeColor = Color.Black;       

layCityLabel.Style.Font = new Font(FontFamily.GenericSansSerif, 11);       

layCityLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;       

layCityLabel.Style.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom;     

  layCityLabel.Style.Offset = new PointF(3, 3);       

layCityLabel.TextRenderingHint = TextRenderingHint.AntiAlias;       

layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;       

layCityLabel.SRID = 4326;       

layCityLabel.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;       

layCityLabel.Style.CollisionDetection = true;       

map.Layers.Add(layCities);       

map.Layers.Add(layCityLabel);       

map.Layers.Add(searchingLayer);
return map;

}

 

  public static DataTable getCitiesDataSource()   

{        string strConnect = "Server=MANH-PC;uid=sa;pwd=123456;Database=DSS";     

  SqlConnection sqlConnect;       

SqlCommand sqlCmd;       

SqlDataAdapter adapter;     

  DataTable dt;
 string strQuery = "Select * From " + "cities" + " WHERE NAME ='" + "VietNam" + "'";
        sqlConnect = new SqlConnection(strConnect);       

sqlCmd = new SqlCommand(strQuery, sqlConnect);       

adapter = new SqlDataAdapter();        dt = new DataTable();
        try     

  {            sqlConnect.Open();         

  adapter.SelectCommand = sqlCmd;         

  adapter.Fill(dt);     

  }       

catch (Exception ex)       

{                   

  }       

finally       

{           

sqlConnect.Close();     

  }       

return dt; 

  }

 

I don't understand label not display when point display 

Thankyou Every One

Coordinator
Jun 20, 2011 at 11:52 AM

try commenting out this line:

layCityLabel.MaxVisible = layLabel.MinVisible;

Hth FObermaier

Jun 21, 2011 at 3:18 AM

I checked but it seems that is not problem label not display.

I show point on Map.( Envelope_Minx and Envelope_MinY).

I show label :layCityLabel.LabelColumn = "NAME";      // "NAME "is a field in SQL.

I don't know ,true or false.

Database:

oid    Envelope_Minx   Envelope_Miny   Name

1 10 10     redriver

2               11                    20     duongriver

 

I loaded point (10,10 ) and point (11;20) but "Name" Redriver and duongriver not display on map

Jun 21, 2011 at 7:59 AM

In fact, I am having problems rendering the labels layer too. The Map is completeley filled with BLACK. SharpMapVersion -0.9

Here's the code I used

LabelLayer layLabel = new LabelLayer("Country labels");
layLabel.DataSource = layer.DataSource; //layer is the Country layer, which is rendered correctly

layLabel.Enabled = true;
layLabel.LabelColumn = "STATE_NAME";
layLabel.Style = new LabelStyle();
layLabel.Style.ForeColor = Color.White;
layLabel.Style.Font = new Font(FontFamily.GenericSerif, 12);
layLabel.SRID = 4326;

//layLabel.Style.BackColor = new SolidBrush(Color.FromArgb(128, 255, 0, 0));
//layLabel.MaxVisible = 90;
/layLabel.MinVisible = 30;
/layLabel.Style.CollisionDetection = true;
//layLabel.Style.CollisionBuffer = new SizeF(20, 20);
//layLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
//layLabel.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest;

 

 

 

Jun 22, 2011 at 3:30 AM

Thank you every one.

I used a layer for label.

I can run successfull