ArcGIS API For Silverlight实现面要素的动态标注

  如果需要对地图中所有面要素进行标注,当然我们可以直接在ArcMap中对数据进行处理加上标注。但是如果要实现选中要素的动态标注呢?

  首先,我们来看一下点要素的标注方法。我们知道在ArcGIS API For Silverlight的符号化中有一个是TextSymbol,因此可以利用这个来实现标注功能,TextSymbol是属于点的符号化,所以只需为一个点的Graphic的符号设置为TextSymbol,文本就可以绑定到相应的属性,或者是自己设置的文本内容也行。

  核心代码如下:

foreach (Graphic resultGraphic in featureSet)
{
  Brush b = new SolidColorBrush(Color.FromArgb(100, 255, 255, 255));

  Graphic graphicLabel = new Graphic()
  {
    Geometry =  resultGraphic.Geometry,
    Symbol = new TextSymbol()
    {
      Text = cbhtGraphic.Attributes["地块号"].ToString(),
      FontSize = 12,
      Foreground = b
    }
  };
  layer.Graphics.Add(graphicLabel);添加结果至GraphicLayer
}

  

  但如果我们要为一个面增加标注呢?那我们该如何获取器位置呢。这里我主要通过Extent中的GetCenter方法获取面要素的外包矩形的中心点作为标注点进行标注。

核心代码如下:

foreach (Graphic resultGraphic in featureSet)
{
  Brush b = new SolidColorBrush(Color.FromArgb(100, 255, 255, 255));

 Graphic graphicLabel = new Graphic()
 {
   Geometry =  resultGraphic.Geometry,
   Symbol = new TextSymbol()
   {
     Text = cbhtGraphic.Attributes["地块号"].ToString(),
     FontSize = 12,
     Foreground = b
   }
 };
  layer.Graphics.Add(graphicLabel);添加结果至GraphicLayer
}

 

posted @ 2014-10-02 20:01  GiserKNK  阅读(693)  评论(0编辑  收藏  举报