如何在圖上添加標(biāo)注

向死而生
1、增加標(biāo)注所在的動(dòng)態(tài)圖層public void loadElectMapText() { LabelLayer laber = new LabelLayer("Text", "Text"); mapControl
1.Map.Layers.Add(laber); }
2、標(biāo)注所在圖層的索引 public int GetLayerByName(string strLayerName) { for (int i = 0; i < mapControl
1.Map.Layers.Count; i++) { if (mapControl
1.Map.Layers[i].Name == strLayerName) return i; } return -1; }
3、自動(dòng)添加標(biāo)注 public void DisplayText(string strLayerText,string property,bool blShow) { //自動(dòng)標(biāo)注 int nTextLayer = GetLayerByName("Text"); if (nTextLayer < 0) return; LabelLayer layer = (LabelLayer)mapControl
1.Map.Layers[nTextLayer]; LabelSource source = layer.Sources[strLayerText]; if (source != null) //已經(jīng)構(gòu)造了標(biāo)注,則不再構(gòu)建。 return; source = new LabelSource(MapInfo.Engine.Session.Current.Catalog.GetTable(strLayerText)); if (source == null) return; source.DefaultLabelProperties.Caption =property;//標(biāo)注用到的那個(gè)字段名稱 //source.DefaultLabelProperties.Style.Font.Name = "宋體";//字體 source.DefaultLabelProperties.Style.Font.Size = 9;//大小 source.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.CenterCenter;//標(biāo)注顯示的位置 // source.DefaultLabelProperties.Layout.Offset = 7;//偏移量 source.DefaultLabelProperties.Style.Font.ForeColor = System.Drawing.Color.Red;//標(biāo)注字顏色 layer.DefaultLabelProperties.Style.Font.TextEffect=MapInfo.Styles.TextEffect.Box;//標(biāo)注背景,Box為方框,Halo為光暈 // layer.DefaultLabelProperties.Style.Font.BackColor=System.Drawing.Color.Yellow;//方框或者光暈的顏色 //layer.DefaultLabelProperties.Style.Font.Shadow = true;//顯示陰影 layer.Sources.Append(source); layer.Enabled = blShow;//layer.Enable要設(shè)置為true 否則不可見 }

才華橫溢的包子
2021-09-23 17:23:54 1377查看 1回答

謝謝
2021-09-23 17:23:54 1024查看 1回答

一千零一夜
2021-09-23 17:25:32 777查看 1回答
2021-09-23 17:25:32 661查看 0回答

萌路家的貓
2021-09-23 17:34:26 665查看 2回答