在前面的博客中提到动态添加点,地址:http://blog.csdn.net/taomanman/article/details/7354103
public void AddMarkergraphics() { ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator(); Graphicslayer graphicslayer = myMap.Layers["MyGraphicslayer"] as Graphicslayer; //添加点信息 Graphic graphic = new Graphic() { Geometry = mercator.FromGeographic(new MapPoint(115.257113,33.0696150000001)),Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol }; graphicslayer.Graphics.Add(graphic); //添加文字信息 TextSymbol textSymbol = new TextSymbol() { FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"),Foreground = new System.Windows.Media.solidColorBrush(Color.FromArgb(255,117,20,99)),FontSize = 12,Text = "需要添加的文字,可以根据需要动态读取赋值" }; Graphic graphicText = new Graphic() { Geometry = mercator.FromGeographic(new MapPoint(115.257113,Symbol = textSymbol }; graphicslayer.Graphics.Add(graphicText); }
主要是利用TextSymbol类来作为文字的显示,然后添加到Graphics中去。
如果需要在动态添加图标记的同时,添加多个文字注视的话,比如在点的上方添加数值,点的下方添加名称,这样的话,我们可以调整的有TextSymbol的OffsetX和OffsetY属性,进行相应的调整即可达到实现目的。
#region 水位/雨量 数值 TextSymbol textSymbol2 = new TextSymbol() { FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"),255,0)),FontSize = 14,Text = item.YL24.ToString(),OffsetX = 6,OffsetY = 20 }; Graphic graphicText2 = new Graphic() { Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(),System.Globalization.CultureInfo.InvariantCulture),double.Parse(item.Longitute.ToString().Trim(),System.Globalization.CultureInfo.InvariantCulture))),Symbol = textSymbol2 }; graphicText.Attributes["TextYL"] = item.YL24; graphicslayer.Graphics.Add(graphicText2); #endregion
实际的效果如下图,并且随着地图的缩放,这些文字也是随着更改,不会出现位置偏差
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。