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
OK,今天又有空来写点啦,这个例子自己不想拉的太长了,所以这节多写点东西,我尽量把东西都介绍全面,有不懂的可以留言~
有空大家共同讨论。
好进入正题,如今天标题所示,我们先来看画点,线,圆吧!
01 |
/// <summary> |
02 |
/// 绘制界面上的点和线 |
03 |
/// </summary> |
07 |
public void DrawAnimationCompleted(Map myMap,List<Graphic> point,ESRI.ArcGIS.Client.Geometry.PointCollection pointLine)
|
08 |
{ |
13 |
linesymbol.Width = 1;
|
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 |
/// <summary> |
02 |
/// 在地图上绘制圆 |
03 |
/// </summary> |
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 |
drawCircleLayer.Children.Add(container);
|
16 |
container.Opacity = 0.5;
|
17 |
container.SetValue(ElementLayer.EnvelopeProperty, new Envelope(myMap.Extent.XMax,myMap.Extent.YMax,myMap.Extent.XMin,myMap.Extent.YMin));
|
18 |
} |
19 |
21 |
Convert.Todouble(pt.Y)));
|
22 |
23 |
Point pt7 = myMap.MapToScreen( new MapPoint((Convert.Todouble(pt.X) + circleKm * kmToEN),
|
24 |
Convert.Todouble(pt.Y)));
|
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);
|
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
{ GisMap.DeleteLayersToMap(myMap, "WindCircleLayer" ); }
|
|
ElementLayer circleLayer = new ElementLayer();
|
circleLayer.ID = "WindCircleLayer" ;
|
|
Canvas circleCanvas = new Canvas();
|
|
Graphic tipGraphic = sender as Graphic;
|
|
if (Convert.Todouble(tipGraphic.Attributes[ "WindCircle7" ]) != 0)
|
{
|
Color color = new Color();
|
color.A = 255;
|
color.R = 153;
|
color.G = 105;
|
color.B = 192;
|
|
DrawEllipse(myMap,circleCanvas, new MapPoint(Convert.Todouble(tipGraphic.Attributes[ "Longitude" ]),
|
Convert.Todouble(tipGraphic.Attributes[ "Latitude" ])), ref circleLayer,
|
Convert.Todouble(300),color,Colors.Blue);
|
|
}
|
|
if (Convert.Todouble(tipGraphic.Attributes[ "WindCircle10" ]) != 0)
|
{
|
Color color = new Color();
|
color.A = 255;
|
color.R = 111;
|
color.G = 91;
|
color.B = 171;
|
|
this .DrawEllipse(myMap,
|
Convert.Todouble(tipGraphic.Attributes[ "WindCircle10" ]),Colors.Blue);
|
}
|
|
|
GisMap.AddLayersToMap(myMap, new ElementLayer[] { circleLayer });
|
}
|
这里的sender是一个Gis元素 Graphic,根据我的WebService 取到的实体后我把这个点加上了Attributes,一系列属性,所以在上面的代码可以看到tipGraphic.Attributes["WindCircle10"],
下面的代码就是在我从WebService取到实体后做添加点的代码:
/// <summary> |
/// 添加鼠标移入、移出事件 |
/// </summary> |
{ |
SimpleMarkerSymbol symbol = new SimpleMarkerSymbol();
|
Color color = new Color();
|
color.A = 255;
|
|
if (Convert.Todouble(model.WS) <= 17.1)
|
{ |
color.R = 0;
|
color.G = 254;
|
color.B = 223;
|
symbol.Color = new SolidColorBrush(color);
|
} |
{ |
color.R = 254;
|
color.G = 243;
|
color.B = 0;
|
symbol.Color = new SolidColorBrush(color);
|
} |
{ |
color.R = 254;
|
color.G = 144;
|
color.B = 44;
|
symbol.Color = new SolidColorBrush(color);
|
} |
{ |
color.R = 254;
|
color.G = 4;
|
color.B = 4; symbol.Color = new SolidColorBrush(color);
|
} |
{ |
color.R = 254;
|
color.G = 58;
|
color.B = 163; symbol.Color = new SolidColorBrush(color);
|
} |
else if (Convert.Todouble(model.WS) > 50.9)
|
{ |
color.R = 174;
|
color.G = 0;
|
color.B = 217; symbol.Color = new SolidColorBrush(color);
|
} |
symbol.Size = 10;
|
if (i == 0)
|
{ |
symbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Square;
|
} |
else
|
{ |
symbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle;
|
} |
pointParam.Add( new Graphic()
|
{ |
Geometry = new MapPoint(model.Longitude,model.Latitude),
|
Symbol = symbol
|
});
|
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);
|
} |
我们先看下Xmal中的代码:
< Canvas x:Name = "typhoonPointInfoCanvas" Visibility = "Visible" Height = "188" HorizontalAlignment = "Left" 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" >
|
< TextBlock x:Name = "typhoonNameTextBlock" Height = "20" Text = "名称:" Foreground = "White" @R_404_3981@ping = "Wrap" />
|
< TextBlock x:Name = "typhoonCollectionTimeTextBlock" Height = "20" Text = "时间:" Foreground = "White" @R_404_3981@ping = "Wrap" d:LayoutOverrides = "HorizontalAlignment" />
|
< TextBlock x:Name = "typhoonPositionTextBlock" Height = "20" Text = "位置:" Foreground = "White" @R_404_3981@ping = "Wrap" d:LayoutOverrides = "HorizontalAlignment" />
|
< TextBlock x:Name = "typhoonWSTextBlock" Height = "20" Text = "最大风速:" Foreground = "White" @R_404_3981@ping = "Wrap" d:LayoutOverrides = "HorizontalAlignment" />
|
< TextBlock x:Name = "typhoonPressureTextBlock" Height = "20" Text = "中心气压:" Foreground = "White" @R_404_3981@ping = "Wrap" d:LayoutOverrides = "HorizontalAlignment" />
|
< TextBlock x:Name = "typhoonCircle7TextBlock" Height = "20" Text = "7级风圈半径:" Foreground = "White" @R_404_3981@ping = "Wrap" d:LayoutOverrides = "HorizontalAlignment" />
|
< TextBlock x:Name = "typhoonCircle10TextBlock" Height = "20" Text = "10级风圈半径:" Foreground = "White" @R_404_3981@ping = "Wrap" d:LayoutOverrides = "HorizontalAlignment" />
|
</ StackPanel >
|
</ Canvas >
|
< BR >
|
看下c# 中的代码:
当我们添加那些点也就是 Graphic 的时候有这样一个事件MouseEventHandler
01 |
/// <summary> |
02 |
/// 绘制单条台风动画前的信息 |
03 |
/// </summary> |
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 |
{ |
17 |
AddPointToGraphic(e.Result[i],i,point);
|
18 |
} |
19 |
#endregion
|
20 |
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 |
<SPAN style= "FONT-SIZE: 14px" > item.MouseEnter += new MouseEventHandler(MainPage_MouseEnter); </SPAN>
|
1 |
item.MouseLeave += new MouseEventHandler(MainPage_DrawLine);
|
01 |
<DIV class =cnblogs_Highlighter><PRE class =brush:csharp> void MainPage_MouseEnter( object sender,MouseEventArgs e)
|
02 |
{
|
03 |
Graphic graphic = sender as Graphic;
|
04 |
Cursor = Cursors.Hand;
|
05 |
|
06 |
typhoonPointInfoCanvas.Visibility = Visibility.Visible;
|
07 |
|
08 |
Point pt = myMap.MapToScreen( new MapPoint(Convert.Todouble(graphic.Attributes[ "Longitude" ]),Convert.Todouble(graphic.Attributes[ "Latitude" ])));
|
09 |
|
11 |
|
13 |
typhoonCollectionTimeTextBlock.Text = "时间:" + graphic.Attributes[ "IssueTime" ].ToString();
|
14 |
typhoonPositionTextBlock.Text = "位置:" + graphic.Attributes[ "Longitude" ].ToString() + "°E," + graphic.Attributes[ "Latitude" ].ToString() + "°N" ; |
15 |
typhoonWSTextBlock.Text = "最大风速:" + graphic.Attributes[ "WS" ].ToString() + " m/s" ; |
16 |
typhoonPressureTextBlock.Text = "中心气压:" + graphic.Attributes[ "Pressure" ].ToString() + " hPa" ; |
17 |
typhoonCircle7TextBlock.Text = "7级风圈半径:" + graphic.Attributes[ "WindCircle7" ].ToString() + " km" ; |
18 |
typhoonCircle10TextBlock.Text = "10级风圈半径:" + graphic.Attributes[ "WindCircle10" ].ToString() + " km" ; |
19 |
|
20 |
circle.DrawEllipse7And10WindCircle(myMap,sender);
|
21 |
selectedGarphic = sender as Graphic;
|
22 |
}</PRE>
|
23 |
</DIV> |
GisMap是个静态类,以下是他的代码
01 |
/// <summary> |
02 |
/// ArcGis 调用类 |
03 |
/// 动态加载、显示隐藏层数据、加载层上的点等 |
04 |
/// 日期:2010-5-10 |
05 |
/// 作者:AngelSoft |
06 |
/// </summary> |
07 |
public static class GisMap
|
08 |
{ |
09 |
10 |
/// <summary>
|
11 |
/// 绘制所有的点到地图上
|
12 |
/// </summary>
|
15 |
public static void DrawSymbol(Graphicslayer glayer,List<Graphic> cacheGraphic)
|
16 |
{ |
17 |
if (glayer != null )
|
18 |
{
|
19 |
int graphicCount = cacheGraphic.Count;
|
20 |
for ( int i = 0; i < graphicCount; i++)
|
21 |
{
|
22 |
glayer.Graphics.Add(cacheGraphic[i]);
|
23 |
} // i
|
24 |
}
|
25 |
}
|
001 |
/// <summary>
|
002 |
/// 加载所有图层上的点
|
003 |
/// 动态绘制
|
004 |
/// 图层和点的对应关系要正确
|
005 |
/// 有几个图层就要有几个点集合
|
006 |
/// </summary>
|
010 |
public static void DrawLayers(Map map,Graphicslayer[] layers, params List<Graphic>[] graphicParam)
|
011 |
{ |
013 |
if (layers != null )
|
014 |
{
|
015 |
int length = layers.Length;
|
016 |
for ( int i = 0; i < length; i++)
|
017 |
{
|
018 |
if (layers[i] == null )
|
019 |
{
|
020 |
layers[i] = new Graphicslayer();
|
021 |
}
|
022 |
DynamicDrawSymbol(layers[i],graphicParam[i],map);
|
023 |
}
|
024 |
}
|
025 |
} |
026 |
027 |
028 |
/// <summary>
|
029 |
/// 加载所有图层上的点
|
030 |
/// 画所有点
|
031 |
/// 图层和点的对应关系要正确
|
032 |
/// 有几个图层就要有几个点集合
|
033 |
/// </summary>
|
038 |
{ |
040 |
if (layers != null )
|
041 |
{
|
042 |
int length = layers.Length;
|
043 |
for ( int i = 0; i < length; i++)
|
044 |
{
|
045 |
if (layers[i] == null )
|
046 |
{
|
047 |
layers[i] = new Graphicslayer();
|
048 |
}
|
049 |
DrawAllGraphics(layers[i],graphicParam[i]);
|
050 |
}
|
051 |
}
|
052 |
} |
053 |
054 |
055 |
056 |
/// <summary>
|
057 |
/// 隐藏或显示 ArcGis 层
|
058 |
/// </summary>
|
062 |
{ |
063 |
if (layers != null )
|
064 |
{
|
065 |
foreach (Graphicslayer item in layers)
|
066 |
{
|
067 |
item.Visible = show;
|
068 |
}
|
069 |
}
|
070 |
} |
071 |
072 |
073 |
/// <summary>
|
074 |
/// 将图层数组全部从 map 中移除
|
075 |
/// </summary>
|
078 |
public static void DeleteLayersToMap(Map map,Graphicslayer[] layers) |
079 |
{ |
080 |
// 逐个将数据移除
|
081 |
foreach (Graphicslayer item in layers)
|
082 |
{
|
083 |
map.Layers.Remove(item);
|
084 |
}
|
085 |
} |
086 |
087 |
/// <summary>
|
088 |
/// 根据 ID 号删除某层
|
089 |
/// </summary>
|
092 |
/// <returns></returns>
|
093 |
public static void DeleteLayersToMap(Map map, string [] ID)
|
094 |
{ |
095 |
int length = ID.Length;
|
096 |
097 |
for ( int i = 0; i < length; i++)
|
098 |
{
|
099 |
foreach (Layer item in map.Layers)
|
100 |
{
|
101 |
if (item.ID == ID[i])
|
102 |
{
|
103 |
map.Layers.Remove(item);
|
104 |
length--;
|
105 |
break ;
|
106 |
}
|
107 |
}
|
108 |
}
|
109 |
} |
110 |
111 |
/// <summary>
|
112 |
/// 将图层数组全部从 map 中移除
|
113 |
/// </summary>
|
116 |
public static void DeleteLayersToMap(Map map,ElementLayer[] layers) |
117 |
{ |
118 |
// 逐个将数据移除
|
119 |
foreach (ElementLayer item in layers)
|
120 |
{
|
121 |
map.Layers.Remove(item);
|
122 |
}
|
123 |
} |
124 |
125 |
126 |
/// <summary>
|
127 |
/// 删除地图上的某一层
|
128 |
/// </summary>
|
131 |
public static void DeleteLayersToMap(Map myMap, string ID)
|
132 |
{ |
133 |
int layers = myMap.Layers.Count;
|
134 |
for ( int i = 0; i < layers; i++)
|
135 |
{
|
136 |
if (myMap.Layers[i].ID == ID)
|
137 |
{
|
138 |
myMap.Layers.RemoveAt(i);
|
139 |
return ;
|
140 |
}
|
141 |
}
|
142 |
} |
143 |
144 |
145 |
public static bool LayerExist(Map myMap, string ID)
|
146 |
{ |
147 |
int layers = myMap.Layers.Count;
|
148 |
for ( int i = 0; i < layers; i++)
|
149 |
{
|
150 |
if (myMap.Layers[i].ID == ID)
|
151 |
{
|
152 |
return true ;
|
153 |
}
|
154 |
}
|
155 |
return false ;
|
156 |
} |
157 |
158 |
159 |
/// <summary>
|
160 |
/// 将图层数组全部添加到 map 中
|
161 |
/// </summary>
|
164 |
public static void AddLayersToMap(Map map,Graphicslayer[] layers) |
165 |
{ |
166 |
// 逐个将数据添加到当前地图中
|
167 |
foreach (Graphicslayer item in layers)
|
168 |
{
|
169 |
if (item != null )
|
170 |
{
|
171 |
map.Layers.Add(item);
|
172 |
}
|
173 |
}
|
174 |
} |
175 |
176 |
/// <summary>
|
177 |
/// 将图层数组全部添加到 map 中
|
178 |
/// </summary>
|
181 |
public static void AddLayersToMap(Map map,ElementLayer[] layers) |
182 |
{ |
183 |
// 逐个将数据添加到当前地图中
|
184 |
foreach (ElementLayer item in layers)
|
185 |
{
|
186 |
map.Layers.Add(item);
|
187 |
}
|
188 |
} |
189 |
190 |
/// <summary>
|
191 |
/// 绘制所有的点到地图上
|
192 |
/// </summary>
|
195 |
public static void AddImagetoElementLayer(ElementLayer eLayer,List<Image> image)
|
196 |
{ |
197 |
if (eLayer != null )
|
198 |
{
|
199 |
foreach (Image item in image)
|
200 |
{
|
201 |
eLayer.Children.Add(item);
|
202 |
}
|
203 |
}
|
204 |
} |
205 |
206 |
/// <summary>
|
207 |
/// 隐藏或显示 ArcGis 层
|
208 |
/// </summary>
|
211 |
public static void LayersVisibility( bool show, params ElementLayer[] layers)
|
212 |
{ |
213 |
if (layers != null )
|
214 |
{
|
215 |
foreach (ElementLayer item in layers)
|
216 |
{
|
217 |
item.Visible = show;
|
218 |
}
|
219 |
}
|
220 |
} |
221 |
222 |
/// <summary>
|
223 |
/// 动态加载图层
|
224 |
/// 使用 ElementLayer 层
|
225 |
/// </summary>
|
229 |
public static void DynamicDrawElementLayer(ElementLayer eLayer,List<UIElement> cacheElement,Map map)
|
230 |
{ |
231 |
// 以下四个变量分别表示地图的四个边
|
232 |
// 即最大经纬度和最小经纬度
|
233 |
// xMax最大经度,yMax最大纬度
|
234 |
double xMax = map.Extent.XMax + 2;
|
235 |
double xMin = map.Extent.XMin - 2;
|
236 |
double yMax = map.Extent.YMax + 2;
|
237 |
double yMin = map.Extent.YMin - 2;
|
238 |
239 |
// 去除不在坐标范围内的点,先检查图层是否为空
|
240 |
if (eLayer != null )
|
241 |
{
|
242 |
int graphicCount = eLayer.Children.Count;
|
243 |
for ( int i = 0; i < graphicCount; i++)
|
244 |
{
|
245 |
UIElement element = eLayer.Children[i];
|
246 |
|
247 |
// 判断经度,纬度
|
248 |
if (!(((element.GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.XMax < xMax && (element.GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.XMax > xMin)
|
249 |
&& ((element.GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.YMax < yMax && (element.GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.YMax > yMin)))
|
250 |
{
|
251 |
// 将点在地图上移除,并放在缓存中
|
252 |
cacheElement.Add(eLayer.Children[i]);
|
253 |
eLayer.Children.Remove(eLayer.Children[i]);
|
254 |
graphicCount--; // 当从集合中移除元素时应该把 graphicCount 减1
|
255 |
i--; // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
|
256 |
}
|
257 |
} // i
|
258 |
}
|
259 |
260 |
// 检查缓存是否为空,并将点绘制到图形上
|
261 |
if (cacheElement != null )
|
262 |
{
|
263 |
int count = cacheElement.Count;
|
264 |
for ( int i = 0; i < count; i++)
|
265 |
{
|
266 |
// 判断经度,纬度
|
267 |
if (((cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.XMax < xMax && (cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.XMax > xMin)
|
268 |
&& ((cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.YMax < yMax && (cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.YMax > yMin))
|
269 |
{
|
270 |
// 运行到此则该点在目前地图范围内,将该点加入到地图中
|
271 |
eLayer.Children.Add(cacheElement[i]);
|
272 |
cacheElement.Remove(cacheElement[i]);
|
273 |
count--; // 当从集合中移除元素时应该把 count 减1
|
274 |
i--; // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
|
275 |
continue ;
|
276 |
}
|
277 |
}
|
278 |
}
|
279 |
} |
280 |
281 |
/// <summary>
|
282 |
/// 将所有元素画到地图上
|
283 |
/// </summary>
|
286 |
public static void DrawAllUIElement(ElementLayer eLayer,List<UIElement> cacheElement)
|
287 |
{ |
288 |
if (eLayer != null )
|
289 |
{
|
290 |
foreach (UIElement item in cacheElement)
|
291 |
{
|
292 |
eLayer.Children.Add(item);
|
293 |
}
|
294 |
}
|
295 |
} |
296 |
297 |
/// <summary>
|
298 |
/// 动态的绘制图层
|
299 |
/// 当然地图移动到相应的坐标后绘制(保留原来的点,绘制新的数据)
|
300 |
/// 实现了无刷新绘制
|
301 |
/// </summary>
|
305 |
private static void DynamicDrawSymbol(Graphicslayer glayer,List<Graphic> cacheGraphic,Map map)
|
306 |
{ |
307 |
// 以下四个变量分别表示地图的四个边
|
308 |
// 即最大经纬度和最小经纬度
|
309 |
// xMax最大经度,yMax最大纬度
|
310 |
double xMax = map.Extent.XMax + 2;
|
311 |
double xMin = map.Extent.XMin - 2;
|
312 |
double yMax = map.Extent.YMax + 2;
|
313 |
double yMin = map.Extent.YMin - 2;
|
314 |
315 |
// 去除不在坐标范围内的点,先检查图层是否为空
|
316 |
if (glayer != null )
|
317 |
{
|
318 |
int graphicCount = glayer.Graphics.Count;
|
319 |
for ( int i = 0; i < graphicCount; i++)
|
320 |
{
|
321 |
// 判断经度,纬度
|
322 |
if (!((glayer.Graphics[i].Geometry.Extent.XMax < xMax && glayer.Graphics[i].Geometry.Extent.XMax > xMin)
|
323 |
&& (glayer.Graphics[i].Geometry.Extent.YMax < yMax && glayer.Graphics[i].Geometry.Extent.YMax > yMin)))
|
324 |
{
|
325 |
// 将点在地图上移除,并放在缓存中
|
326 |
cacheGraphic.Add(glayer.Graphics[i]);
|
327 |
glayer.Graphics.Remove(glayer.Graphics[i]);
|
328 |
graphicCount--; // 当从集合中移除元素时应该把 graphicCount 减1
|
329 |
i--; // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
|
330 |
}
|
331 |
} // i
|
332 |
}
|
333 |
334 |
// 检查缓存是否为空,并将点绘制到图形上
|
335 |
if (cacheGraphic != null )
|
336 |
{
|
337 |
int count = cacheGraphic.Count;
|
338 |
for ( int i = 0; i < count; i++)
|
339 |
{
|
340 |
// 判断经度,纬度
|
341 |
if ((cacheGraphic[i].Geometry.Extent.XMax < xMax && cacheGraphic[i].Geometry.Extent.XMax > xMin)
|
342 |
&& (cacheGraphic[i].Geometry.Extent.YMax < yMax && cacheGraphic[i].Geometry.Extent.YMax > yMin))
|
343 |
{
|
344 |
// 运行到此则该点在目前地图范围内,将该点加入到地图中
|
345 |
glayer.Graphics.Add(cacheGraphic[i]);
|
346 |
cacheGraphic.Remove(cacheGraphic[i]);
|
347 |
count--; // 当从集合中移除元素时应该把 count 减1
|
348 |
i--; // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
|
349 |
continue ;
|
350 |
}
|
351 |
}
|
352 |
}
|
353 |
} |
354 |
355 |
/// <summary>
|
356 |
/// 将所有元素画到地图上
|
357 |
/// </summary>
|
360 |
private static void DrawAllGraphics(Graphicslayer eLayer,List<Graphic> cacheGraphic)
|
361 |
{ |
362 |
if (eLayer != null )
|
363 |
{
|
364 |
foreach (Graphic item in cacheGraphic)
|
365 |
{
|
366 |
eLayer.Graphics.Add(item);
|
367 |
}
|
368 |
}
|
369 |
} |
370 |
} |
今天把 GisMap 这个类都写出来了也为了我写下一篇文章做准备吧!后面会写一篇动态加载数据点的文章!因为当大批量点(2000)左右加载到地图上的时候,
就会非常的卡,基本都动不了,所以我们要动态去加载这些点。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。