silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(三)--绘制点、线、圆,显示提示信息大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

  ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(三)--绘制点、线、圆,显示提示信息 平台:Vs 2010,Blend 4,Silverlight 4 调用API: ArcGis for Silverligth API(ESRI.ArcGIs.CLIENt) 转载自:http://www.cnblogs.com/Royal_WH/archive/20
 

ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(三)--绘制点、线、圆,显示提示信息

平台:Vs 2010,Blend 4,Silverlight 4

调用API: ArcGis for Silverligth API(ESRI.ArcGIs.CLIENt)

转载自:http://www.cnblogs.com/Royal_WH/archive/2010/11/05/1869906.html@H_607_34@

OK,今天又有空来写点啦,这个例子自己不想拉的太长了,所以这节多写点东西,我尽量把东西都介绍全面,有不懂的可以留言~

有空大家共同讨论。

@H_607_34@

好进入正题,如今天标题所示,我们先来看画点,线,圆吧!

01 /// <sum@R_262_11035@>
02 /// 绘制界面上的点和线
03 /// </sum@R_262_11035@>
04 /// <param name="mymap"></param>
05 /// <param name="point"></param>
06 /// <param name="pointLine"></param>
07 public void DrawAnimationCompleted(Map mymap,List<Graphic> point,ESRI.ArcGIs.CLIENt.Geometry.PointCollection pointLinE)
08 {
09     GraphicsLayer gPointLayer = new GraphicsLayer();
10     GraphicsLayer lineLayer = new GraphicsLayer();
11     SimpleLinesymbol linesymbol = new SimpleLinesymbol();
12     linesymbol.Color = new SolidColorBrush(Colors.brown);
13     linesymbol.Width = 1;
14     linesymbol.Style = SimpleLinesymbol.Linestyle.solid;
15  
16     // 画线到图层上并绘制到地图上
17     Gismap.AddLayersToMap(mymap,new GraphicsLayer[] { lineLayer });
18     GisLine.DrawLineOnMap(pointLine,lineLayer,linesymbol);
19  
20     Gismap.DrawAllLayers(mymap,new GraphicsLayer[] { gPointLayer },point);
21     Gismap.AddLayersToMap(mymap,new GraphicsLayer[] { gPointLayer });
22 }

好,看一下如何画圆吧。

01 /// <sum@R_262_11035@>
02 /// 在地图上绘制圆
03 /// </sum@R_262_11035@>
04 /// <param name="mymap">地图</param>
05 /// <param name="container">绘制容器</param>
06 /// <param name="pt">要绘制的点</param>
07 /// <param name="drawCircleLayer"></param>
08 /// <param name="circleKm">直径</param>
09 /// <param name="color">填充色</param>
10 /// <param name="ellipsestroke">边框色</param>
11 public void DrawEllipse(Map mymap,Canvas container,MapPoint pt,ref ElementLayer drawCircleLayer,double circleKm,Color color,Color ellipsestroke)
12 {
13     if (!drawCircleLayer.Children.Contains(container))
14     {
15 @R_944_5179@ drawCircleLayer.Children.Add(container);
16 @R_944_5179@ container.opacity = 0.5;
17 @R_944_5179@ container.SETVALue(ElementLayer.EnvelopeProperty,new Envelope(mymap.Extent.XMax,mymap.Extent.ymax,mymap.Extent.XMin,mymap.Extent.ymin));
18     }
19  
20     Point ptFirst = mymap.MapToScreen(new @H_551_170@mapPoint(Convert.ToDouble(pt.X),
21 @R_944_5179@ Convert.ToDouble(pt.Y)));
22  
23     Point pt7 = mymap.MapToScreen(new @H_551_170@mapPoint((Convert.ToDouble(pt.X) + circleKm * kmToEN),
24 @R_944_5179@ Convert.ToDouble(pt.Y)));
25  
26     Ellipse ellipse7 = new Ellipse();
27     ellipse7.Width = (pt7.X - ptFirst.X) * 2;
28     ellipse7.Height = ellipse7.Width;
29     ellipse7.strokeThickness = 1;
30     ellipse7.stroke = new SolidColorBrush(ellipsestroke);
31     ellipse7.Fill = new SolidColorBrush(color);
32     Canvas.SetLeft(ellipse7,ptFirst.X - ellipse7.Width / 2);
33     Canvas.SetTop(ellipse7,ptFirst.Y - ellipse7.Width / 2);
34     ellipse7.opacity = 0.5;
35  
36     container.Children.Add(ellipse7);
37     container.IsHitTestVisible = false;
38     container.SETVALue(Canvas.ZIndexProperty,-10);
39 }

这是一个画圆的方法,需要地图类,点,Canvas容器,Gis 的地图层ElementLayer和color

前台是这样调用

