如何在圖上添加標注

向死而生
1、增加標注所在的動態圖層public void loadElectMapText() { LabelLayer laber = new LabelLayer("Text", "Text"); mapControl
1.Map.Layers.Add(laber); }
2、標注所在圖層的索引 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、自動添加標注 public void DisplayText(string strLayerText,string property,bool blShow) { //自動標注 int nTextLayer = GetLayerByName("Text"); if (nTextLayer < 0) return; LabelLayer layer = (LabelLayer)mapControl
1.Map.Layers[nTextLayer]; LabelSource source = layer.Sources[strLayerText]; if (source != null) //已經構造了標注,則不再構建。 return; source = new LabelSource(MapInfo.Engine.Session.Current.Catalog.GetTable(strLayerText)); if (source == null) return; source.DefaultLabelProperties.Caption =property;//標注用到的那個字段名稱 //source.DefaultLabelProperties.Style.Font.Name = "宋體";//字體 source.DefaultLabelProperties.Style.Font.Size = 9;//大小 source.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.CenterCenter;//標注顯示的位置 // source.DefaultLabelProperties.Layout.Offset = 7;//偏移量 source.DefaultLabelProperties.Style.Font.ForeColor = System.Drawing.Color.Red;//標注字顏色 layer.DefaultLabelProperties.Style.Font.TextEffect=MapInfo.Styles.TextEffect.Box;//標注背景,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要設置為true 否則不可見 }

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

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

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

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