ArcGIS API for Silverlight 动态添加点的同时,添加文字说明(利用TextSymbol添加多文字信息 )

  



     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, 33.0696150000001)),
                Symbol = textSymbol
            };
            graphicsLayer.Graphics.Add(graphicText);

        }


主要是利用TextSymbol类来作为文字的显示,然后添加到Graphics中去。

如果需要在动态添加图标记的同时,添加多个文字注视的话,比如在点的上方添加数值,点的下方添加名称,这样的话,我们可以调整的有TextSymbol的OffsetX和OffsetY属性,进行相应的调整即可达到实现目的。


 #region 水位/雨量 数值
TextSymbol textSymbol2 = new TextSymbol()
{
        FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"),
        Foreground = new System.Windows.Media.SolidColorBrush(Color.FromArgb(255, 255, 0, 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



实际的效果如下图,并且随着地图的缩放,这些文字也是随着更改,不会出现位置偏差


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值