/// <sum@R_262_11035@>
  /// 绘制7级风圈和10级风圈
  /// </sum@R_262_11035@>
  /// <param name="mymap"></param>
  /// <param name="sender"></param>
  public void DrawEllipse7And10WindCircle(Map mymap,object sender)
  {
@R_944_5179@           if (Gismap.LayerExist(mymap,"WindCircleLayer"))           
 {                Gismap.deleteLayersToMap(mymap,"WindCircleLayer");            }
  
@R_944_5179@     ElementLayer circleLayer = new ElementLayer();
@R_944_5179@     circleLayer.ID = "WindCircleLayer";
  
@R_944_5179@     Canvas circleCanvas = new Canvas();
  
@R_944_5179@     Graphic tipGraphic = sender as Graphic;
  
@R_944_5179@     if (Convert.ToDouble(tipGraphic.Attributes["WindCircle7"]) != 0)
@R_944_5179@     {
@R_944_5179@@R_944_5179@  Color color = new Color();
@R_944_5179@@R_944_5179@  color.A = 255;
@R_944_5179@@R_944_5179@  color.R = 153;
@R_944_5179@@R_944_5179@  color.G = 105;
@R_944_5179@@R_944_5179@  color.b = 192;
  
@R_944_5179@@R_944_5179@  DrawEllipse(mymap,circleCanvas,new @H_551_170@mapPoint(Convert.ToDouble(tipGraphic.Attributes["Longitude"]),
@R_944_5179@@R_944_5179@      Convert.ToDouble(tipGraphic.Attributes["Latitude"])),ref circleLayer,
@R_944_5179@@R_944_5179@      Convert.ToDouble(300),color,Colors.bluE);
  
@R_944_5179@     }
  
@R_944_5179@     if (Convert.ToDouble(tipGraphic.Attributes["WindCircle10"]) != 0)
@R_944_5179@     {
@R_944_5179@@R_944_5179@  Color color = new Color();
@R_944_5179@@R_944_5179@  color.A = 255;
@R_944_5179@@R_944_5179@  color.R = 111;
@R_944_5179@@R_944_5179@  color.G = 91;
@R_944_5179@@R_944_5179@  color.b = 171;
  
@R_944_5179@@R_944_5179@  this.DrawEllipse(mymap,
@R_944_5179@@R_944_5179@      Convert.ToDouble(tipGraphic.Attributes["WindCircle10"]),Colors.bluE);
@R_944_5179@     }
  
  
@R_944_5179@     Gismap.AddLayersToMap(mymap,new ElementLayer[] { circleLayer });
@R_944_5179@ }

这里的sender是一个Gis元素 Graphic,根据我的Webservice 取到的实体后我把这个点加上Attributes,一系列属性,所以在上面的代码可以看到tipGraphic.Attributes["WindCircle10"],

@H_607_34@

下面的代码就是在我从Webservice取到实体后做添加点的代码:

/// <sum@R_262_11035@>
/// 添加台风点代码
/// 添加鼠标移入、移出事件
/// </sum@R_262_11035@>
/// <param name="model"></param>
/// <param name="i"></param>
private void AddPointToGraphic(TyphoonModel model, int i,List<Graphic> pointParam)
{
    SimpleMarkerSymbol symbol = new SimpleMarkerSymbol();
    Color color = new Color();
    color.A = 255;
      
    if (Convert.ToDouble(model.WS) <= 17.1)
    {
@R_944_5179@ color.R = 0;
@R_944_5179@ color.G = 254;
@R_944_5179@ color.b = 223;
@R_944_5179@ symbol.Color = new SolidColorBrush(color);
    }
    else if (Convert.ToDouble(model.WS) > 17.1 && Convert.ToDouble(model.WS) <= 24.4)
    {
@R_944_5179@ color.R = 254;
@R_944_5179@ color.G = 243;
@R_944_5179@ color.b = 0;
@R_944_5179@ symbol.Color = new SolidColorBrush(color);
    }
    else if (Convert.ToDouble(model.WS) > 24.4 && Convert.ToDouble(model.WS) <= 32.6)
    {
@R_944_5179@ color.R = 254;
@R_944_5179@ color.G = 144;
@R_944_5179@ color.b = 44;
@R_944_5179@ symbol.Color = new SolidColorBrush(color);
    }
    else if (Convert.ToDouble(model.WS) > 32.6 && Convert.ToDouble(model.WS) <= 41.4)
    {
@R_944_5179@ color.R = 254;
@R_944_5179@ color.G = 4;
@R_944_5179@ color.b = 4; symbol.Color = new SolidColorBrush(color);
    }
    else if (Convert.ToDouble(model.WS) > 41.4 && Convert.ToDouble(model.WS) <= 50.9)
    {
@R_944_5179@ color.R = 254;
@R_944_5179@ color.G = 58;
@R_944_5179@ color.b = 163; symbol.Color = new SolidColorBrush(color);
    }
    else if (Convert.ToDouble(model.WS) > 50.9)
    {
@R_944_5179@ color.R = 174;
@R_944_5179@ color.G = 0;
@R_944_5179@ color.b = 217; symbol.Color = new SolidColorBrush(color);
    }
 
    symbol.Size = 10;
    if (i == 0)
    {
@R_944_5179@ symbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Square;
    }
    else
    {
@R_944_5179@ symbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle;
    }
 
    pointParam.Add(new Graphic()
    {
@R_944_5179@ Geometry = new @H_551_170@mapPoint(model.Longitude,model.LatitudE),
@R_944_5179@ Symbol = symbol
    });
 
    pointParam[i].Attributes.Add("TyphoonID",model.TyphoonID);
    pointParam[i].Attributes.Add("TyphoonNo",model.TyphoonNo);
    pointParam[i].Attributes.Add("TyphoonName",model.TyphoonName);
    pointParam[i].Attributes.Add("WindCircle7",model.WindCircle7);
    pointParam[i].Attributes.Add("WindCircle10",model.WindCircle10);
    pointParam[i].Attributes.Add("WS",model.WS);
    pointParam[i].Attributes.Add("Pressure",model.PressurE);
    pointParam[i].Attributes.Add("IssueTime",model.IssueTimE);
    pointParam[i].Attributes.Add("Future",model.FuturE);
    pointParam[i].Attributes.Add("Latitude",model.LatitudE);
    pointParam[i].Attributes.Add("Longitude",model.LongitudE);
}

