073 /// <summary> 074 /// 将图层数组全部从 map 中移除 075 /// </summary> 076 /// <param name="map">表示一张 ArcGis 地图</param> 077 /// <param name="layers">表示地图层的数组</param> 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> 090 /// <param name="map"></param> 091 /// <param name="ID"></param> 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> 114 /// <param name="map">表示一张 ArcGis 地图</param> 115 /// <param name="layers">表示地图层的数组</param> 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> 129 /// <param name="myMap"></param> 130 /// <param name="ID">ID号</param> 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> 162 /// <param name="map">表示一张 ArcGis 地图</param> 163 /// <param name="layers">表示地图层的数组</param> 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> 179 /// <param name="map">表示一张 ArcGis 地图</param> 180 /// <param name="layers">表示地图层的数组</param> 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> 193 /// <param name="eLayer"></param> 194 /// <param name="image"></param> 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> 209 /// <param name="show">隐藏或显示</param> 210 /// <param name="layers">层</param> 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> 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 // 以下四个变量分别表示地图的四个边 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> 284 /// <param name="eLayer"></param> 285 /// <param name="cacheElement"></param> 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> 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 // 以下四个变量分别表示地图的四个边 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> 358 /// <param name="eLayer"></param> 359 /// <param name="cacheElement"></param> 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)左右加载到地图上的时候 |
ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(三.3)
最新推荐文章于 2013-12-27 14:09:48 发布
2011-09-05 20:39