大佬教程收集整理的这篇文章主要介绍了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();
|
15 |
16 |
// 画线到图层上并绘制到地图上
|
19 |
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 |
{ |
17 |
@R_944_5179@ container.SETVALue(ElementLayer.EnvelopeProperty, new Envelope(mymap.Extent.XMax,mymap.Extent.ymax,mymap.Extent.XMin,mymap.Extent.ymin));
|
18 |
} |
19 |
22 |
23 |
Point pt7 = mymap.MapToScreen( new @H_551_170@mapPoint((Convert.ToDouble(pt.X) + circleKm * kmToEN),
|
25 |
26 |
Ellipse ellipse7 = new Ellipse();
|
27 |
ellipse7.Width = (pt7.X - ptFirst.X) * 2;
|
28 |
ellipse7.Height = ellipse7.Width;
|
31 |
ellipse7.Fill = new SolidColorBrush(color);
|
35 |
36 |
container.Children.Add(ellipse7);
|
37 |
container.IsHitTestVisible = false ; |
39 |
} |
这是一个画圆的方法,需要地图类,点,Canvas容器,Gis 的地图层ElementLayer和color
这里的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)
|
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.R = 254;
|
@R_944_5179@ color.G = 243;
|
} |
@R_944_5179@ color.R = 254;
|
@R_944_5179@ color.G = 144;
|
} |
@R_944_5179@ color.R = 254;
|
@R_944_5179@ color.G = 4;
|
} |
@R_944_5179@ color.R = 254;
|
@R_944_5179@ color.G = 58;
|
} |
@R_944_5179@ color.R = 174;
|
@R_944_5179@ color.G = 0;
|
} |
if (i == 0)
|
} |
else
|
} |
pointParam.Add( new Graphic()
|
});
|
} |
@H_607_34@
@H_607_34@
@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}" />
|
@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 >
|
< BR >
|
看下c# 中的代码:
当我们添加那些点也就是 Graphic 的时候有这样一个事件MouseEventHandler
@H_607_34@
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 |
{ |
14 |
point = new List<Graphic>();
|
15 |
for ( int i = 0; i < length; i++)
|
16 |
{ |
18 |
} |
19 |
#endregion
|
20 |
23 |
AddLineToMap(e.Result.ToList(),length,pointLinE);
|
24 |
25 |
// 显示点层
|
28 |
} |
@H_62_4 673@ @H_725_4674@
01 |
<DIV class =cnblogs_Highlighter><PRE class =brush:csharp>@R_944_5179@ void @H_551_170@mainPage_MouseEnter(object sender,MouseEventArgs E)
|
05 |
|
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 |
|
11 |
|
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" ; |
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 |
|
22 |
@R_944_5179@ }</PRE>
|
23 |
</DIV> |
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>
|
16 |
{ |
19 |
@R_944_5179@ int graphicCount = cacheGraphic.Count;
|
20 |
@R_944_5179@ for ( int i = 0; i < graphicCount; 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 |
{ |
016 |
@R_944_5179@ for ( int i = 0; i < length; i++)
|
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 |
{ |
043 |
@R_944_5179@ for ( int i = 0; i < length; i++)
|
050 |
@R_944_5179@ }
|
051 |
@R_944_5179@ }
|
052 |
} |
053 |
054 |
055 |
056 |
/// <sum@R_262_11035@>
|
057 |
/// 隐藏或显示 ArcGis 层
|
059 |
/// <param name="show">隐藏或显示</param>
|
060 |
/// <param name="layers">层</param>
|
061 |
public static void LayersVisibility( bool show, params GraphicsLayer[] layers)
|
062 |
{ |
065 |
@R_944_5179@ foreach (GraphicsLayer item in layers)
|
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)
|
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>
|
094 |
{ |
095 |
@R_944_5179@ int length = ID.Length;
|
096 |
097 |
@R_944_5179@ for ( int i = 0; i < length; i++)
|
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)
|
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>
|
132 |
{ |
134 |
@R_944_5179@ for ( int i = 0; i < layers; i++)
|
140 |
@R_944_5179@ }
|
141 |
@R_944_5179@ }
|
142 |
} |
143 |
144 |
146 |
{ |
148 |
@R_944_5179@ for ( int i = 0; i < layers; i++)
|
153 |
@R_944_5179@ }
|
154 |
@R_944_5179@ }
|
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 |
{ |
167 |
@R_944_5179@ foreach (GraphicsLayer item in layers)
|
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 |
{ |
184 |
@R_944_5179@ foreach (ElementLayer item in layers)
|
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>
|
196 |
{ |
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 |
{ |
215 |
@R_944_5179@ foreach (ElementLayer item in layers)
|
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@ // 即最大经纬度和最小经纬度
|
234 |
@R_944_5179@ double xMax = map.Extent.XMax + 2;
|
235 |
@R_944_5179@ double xMin = map.Extent.XMin - 2;
|
238 |
242 |
@R_944_5179@ int graphicCount = eLayer.Children.Count;
|
243 |
@R_944_5179@ for ( int i = 0; i < graphicCount; i++)
|
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)))
|
257 |
@R_944_5179@ } // i
|
258 |
@R_944_5179@ }
|
259 |
260 |
@R_944_5179@ // 检查缓存是否为空,并将点绘制到图形上
|
263 |
@R_944_5179@ int count = cacheElement.Count;
|
264 |
@R_944_5179@ for ( int i = 0; i < count; i++)
|
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))
|
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 |
{ |
290 |
@R_944_5179@ foreach (UIElement item in cacheElement)
|
293 |
@R_944_5179@ }
|
294 |
@R_944_5179@ }
|
295 |
} |
296 |
297 |
/// <sum@R_262_11035@>
|
298 |
/// 动态的绘制图层
|
299 |
/// 当然地图移动到相应的坐标后绘制(保留原来的点,绘制新的数据)
|
300 |
/// 实现了无刷新绘制
|
302 |
/// <param name="glayer">表示地图上的层</param>
|
303 |
/// <param name="cacheGraphic">存放 Graphics 的缓存</param>
|
304 |
/// <param name="map">表示一张 ArcGis 地图</param>
|
306 |
{ |
307 |
@R_944_5179@ // 以下四个变量分别表示地图的四个边
|
308 |
@R_944_5179@ // 即最大经纬度和最小经纬度
|
310 |
@R_944_5179@ double xMax = map.Extent.XMax + 2;
|
311 |
@R_944_5179@ double xMin = map.Extent.XMin - 2;
|
314 |
319 |
@R_944_5179@ for ( int i = 0; i < graphicCount; i++)
|
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)))
|
331 |
@R_944_5179@ } // i
|
332 |
@R_944_5179@ }
|
333 |
334 |
@R_944_5179@ // 检查缓存是否为空,并将点绘制到图形上
|
337 |
@R_944_5179@ int count = cacheGraphic.Count;
|
338 |
@R_944_5179@ for ( int i = 0; i < count; i++)
|
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))
|
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 |
{ |
367 |
@R_944_5179@ }
|
368 |
@R_944_5179@ }
|
369 |
} |
370 |
} |
今天把 Gismap 这个类都写出来了也为了我写下一篇文章做准备吧!后面会写一篇动态加载数据点的文章!因为当大批量点(2000)左右加载到地图上的时候,
就会非常的卡,基本都动不了,所以我们要动态去加载这些点。
以上是大佬教程为你收集整理的ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(三)--绘制点、线、圆,显示提示信息全部内容,希望文章能够帮你解决ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(三)--绘制点、线、圆,显示提示信息所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。