@H_607_34@

信息提示功能如图:

@H_607_34@

ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(三)--绘制点、线、圆,显示提示信息

@H_607_34@

@H_607_34@

我们先看下Xmal中的代码:

 

<Canvas x:Name="typhoonPoinTinfoCanvas" Visibility="Visible" Height="188" HorizontalAlignment="Left" @H_810_3188@margin="0,-272,0" VerticalAlignment="Top" Width="360">
    <Path Stretch="Fill" stroke="Black"  Height="168.5" Width="328.5" UseLayoutRounding="false" Canvas.Left="0.5" Canvas.Top="-0.5" Data="M113,25 C113,11.745166 123.74516,1.0000004 137,1.0000004 L304,1.0000004 c317.25482,1.0000004 328,11.745166 328,25 L328,144 C328,157.25484 317.25482,168 304,168 L137,168 C123.74516,168 113,157.25484 113,144 z M112.5,24.499998 L0.5,0.5 L112.5,72.499992 z" Fill="{Staticresource CommonGradient2}"/>
 
    <StackPanel Orientation="Vertical" Height="168" Width="176" Canvas.Left="137" Canvas.Top="15">
@R_944_5179@ <TextBlock x:Name="typhoonNameTextBlock" Height="20" Text="名称:" Foreground="White" textwrapping="Wrap"/>
@R_944_5179@ <TextBlock x:Name="typhoonCollectionTimeTextBlock" Height="20" Text="时间:" Foreground="White" textwrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
@R_944_5179@ <TextBlock x:Name="typhoonPositiontextBlock" Height="20" Text="位置:" Foreground="White" textwrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
@R_944_5179@ <TextBlock x:Name="typhoonWSTextBlock" Height="20" Text="最大风速:" Foreground="White" textwrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
@R_944_5179@ <TextBlock x:Name="typhoonPressureTextBlock" Height="20" Text="中心气压:" Foreground="White" textwrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
@R_944_5179@ <TextBlock x:Name="typhoonCircle7TextBlock" Height="20" Text="7级风圈半径:" Foreground="White" textwrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
@R_944_5179@ <TextBlock x:Name="typhoonCircle10TextBlock" Height="20" Text="10级风圈半径:" Foreground="White" textwrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
 
    </StackPanel>
</Canvas>
        <LinearGradientBrush x:Key="CommonGradient" StartPoint="0.5,0" EndPoint="0.5,1">            <GradientStop Offset="0" Color="#ee76a8d3"/>            <GradientStop Offset="0.25" Color="#ee5b8cb5"/>            <GradientStop Offset="0.75" Color="#ee4b7ba7"/>        </LinearGradientBrush><BR>

 

 

看下c# 中的代码:

当我们添加那些点也就是 Graphic 的时候有这样一个事件MouseEventHandler

@H_607_34@

 

01 // 添加点和线,先显示点层,动画结束后显示线层
02 @H_551_170@mapDraw.DrawLineAndPoint(ref point,mymap,gLayer,ref pointLine,e,length);
03  
04  
05 // 添加点事件
06 foreach (Graphic item in point)
07 {
08     item.MouseEnter += new @H_551_170@mouseEventHandler(MainPage_MouseEnter);
09     item.MouSELEave += new @H_551_170@mouseEventHandler(MainPage_DrawLinE);
10 }

 

 

 

01 /// <sum@R_262_11035@>
02 /// 绘制单条台风动画前的信息
03 /// </sum@R_262_11035@>
04 /// <param name="point"></param>
05 /// <param name="mymap"></param>
06 /// <param name="gLayer"></param>
07 /// <param name="pointLine"></param>
08 /// <param name="e"></param>
09 /// <param name="length"></param>
10 public void DrawLineAndPoint(ref List<Graphic> point,Map mymap,GraphicsLayer gLayer,
11    ref ESRI.ArcGIs.CLIENt.Geometry.PointCollection pointLine,GetTyphoonsCompletedEventArgs e,int length)
12 {
13     #region 添加代码
14     point = new List<Graphic>();
15     for (int i = 0; i < length; i++)
16     {
17 @R_944_5179@ AddPointToGraphic(e.result[i],i,point);
18     }
19     #endregion
20  
21     // 添加线的代码
22     pointLine = new ESRI.ArcGIs.CLIENt.Geometry.PointCollection();
23     AddLineToMap(e.Result.ToList(),length,pointLinE);
24  
25     // 显示点层
26     Gismap.DrawAllLayers(mymap,new GraphicsLayer[] { gLayer },point);
27     Gismap.AddLayersToMap(mymap,new GraphicsLayer[] { gLayer });
28 }

 

1 AddPointToGraphic这个方法就是图片上面的那段代码
@H_62_4673@ @H_725_4674@
1 <SPAN style="FONT-SIZE: 14px"> item.MouseEnter += new @H_551_170@mouseEventHandler(MainPage_MouseEnter);     </SPAN>
1  item.MouSELEave += new @H_551_170@mouseEventHandler(MainPage_DrawLinE);  
@H_725_4674@
1 这两段代码就是我们添加鼠标移入和移出事件了,我们看下移入事件:
01 <DIV class=cnblogs_Highlighter><PRE class=brush:csharp>@R_944_5179@ void @H_551_170@mainPage_MouseEnter(object sender,MouseEventArgs E)
02 @R_944_5179@ {
03 @R_944_5179@     Graphic graphic = sender as Graphic;
04 @R_944_5179@     cursor = cursors.Hand;
05   
06 @R_944_5179@     typhoonPoinTinfoCanvas.Visibility = Visibility.Visible;
07   
08 @R_944_5179@     Point pt = mymap.MapToScreen(new @H_551_170@mapPoint(Convert.ToDouble(graphic.Attributes["Longitude"]),Convert.ToDouble(graphic.Attributes["Latitude"])));
09   
10 @R_944_5179@     typhoonPoinTinfoCanvas.SETVALue(Grid.MarginProperty,new Thickness(pt.X,pt.Y,0));
11   
12 @R_944_5179@     typhoonNameTextBlock.Text = "台风:" + graphic.Attributes["TyphoonName"].ToString();
13 @R_944_5179@     typhoonCollectionTimeTextBlock.Text = "时间:" + graphic.Attributes["IssueTime"].ToString();
14 @R_944_5179@     typhoonPositiontextBlock.Text = "位置:" + graphic.Attributes["Longitude"].ToString() + "°E," + graphic.Attributes["Latitude"].ToString() + "°N";
15 @R_944_5179@     typhoonWSTextBlock.Text = "最大风速:" + graphic.Attributes["WS"].ToString() + " m/s";
16 @R_944_5179@     typhoonPressureTextBlock.Text = "中心气压:" + graphic.Attributes["Pressure"].ToString() + " hPa";
17 @R_944_5179@     typhoonCircle7TextBlock.Text = "7级风圈半径:" + graphic.Attributes["WindCircle7"].ToString() + " km";
18 @R_944_5179@     typhoonCircle10TextBlock.Text = "10级风圈半径:" + graphic.Attributes["WindCircle10"].ToString() + " km";
19   
20 @R_944_5179@     circle.DrawEllipse7And10WindCircle(mymap,sender);
21 @R_944_5179@     SELEctedGarphic = sender as Graphic;
22 @R_944_5179@ }</PRE>
23 </DIV>
1 我们看到在显示信息的同时我们又把圆画了上去<SPAN style="FONT-SIZE: 14px">DrawEllipse7And10WindCircle()这个函数</SPAN>

Gismap是个静态类,以下是他的代码

01 /// <sum@R_262_11035@>
02 /// ArcGis 调用
03 /// 动态加载、显示隐藏层数据、加载层上的点等
04 /// 日期:2010-5-10
05 /// 作者:AngelSoft
06 /// </sum@R_262_11035@>
07 public static class Gismap
08 {
09  
10     /// <sum@R_262_11035@>
11     /// 绘制所有的点到地图上
12     /// </sum@R_262_11035@>
13     /// <param name="glayer"></param>
14     /// <param name="cacheGraphic"></param>
15     public static void DrawSymbol(GraphicsLayer glayer,List<Graphic> cacheGraphiC)
16     {
17 @R_944_5179@ if (glayer != null)
18 @R_944_5179@ {
19 @R_944_5179@     int graphicCount = cacheGraphic.Count;
20 @R_944_5179@     for (int i = 0; i < graphicCount; i++)
21 @R_944_5179@     {
22 @R_944_5179@@R_944_5179@  glayer.Graphics.Add(cacheGraphic[i]);
23 @R_944_5179@     } // i
24 @R_944_5179@ }
25     }
001     /// <sum@R_262_11035@>
002     /// 加载所有图层上的点
003     /// 动态绘制
004     /// 图层和点的对应关系要正确
005     /// 有几个图层就要有几个点集合
006     /// </sum@R_262_11035@>
007     /// <param name="map">ArcGis 地图变量</param>
008     /// <param name="layers">GraphicLayer 层数组</param>
009     /// <param name="graphicParam">Graphic 点数组</param>
010     public static void DrawLayers(Map map,GraphicsLayer[] layers,params List<Graphic>[] graphicParam)
011     {
012 @R_944_5179@ // 计算要绘制的层数并一层一层的绘制(调用动态绘制方法)
013 @R_944_5179@ if (layers != null)
014 @R_944_5179@ {
015 @R_944_5179@     int length = layers.Length;
016 @R_944_5179@     for (int i = 0; i < length; i++)
017 @R_944_5179@     {
018 @R_944_5179@@R_944_5179@  if (layers[i] == null)
019 @R_944_5179@@R_944_5179@  {
020 @R_944_5179@@R_944_5179@      layers[i] = new GraphicsLayer();
021 @R_944_5179@@R_944_5179@  }
022 @R_944_5179@@R_944_5179@  DynamicDrawSymbol(layers[i],graphicParam[i],map);
023 @R_944_5179@     }
024 @R_944_5179@ }
025     }
026  
027  
028     /// <sum@R_262_11035@>
029     /// 加载所有图层上的点
030     /// 画所有点
031     /// 图层和点的对应关系要正确
032     /// 有几个图层就要有几个点集合
033     /// </sum@R_262_11035@>
034     /// <param name="map">ArcGis 地图变量</param>
035     /// <param name="layers">GraphicLayer 层数组</param>
036     /// <param name="graphicParam">Graphic 点数组</param>
037     public static void DrawAllLayers(Map map, params List<Graphic>[] graphicParam)
038     {
039 @R_944_5179@ // 计算要绘制的层数并一层一层的绘制(调用动态绘制方法)
040 @R_944_5179@ if (layers != null)
041 @R_944_5179@ {
042 @R_944_5179@     int length = layers.Length;
043 @R_944_5179@     for (int i = 0; i < length; i++)
044 @R_944_5179@     {
045 @R_944_5179@@R_944_5179@  if (layers[i] == null)
046 @R_944_5179@@R_944_5179@  {
047 @R_944_5179@@R_944_5179@      layers[i] = new GraphicsLayer();
048 @R_944_5179@@R_944_5179@  }
049 @R_944_5179@@R_944_5179@  DrawAllGraphics(layers[i],graphicParam[i]);
050 @R_944_5179@     }
051 @R_944_5179@ }
052     }
053  
054  
055  
056     /// <sum@R_262_11035@>
057     /// 隐藏或显示 ArcGis 层
058     /// </sum@R_262_11035@>
059     /// <param name="show">隐藏或显示</param>
060     /// <param name="layers">层</param>
061     public static void LayersVisibility(bool show,params GraphicsLayer[] layers)
062     {
063 @R_944_5179@ if (layers != null)
064 @R_944_5179@ {
065 @R_944_5179@     foreach (GraphicsLayer item in layers)
066 @R_944_5179@     {
067 @R_944_5179@@R_944_5179@  item.Visible = show;
068 @R_944_5179@     }
069 @R_944_5179@ }
070     }
071  
072  
073     /// <sum@R_262_11035@>
074     /// 将图层数组全部从 map 中移除
075     /// </sum@R_262_11035@>
076     /// <param name="map">表示一张 ArcGis 地图</param>
077     /// <param name="layers">表示地图层的数组</param>
078     public static void deleteLayersToMap(Map map,GraphicsLayer[] layers)
079     {
080 @R_944_5179@ // 逐个将数据移除
081 @R_944_5179@ foreach (GraphicsLayer item in layers)
082 @R_944_5179@ {
083 @R_944_5179@     @H_551_170@map.Layers.Remove(item);
084 @R_944_5179@ }
085     }
086  
087     /// <sum@R_262_11035@>
088     /// 根据 ID 号删除某层
089     /// </sum@R_262_11035@>
090     /// <param name="map"></param>
091     /// <param name="ID"></param>
092     /// <returns></returns>
093     public static void deleteLayersToMap(Map map,String[] ID)
094     {
095 @R_944_5179@ int length = ID.Length;
096  
097 @R_944_5179@ for (int i = 0; i < length; i++)
098 @R_944_5179@ {
099 @R_944_5179@     foreach (Layer item in @H_551_170@map.Layers)
100 @R_944_5179@     {
101 @R_944_5179@@R_944_5179@  if (item.ID == ID[i])
102 @R_944_5179@@R_944_5179@  {
103 @R_944_5179@@R_944_5179@      @H_551_170@map.Layers.Remove(item);
104 @R_944_5179@@R_944_5179@      length--;
105 @R_944_5179@@R_944_5179@      break;
106 @R_944_5179@@R_944_5179@  }
107 @R_944_5179@     }
108 @R_944_5179@ }
109     }
110  
111     /// <sum@R_262_11035@>
112     /// 将图层数组全部从 map 中移除
113     /// </sum@R_262_11035@>
114     /// <param name="map">表示一张 ArcGis 地图</param>
115     /// <param name="layers">表示地图层的数组</param>
116     public static void deleteLayersToMap(Map map,ElementLayer[] layers)
117     {
118 @R_944_5179@ // 逐个将数据移除
119 @R_944_5179@ foreach (ElementLayer item in layers)
120 @R_944_5179@ {
121 @R_944_5179@     @H_551_170@map.Layers.Remove(item);
122 @R_944_5179@ }
123     }
124  
125  
126     /// <sum@R_262_11035@>
127     /// 删除地图上的某一层
128     /// </sum@R_262_11035@>
129     /// <param name="mymap"></param>
130     /// <param name="ID">ID号</param>
131     public static void deleteLayersToMap(Map mymap,String ID)
132     {
133 @R_944_5179@ int layers = mymap.Layers.Count;
134 @R_944_5179@ for (int i = 0; i < layers; i++)
135 @R_944_5179@ {
136 @R_944_5179@     if (mymap.Layers[i].ID == ID)
137 @R_944_5179@     {
138 @R_944_5179@@R_944_5179@  @H_551_170@mymap.Layers.RemoveAt(i);
139 @R_944_5179@@R_944_5179@  return;
140 @R_944_5179@     }
141 @R_944_5179@ }
142     }
143  
144  
145     public static bool LayerExist(Map mymap,String ID)
146     {
147 @R_944_5179@ int layers = mymap.Layers.Count;
148 @R_944_5179@ for (int i = 0; i < layers; i++)
149 @R_944_5179@ {
150 @R_944_5179@     if (mymap.Layers[i].ID == ID)
151 @R_944_5179@     {
152 @R_944_5179@@R_944_5179@  return true;
153 @R_944_5179@     }
154 @R_944_5179@ }
155 @R_944_5179@ return false;
156     }
157  
158  
159     /// <sum@R_262_11035@>
160     /// 将图层数组全部添加到 map 中
161     /// </sum@R_262_11035@>
162     /// <param name="map">表示一张 ArcGis 地图</param>
163     /// <param name="layers">表示地图层的数组</param>
164     public static void AddLayersToMap(Map map,GraphicsLayer[] layers)
165     {
166 @R_944_5179@ // 逐个将数据添加到当前地图中
167 @R_944_5179@ foreach (GraphicsLayer item in layers)
168 @R_944_5179@ {
169 @R_944_5179@     if (item != null)
170 @R_944_5179@     {
171 @R_944_5179@@R_944_5179@  @H_551_170@map.Layers.Add(item);
172 @R_944_5179@     }
173 @R_944_5179@ }
174     }
175  
176     /// <sum@R_262_11035@>
177     /// 将图层数组全部添加到 map 中
178     /// </sum@R_262_11035@>
179     /// <param name="map">表示一张 ArcGis 地图</param>
180     /// <param name="layers">表示地图层的数组</param>
181     public static void AddLayersToMap(Map map,ElementLayer[] layers)
182     {
183 @R_944_5179@ // 逐个将数据添加到当前地图中
184 @R_944_5179@ foreach (ElementLayer item in layers)
185 @R_944_5179@ {
186 @R_944_5179@     @H_551_170@map.Layers.Add(item);
187 @R_944_5179@ }
188     }
189  
190     /// <sum@R_262_11035@>
191     /// 绘制所有的点到地图上
192     /// </sum@R_262_11035@>
193     /// <param name="eLayer"></param>
194     /// <param name="image"></param>
195     public static void AddImagetoElementLayer(ElementLayer eLayer,List<Image> imagE)
196     {
197 @R_944_5179@ if (eLayer != null)
198 @R_944_5179@ {
199 @R_944_5179@     foreach (Image item in imagE)
200 @R_944_5179@     {
201 @R_944_5179@@R_944_5179@  eLayer.Children.Add(item);
202 @R_944_5179@     }
203 @R_944_5179@ }
204     }
205  
206     /// <sum@R_262_11035@>
207     /// 隐藏或显示 ArcGis 层
208     /// </sum@R_262_11035@>
209     /// <param name="show">隐藏或显示</param>
210     /// <param name="layers">层</param>
211     public static void LayersVisibility(bool show,params ElementLayer[] layers)
212     {
213 @R_944_5179@ if (layers != null)
214 @R_944_5179@ {
215 @R_944_5179@     foreach (ElementLayer item in layers)
216 @R_944_5179@     {
217 @R_944_5179@@R_944_5179@  item.Visible = show;
218 @R_944_5179@     }
219 @R_944_5179@ }
220     }
221  
222     /// <sum@R_262_11035@>
223     /// 动态加载图层
224     /// 使用 ElementLayer 层
225     /// </sum@R_262_11035@>
226     /// <param name="eLayer"></param>
227     /// <param name="cacheGraphic"></param>
228     /// <param name="map"></param>
229     public static void DynamicDrawElementLayer(ElementLayer eLayer,List<UIElement> cacheElement,Map map)
230     {
231 @R_944_5179@ // 以下四个变量分别表示地图的四个边
232 @R_944_5179@ // 即最大经纬度和最小经纬度
233 @R_944_5179@ // xMax最大经度,ymax最大纬度
234 @R_944_5179@ double xMax = map.Extent.XMax + 2;
235 @R_944_5179@ double xMin = map.Extent.XMin - 2;
236 @R_944_5179@ double ymax = map.Extent.ymax + 2;
237 @R_944_5179@ double ymin = map.Extent.ymin - 2;
238  
239 @R_944_5179@ // 去除不在坐标范围内的点,先检查图层是否为空
240 @R_944_5179@ if (eLayer != null)
241 @R_944_5179@ {
242 @R_944_5179@     int graphicCount = eLayer.Children.Count;
243 @R_944_5179@     for (int i = 0; i < graphicCount; i++)
244 @R_944_5179@     {
245 @R_944_5179@@R_944_5179@  UIElement element = eLayer.Children[i];
246 @R_944_5179@@R_944_5179@    
247 @R_944_5179@@R_944_5179@  // 判断经度,纬度
248 @R_944_5179@@R_944_5179@  if (!(((element.GetValue(ElementLayer.EnvelopeProperty) as EnvelopE).Extent.XMax < xMax && (element.GetValue(ElementLayer.EnvelopeProperty) as EnvelopE).Extent.XMax > xMin)
249 @R_944_5179@@R_944_5179@      && ((element.GetValue(ElementLayer.EnvelopeProperty) as EnvelopE).Extent.ymax < ymax && (element.GetValue(ElementLayer.EnvelopeProperty) as EnvelopE).Extent.ymax > ymin)))
250 @R_944_5179@@R_944_5179@  {
251 @R_944_5179@@R_944_5179@      // 将点在地图上移除,并放在缓存中
252 @R_944_5179@@R_944_5179@      cacheElement.Add(eLayer.Children[i]);
253 @R_944_5179@@R_944_5179@      eLayer.Children.Remove(eLayer.Children[i]);
254 @R_944_5179@@R_944_5179@      graphicCount--;   // 当从集合中移除元素时应该把 graphicCount 减1
255 @R_944_5179@@R_944_5179@      i--;@R_944_5179@       // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
256 @R_944_5179@@R_944_5179@  }
257 @R_944_5179@     } // i
258 @R_944_5179@ }
259  
260 @R_944_5179@ // 检查缓存是否为空,并将点绘制到图形上
261 @R_944_5179@ if (cacheElement != null)
262 @R_944_5179@ {
263 @R_944_5179@     int count = cacheElement.Count;
264 @R_944_5179@     for (int i = 0; i < count; i++)
265 @R_944_5179@     {
266 @R_944_5179@@R_944_5179@  // 判断经度,纬度
267 @R_944_5179@@R_944_5179@  if (((cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as EnvelopE).Extent.XMax < xMax && (cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as EnvelopE).Extent.XMax > xMin)
268 @R_944_5179@@R_944_5179@      && ((cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as EnvelopE).Extent.ymax < ymax && (cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as EnvelopE).Extent.ymax > ymin))
269 @R_944_5179@@R_944_5179@  {
270 @R_944_5179@@R_944_5179@      // 运行到此则该点在目前地图范围内,将该点加入到地图中
271 @R_944_5179@@R_944_5179@      eLayer.Children.Add(cacheElement[i]);
272 @R_944_5179@@R_944_5179@      cacheElement.Remove(cacheElement[i]);
273 @R_944_5179@@R_944_5179@      count--;    // 当从集合中移除元素时应该把 count 减1
274 @R_944_5179@@R_944_5179@      i--;@R_944_5179@ // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
275 @R_944_5179@@R_944_5179@      conTinue;
276 @R_944_5179@@R_944_5179@  }
277 @R_944_5179@     }
278 @R_944_5179@ }
279     }
280  
281     /// <sum@R_262_11035@>
282     /// 将所有元素画到地图上
283     /// </sum@R_262_11035@>
284     /// <param name="eLayer"></param>
285     /// <param name="cacheElement"></param>
286     public static void DrawAllUIElement(ElementLayer eLayer,List<UIElement> cacheElement)
287     {
288 @R_944_5179@ if (eLayer != null)
289 @R_944_5179@ {
290 @R_944_5179@     foreach (UIElement item in cacheElement)
291 @R_944_5179@     {
292 @R_944_5179@@R_944_5179@  eLayer.Children.Add(item);
293 @R_944_5179@     }
294 @R_944_5179@ }
295     }
296  
297     /// <sum@R_262_11035@>
298     /// 动态的绘制图层
299     /// 当然地图移动到相应的坐标后绘制(保留原来的点,绘制新的数据)
300     /// 实现了无刷新绘制
301     /// </sum@R_262_11035@>
302     /// <param name="glayer">表示地图上的层</param>
303     /// <param name="cacheGraphic">存放 Graphics 的缓存</param>
304     /// <param name="map">表示一张 ArcGis 地图</param>
305     private static void DynamicDrawSymbol(GraphicsLayer glayer,List<Graphic> cacheGraphic,Map map)
306     {
307 @R_944_5179@ // 以下四个变量分别表示地图的四个边
308 @R_944_5179@ // 即最大经纬度和最小经纬度
309 @R_944_5179@ // xMax最大经度,ymax最大纬度
310 @R_944_5179@ double xMax = map.Extent.XMax + 2;
311 @R_944_5179@ double xMin = map.Extent.XMin - 2;
312 @R_944_5179@ double ymax = map.Extent.ymax + 2;
313 @R_944_5179@ double ymin = map.Extent.ymin - 2;
314  
315 @R_944_5179@ // 去除不在坐标范围内的点,先检查图层是否为空
316 @R_944_5179@ if (glayer != null)
317 @R_944_5179@ {
318 @R_944_5179@     int graphicCount = glayer.Graphics.Count;
319 @R_944_5179@     for (int i = 0; i < graphicCount; i++)
320 @R_944_5179@     {
321 @R_944_5179@@R_944_5179@  // 判断经度,纬度
322 @R_944_5179@@R_944_5179@  if (!((glayer.Graphics[i].Geometry.Extent.XMax < xMax && glayer.Graphics[i].Geometry.Extent.XMax > xMin)
323 @R_944_5179@@R_944_5179@      && (glayer.Graphics[i].Geometry.Extent.ymax < ymax && glayer.Graphics[i].Geometry.Extent.ymax > ymin)))
324 @R_944_5179@@R_944_5179@  {
325 @R_944_5179@@R_944_5179@      // 将点在地图上移除,并放在缓存中
326 @R_944_5179@@R_944_5179@      cacheGraphic.Add(glayer.Graphics[i]);
327 @R_944_5179@@R_944_5179@      glayer.Graphics.Remove(glayer.Graphics[i]);
328 @R_944_5179@@R_944_5179@      graphicCount--;   // 当从集合中移除元素时应该把 graphicCount 减1
329 @R_944_5179@@R_944_5179@      i--;@R_944_5179@       // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
330 @R_944_5179@@R_944_5179@  }
331 @R_944_5179@     } // i
332 @R_944_5179@ }
333  
334 @R_944_5179@ // 检查缓存是否为空,并将点绘制到图形上
335 @R_944_5179@ if (cacheGraphic != null)
336 @R_944_5179@ {
337 @R_944_5179@     int count = cacheGraphic.Count;
338 @R_944_5179@     for (int i = 0; i < count; i++)
339 @R_944_5179@     {
340 @R_944_5179@@R_944_5179@  // 判断经度,纬度
341 @R_944_5179@@R_944_5179@  if ((cacheGraphic[i].Geometry.Extent.XMax < xMax && cacheGraphic[i].Geometry.Extent.XMax > xMin)
342 @R_944_5179@@R_944_5179@      && (cacheGraphic[i].Geometry.Extent.ymax < ymax && cacheGraphic[i].Geometry.Extent.ymax > ymin))
343 @R_944_5179@@R_944_5179@  {
344 @R_944_5179@@R_944_5179@      // 运行到此则该点在目前地图范围内,将该点加入到地图中
345 @R_944_5179@@R_944_5179@      glayer.Graphics.Add(cacheGraphic[i]);
346 @R_944_5179@@R_944_5179@      cacheGraphic.Remove(cacheGraphic[i]);
347 @R_944_5179@@R_944_5179@      count--;    // 当从集合中移除元素时应该把 count 减1
348 @R_944_5179@@R_944_5179@      i--;@R_944_5179@ // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
349 @R_944_5179@@R_944_5179@      conTinue;
350 @R_944_5179@@R_944_5179@  }
351 @R_944_5179@     }
352 @R_944_5179@ }
353     }
354  
355     /// <sum@R_262_11035@>
356     /// 将所有元素画到地图上
357     /// </sum@R_262_11035@>
358     /// <param name="eLayer"></param>
359     /// <param name="cacheElement"></param>
360     private static void DrawAllGraphics(GraphicsLayer eLayer,List<Graphic> cacheGraphiC)
361     {
362 @R_944_5179@ if (eLayer != null)
363 @R_944_5179@ {
364 @R_944_5179@     foreach (Graphic item in cacheGraphiC)
365 @R_944_5179@     {
366 @R_944_5179@@R_944_5179@  eLayer.Graphics.Add(item);
367 @R_944_5179@     }
368 @R_944_5179@ }
369     }
370 }

 

 

今天把 Gismap 这个类都写出来了也为了我写下一篇文章做准备吧!后面会写一篇动态加载数据点的文章!因为当大批量点(2000)左右加载到地图上的时候,

就会非常的卡,基本都动不了,所以我们要动态去加载这些点。

大佬总结

以上是大佬教程为你收集整理的ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(三)--绘制点、线、圆,显示提示信息全部内容,希望文章能够帮你解决ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(三)--绘制点、线、圆,显示提示信息所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:apiarcgisgissilverlight信息地图提示显示线绘制
猜你在找的silverlight相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap