ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等--绘制点、线、圆,显示提示信息
ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等--绘制点、线、圆,显示提示信息
- /// <summary>
- /// 绘制界面上的点和线
- /// </summary>
- /// <param name="myMap"></param>
- /// <param name="point"></param>
- /// <param name="pointLine"></param>
- public void DrawAnimationCompleted(Map myMap, List<Graphic> point,ESRI.ArcGIS.Client.Geometry.PointCollection pointLine)
- {
- GraphicsLayer gPointLayer = new GraphicsLayer();
- GraphicsLayer lineLayer = new GraphicsLayer();
- SimpleLineSymbol lineSymbol = new SimpleLineSymbol();
- lineSymbol.Color = new SolidColorBrush(Colors.Brown);
- lineSymbol.Width = 1;
- lineSymbol.Style = SimpleLineSymbol.LineStyle.Solid;
- // 画线到图层上并绘制到地图上
- GisMap.AddLayersToMap(myMap, new GraphicsLayer[] { lineLayer });
- GisLine.DrawLineOnMap(pointLine, lineLayer, lineSymbol);
- GisMap.DrawAllLayers(myMap, new GraphicsLayer[] { gPointLayer }, point);
- GisMap.AddLayersToMap(myMap, new GraphicsLayer[] { gPointLayer });
- }
好,看一下如何画圆吧。
- /// <summary>
- /// 在地图上绘制圆
- /// </summary>
- /// <param name="myMap">地图</param>
- /// <param name="container">绘制容器</param>
- /// <param name="pt">要绘制的点</param>
- /// <param name="drawCircleLayer"></param>
- /// <param name="circleKm">直径</param>
- /// <param name="color">填充色</param>
- /// <param name="ellipseStroke">边框色</param>
- public void DrawEllipse(Map myMap, Canvas container, MapPoint pt,ref ElementLayer drawCircleLayer, double circleKm,Color color,Color ellipseStroke)
- {
- if (!drawCircleLayer.Children.Contains(container))
- {
- drawCircleLayer.Children.Add(container);
- container.Opacity = 0.5;
- container.SetValue(ElementLayer.EnvelopeProperty, new Envelope(myMap.Extent.XMax, myMap.Extent.YMax, myMap.Extent.XMin, myMap.Extent.YMin));
- }
- Point ptFirst = myMap.MapToScreen(new MapPoint(Convert.ToDouble(pt.X),
- Convert.ToDouble(pt.Y)));
- Point pt7 = myMap.MapToScreen(new MapPoint((Convert.ToDouble(pt.X) + circleKm * kmToEN),
- Convert.ToDouble(pt.Y)));
- Ellipse ellipse7 = new Ellipse();
- ellipse7.Width = (pt7.X - ptFirst.X) * 2;
- ellipse7.Height = ellipse7.Width;
- ellipse7.StrokeThickness = 1;
- ellipse7.Stroke = new SolidColorBrush(ellipseStroke);
- ellipse7.Fill = new SolidColorBrush(color);
- Canvas.SetLeft(ellipse7, ptFirst.X - ellipse7.Width / 2);
- Canvas.SetTop(ellipse7, ptFirst.Y - ellipse7.Width / 2);
- ellipse7.Opacity = 0.5;
- container.Children.Add(ellipse7);
- container.IsHitTestVisible = false;
- container.SetValue(Canvas.ZIndexProperty, -10);
- }
这是一个画圆的方法,需要地图类,点,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, circleCanvas, new MapPoint(Convert.ToDouble(tipGraphic.Attributes["Longitude"]),
- Convert.ToDouble(tipGraphic.Attributes["Latitude"])), ref circleLayer,
- Convert.ToDouble(tipGraphic.Attributes["WindCircle10"]), color, Colors.Blue);
- }
- GisMap.AddLayersToMap(myMap, new ElementLayer[] { circleLayer });
- }
这里的sender是一个Gis元素 Graphic,根据我的WebService 取到的实体后我把这个点加上了Attributes,一系列属性,所以在上面的代码可以看到tipGraphic.Attributes["WindCircle10"],
下面的代码就是在我从WebService取到实体后做添加点的代码:
- /// <summary>
- /// 添加台风点代码
- /// 添加鼠标移入、移出事件
- /// </summary>
- /// <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)
- {
- color.R = 0;
- color.G = 254;
- color.B = 223;
- symbol.Color = new SolidColorBrush(color);
- }
- else if (Convert.ToDouble(model.WS) > 17.1 && Convert.ToDouble(model.WS) <= 24.4)
- {
- color.R = 254;
- color.G = 243;
- color.B = 0;
- symbol.Color = new SolidColorBrush(color);
- }
- else if (Convert.ToDouble(model.WS) > 24.4 && Convert.ToDouble(model.WS) <= 32.6)
- {
- color.R = 254;
- color.G = 144;
- color.B = 44;
- symbol.Color = new SolidColorBrush(color);
- }
- else if (Convert.ToDouble(model.WS) > 32.6 && Convert.ToDouble(model.WS) <= 41.4)
- {
- color.R = 254;
- color.G = 4;
- color.B = 4; symbol.Color = new SolidColorBrush(color);
- }
- else if (Convert.ToDouble(model.WS) > 41.4 && Convert.ToDouble(model.WS) <= 50.9)
- {
- 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("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);
- }
信息提示功能如图:
我们先看下Xmal中的代码:
- <Canvas x:Name="typhoonPointInfoCanvas" Visibility="Visible" Height="188" HorizontalAlignment="Left" Margin="0,-272,0,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" TextWrapping="Wrap"/>
- <TextBlock x:Name="typhoonCollectionTimeTextBlock" Height="20" Text="时间:" Foreground="White" TextWrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
- <TextBlock x:Name="typhoonPositionTextBlock" Height="20" Text="位置:" Foreground="White" TextWrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
- <TextBlock x:Name="typhoonWSTextBlock" Height="20" Text="最大风速:" Foreground="White" TextWrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
- <TextBlock x:Name="typhoonPressureTextBlock" Height="20" Text="中心气压:" Foreground="White" TextWrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
- <TextBlock x:Name="typhoonCircle7TextBlock" Height="20" Text="7级风圈半径:" Foreground="White" TextWrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
- <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
看下c# 中的代码:
当我们添加那些点也就是 Graphic 的时候有这样一个事件MouseEventHandler
- // 添加点和线,先显示点层,动画结束后显示线层
- mapDraw.DrawLineAndPoint(ref point, myMap, gLayer, ref pointLine, e, length);
- // 添加点事件
- foreach (Graphic item in point)
- {
- item.MouseEnter += new MouseEventHandler(MainPage_MouseEnter);
- item.MouseLeave += new MouseEventHandler(MainPage_DrawLine);
- }
- /// <summary>
- /// 绘制单条台风动画前的信息
- /// </summary>
- /// <param name="point"></param>
- /// <param name="myMap"></param>
- /// <param name="gLayer"></param>
- /// <param name="pointLine"></param>
- /// <param name="e"></param>
- /// <param name="length"></param>
- public void DrawLineAndPoint(ref List<Graphic> point,Map myMap,GraphicsLayer gLayer,
- ref ESRI.ArcGIS.Client.Geometry.PointCollection pointLine, GetTyphoonsCompletedEventArgs e, int length)
- {
- #region 添加点代码
- point = new List<Graphic>();
- for (int i = 0; i < length; i++)
- {
- AddPointToGraphic(e.Result[i], i, point);
- }
- #endregion
- // 添加线的代码
- pointLine = new ESRI.ArcGIS.Client.Geometry.PointCollection();
- AddLineToMap(e.Result.ToList(), length, pointLine);
- // 显示点层
- GisMap.DrawAllLayers(myMap, new GraphicsLayer[] { gLayer }, point);
- GisMap.AddLayersToMap(myMap, new GraphicsLayer[] { gLayer });
- }
AddPointToGraphic这个方法就是图片上面的那段代码
<SPAN style="FONT-SIZE: 14px"
> item.MouseEnter +=
new
MouseEventHandler(MainPage_MouseEnter); </SPAN>
item.MouseLeave +=
new
MouseEventHandler(MainPage_DrawLine);
这两段代码就是我们添加鼠标移入和移出事件了,我们看下移入事件:
- <DIV class=cnblogs_Highlighter><PRE class=brush:csharp> void MainPage_MouseEnter(object sender, MouseEventArgs e)
- {
- Graphic graphic = sender as Graphic;
- Cursor = Cursors.Hand;
- typhoonPointInfoCanvas.Visibility = Visibility.Visible;
- Point pt = myMap.MapToScreen(new MapPoint(Convert.ToDouble(graphic.Attributes["Longitude"]), Convert.ToDouble(graphic.Attributes["Latitude"])));
- typhoonPointInfoCanvas.SetValue(Grid.MarginProperty, new Thickness(pt.X, pt.Y, 0, 0));
- typhoonNameTextBlock.Text = "台风:" + graphic.Attributes["TyphoonName"].ToString();
- typhoonCollectionTimeTextBlock.Text = "时间:" + graphic.Attributes["IssueTime"].ToString();
- typhoonPositionTextBlock.Text = "位置:" + graphic.Attributes["Longitude"].ToString() + "°E," + graphic.Attributes["Latitude"].ToString() + "°N";
- typhoonWSTextBlock.Text = "最大风速:" + graphic.Attributes["WS"].ToString() + " m/s";
- typhoonPressureTextBlock.Text = "中心气压:" + graphic.Attributes["Pressure"].ToString() + " hPa";
- typhoonCircle7TextBlock.Text = "7级风圈半径:" + graphic.Attributes["WindCircle7"].ToString() + " km";
- typhoonCircle10TextBlock.Text = "10级风圈半径:" + graphic.Attributes["WindCircle10"].ToString() + " km";
- circle.DrawEllipse7And10WindCircle(myMap, sender);
- selectedGarphic = sender as Graphic;
- }</PRE>
- </DIV>
我们看到在显示信息的同时我们又把圆画了上去<SPAN style="FONT-SIZE: 14px">DrawEllipse7And10WindCircle()这个函数</SPAN>
GisMap是个静态类,以下是他的代码
- /// <summary>
- /// ArcGis 调用类
- /// 动态加载、显示隐藏层数据、加载层上的点等
- /// 日期:2010-5-10
- /// 作者:AngelSoft
- /// </summary>
- public static class GisMap
- {
- /// <summary>
- /// 绘制所有的点到地图上
- /// </summary>
- /// <param name="glayer"></param>
- /// <param name="cacheGraphic"></param>
- public static void DrawSymbol(GraphicsLayer glayer, List<Graphic> cacheGraphic)
- {
- if (glayer != null)
- {
- int graphicCount = cacheGraphic.Count;
- for (int i = 0; i < graphicCount; i++)
- {
- glayer.Graphics.Add(cacheGraphic[i]);
- } // i
- }
- }
- /// <summary>
- /// 加载所有图层上的点
- /// 动态绘制
- /// 图层和点的对应关系要正确
- /// 有几个图层就要有几个点集合
- /// </summary>
- /// <param name="map">ArcGis 地图变量</param>
- /// <param name="layers">GraphicLayer 层数组</param>
- /// <param name="graphicParam">Graphic 点数组</param>
- public static void DrawLayers(Map map, GraphicsLayer[] layers, params List<Graphic>[] graphicParam)
- {
- // 计算要绘制的层数并一层一层的绘制(调用动态绘制方法)
- if (layers != null)
- {
- int length = layers.Length;
- for (int i = 0; i < length; i++)
- {
- if (layers[i] == null)
- {
- layers[i] = new GraphicsLayer();
- }
- DynamicDrawSymbol(layers[i], graphicParam[i], map);
- }
- }
- }
- /// <summary>
- /// 加载所有图层上的点
- /// 画所有点
- /// 图层和点的对应关系要正确
- /// 有几个图层就要有几个点集合
- /// </summary>
- /// <param name="map">ArcGis 地图变量</param>
- /// <param name="layers">GraphicLayer 层数组</param>
- /// <param name="graphicParam">Graphic 点数组</param>
- public static void DrawAllLayers(Map map, GraphicsLayer[] layers, params List<Graphic>[] graphicParam)
- {
- // 计算要绘制的层数并一层一层的绘制(调用动态绘制方法)
- if (layers != null)
- {
- int length = layers.Length;
- for (int i = 0; i < length; i++)
- {
- if (layers[i] == null)
- {
- layers[i] = new GraphicsLayer();
- }
- DrawAllGraphics(layers[i], graphicParam[i]);
- }
- }
- }
- /// <summary>
- /// 隐藏或显示 ArcGis 层
- /// </summary>
- /// <param name="show">隐藏或显示</param>
- /// <param name="layers">层</param>
- public static void LayersVisibility(bool show, params GraphicsLayer[] layers)
- {
- if (layers != null)
- {
- foreach (GraphicsLayer item in layers)
- {
- item.Visible = show;
- }
- }
- }
- /// <summary>
- /// 将图层数组全部从 map 中移除
- /// </summary>
- /// <param name="map">表示一张 ArcGis 地图</param>
- /// <param name="layers">表示地图层的数组</param>
- public static void DeleteLayersToMap(Map map, GraphicsLayer[] layers)
- {
- // 逐个将数据移除
- foreach (GraphicsLayer item in layers)
- {
- map.Layers.Remove(item);
- }
- }
- /// <summary>
- /// 根据 ID 号删除某层
- /// </summary>
- /// <param name="map"></param>
- /// <param name="ID"></param>
- /// <returns></returns>
- public static void DeleteLayersToMap(Map map, string[] ID)
- {
- int length = ID.Length;
- for (int i = 0; i < length; i++)
- {
- foreach (Layer item in map.Layers)
- {
- if (item.ID == ID[i])
- {
- map.Layers.Remove(item);
- length--;
- break;
- }
- }
- }
- }
- /// <summary>
- /// 将图层数组全部从 map 中移除
- /// </summary>
- /// <param name="map">表示一张 ArcGis 地图</param>
- /// <param name="layers">表示地图层的数组</param>
- public static void DeleteLayersToMap(Map map, ElementLayer[] layers)
- {
- // 逐个将数据移除
- foreach (ElementLayer item in layers)
- {
- map.Layers.Remove(item);
- }
- }
- /// <summary>
- /// 删除地图上的某一层
- /// </summary>
- /// <param name="myMap"></param>
- /// <param name="ID">ID号</param>
- public static void DeleteLayersToMap(Map myMap, string ID)
- {
- int layers = myMap.Layers.Count;
- for (int i = 0; i < layers; i++)
- {
- if (myMap.Layers[i].ID == ID)
- {
- myMap.Layers.RemoveAt(i);
- return;
- }
- }
- }
- public static bool LayerExist(Map myMap, string ID)
- {
- int layers = myMap.Layers.Count;
- for (int i = 0; i < layers; i++)
- {
- if (myMap.Layers[i].ID == ID)
- {
- return true;
- }
- }
- return false;
- }
- /// <summary>
- /// 将图层数组全部添加到 map 中
- /// </summary>
- /// <param name="map">表示一张 ArcGis 地图</param>
- /// <param name="layers">表示地图层的数组</param>
- public static void AddLayersToMap(Map map, GraphicsLayer[] layers)
- {
- // 逐个将数据添加到当前地图中
- foreach (GraphicsLayer item in layers)
- {
- if (item != null)
- {
- map.Layers.Add(item);
- }
- }
- }
- /// <summary>
- /// 将图层数组全部添加到 map 中
- /// </summary>
- /// <param name="map">表示一张 ArcGis 地图</param>
- /// <param name="layers">表示地图层的数组</param>
- public static void AddLayersToMap(Map map, ElementLayer[] layers)
- {
- // 逐个将数据添加到当前地图中
- foreach (ElementLayer item in layers)
- {
- map.Layers.Add(item);
- }
- }
- /// <summary>
- /// 绘制所有的点到地图上
- /// </summary>
- /// <param name="eLayer"></param>
- /// <param name="image"></param>
- public static void AddImageToElementLayer(ElementLayer eLayer, List<Image> image)
- {
- if (eLayer != null)
- {
- foreach (Image item in image)
- {
- eLayer.Children.Add(item);
- }
- }
- }
- /// <summary>
- /// 隐藏或显示 ArcGis 层
- /// </summary>
- /// <param name="show">隐藏或显示</param>
- /// <param name="layers">层</param>
- public static void LayersVisibility(bool show, params ElementLayer[] layers)
- {
- if (layers != null)
- {
- foreach (ElementLayer item in layers)
- {
- item.Visible = show;
- }
- }
- }
- /// <summary>
- /// 动态加载图层
- /// 使用 ElementLayer 层
- /// </summary>
- /// <param name="eLayer"></param>
- /// <param name="cacheGraphic"></param>
- /// <param name="map"></param>
- public static void DynamicDrawElementLayer(ElementLayer eLayer, List<UIElement> cacheElement, Map map)
- {
- // 以下四个变量分别表示地图的四个边
- // 即最大经纬度和最小经纬度
- // xMax最大经度,yMax最大纬度
- double xMax = map.Extent.XMax + 2;
- double xMin = map.Extent.XMin - 2;
- double yMax = map.Extent.YMax + 2;
- double yMin = map.Extent.YMin - 2;
- // 去除不在坐标范围内的点,先检查图层是否为空
- if (eLayer != null)
- {
- int graphicCount = eLayer.Children.Count;
- for (int i = 0; i < graphicCount; i++)
- {
- UIElement element = eLayer.Children[i];
- // 判断经度,纬度
- if (!(((element.GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.XMax < xMax && (element.GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.XMax > xMin)
- && ((element.GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.YMax < yMax && (element.GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.YMax > yMin)))
- {
- // 将点在地图上移除,并放在缓存中
- cacheElement.Add(eLayer.Children[i]);
- eLayer.Children.Remove(eLayer.Children[i]);
- graphicCount--; // 当从集合中移除元素时应该把 graphicCount 减1
- i--; // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
- }
- } // i
- }
- // 检查缓存是否为空,并将点绘制到图形上
- if (cacheElement != null)
- {
- int count = cacheElement.Count;
- for (int i = 0; i < count; i++)
- {
- // 判断经度,纬度
- if (((cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.XMax < xMax && (cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.XMax > xMin)
- && ((cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.YMax < yMax && (cacheElement[i].GetValue(ElementLayer.EnvelopeProperty) as Envelope).Extent.YMax > yMin))
- {
- // 运行到此则该点在目前地图范围内,将该点加入到地图中
- eLayer.Children.Add(cacheElement[i]);
- cacheElement.Remove(cacheElement[i]);
- count--; // 当从集合中移除元素时应该把 count 减1
- i--; // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
- continue;
- }
- }
- }
- }
- /// <summary>
- /// 将所有元素画到地图上
- /// </summary>
- /// <param name="eLayer"></param>
- /// <param name="cacheElement"></param>
- public static void DrawAllUIElement(ElementLayer eLayer, List<UIElement> cacheElement)
- {
- if (eLayer != null)
- {
- foreach (UIElement item in cacheElement)
- {
- eLayer.Children.Add(item);
- }
- }
- }
- /// <summary>
- /// 动态的绘制图层
- /// 当然地图移动到相应的坐标后绘制(保留原来的点,绘制新的数据)
- /// 实现了无刷新绘制
- /// </summary>
- /// <param name="glayer">表示地图上的层</param>
- /// <param name="cacheGraphic">存放 Graphics 的缓存</param>
- /// <param name="map">表示一张 ArcGis 地图</param>
- private static void DynamicDrawSymbol(GraphicsLayer glayer, List<Graphic> cacheGraphic, Map map)
- {
- // 以下四个变量分别表示地图的四个边
- // 即最大经纬度和最小经纬度
- // xMax最大经度,yMax最大纬度
- double xMax = map.Extent.XMax + 2;
- double xMin = map.Extent.XMin - 2;
- double yMax = map.Extent.YMax + 2;
- double yMin = map.Extent.YMin - 2;
- // 去除不在坐标范围内的点,先检查图层是否为空
- if (glayer != null)
- {
- int graphicCount = glayer.Graphics.Count;
- for (int i = 0; i < graphicCount; i++)
- {
- // 判断经度,纬度
- if (!((glayer.Graphics[i].Geometry.Extent.XMax < xMax && glayer.Graphics[i].Geometry.Extent.XMax > xMin)
- && (glayer.Graphics[i].Geometry.Extent.YMax < yMax && glayer.Graphics[i].Geometry.Extent.YMax > yMin)))
- {
- // 将点在地图上移除,并放在缓存中
- cacheGraphic.Add(glayer.Graphics[i]);
- glayer.Graphics.Remove(glayer.Graphics[i]);
- graphicCount--; // 当从集合中移除元素时应该把 graphicCount 减1
- i--; // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
- }
- } // i
- }
- // 检查缓存是否为空,并将点绘制到图形上
- if (cacheGraphic != null)
- {
- int count = cacheGraphic.Count;
- for (int i = 0; i < count; i++)
- {
- // 判断经度,纬度
- if ((cacheGraphic[i].Geometry.Extent.XMax < xMax && cacheGraphic[i].Geometry.Extent.XMax > xMin)
- && (cacheGraphic[i].Geometry.Extent.YMax < yMax && cacheGraphic[i].Geometry.Extent.YMax > yMin))
- {
- // 运行到此则该点在目前地图范围内,将该点加入到地图中
- glayer.Graphics.Add(cacheGraphic[i]);
- cacheGraphic.Remove(cacheGraphic[i]);
- count--; // 当从集合中移除元素时应该把 count 减1
- i--; // 元素被移除后相当于当前元素的后一位元素会 -1,应该再循环一次本次循环所以应该 -1
- continue;
- }
- }
- }
- }
- /// <summary>
- /// 将所有元素画到地图上
- /// </summary>
- /// <param name="eLayer"></param>
- /// <param name="cacheElement"></param>
- private static void DrawAllGraphics(GraphicsLayer eLayer, List<Graphic> cacheGraphic)
- {
- if (eLayer != null)
- {
- foreach (Graphic item in cacheGraphic)
- {
- eLayer.Graphics.Add(item);
- }
- }
- }
今天把 GisMap 这个类都写出来了也为了我写下一篇文章做准备吧!后面会写一篇动态加载数据点的文章!因为当大批量点(2000)左右加载到地图上的时候,
就会非常的卡,基本都动不了,所以我们要动态去加载这些点。
ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等--绘制点、线、圆,显示提示信息的更多相关文章
- 利用Arcgis for javascript API绘制GeoJSON并同时弹出多个Popup
1.引言 由于Arcgis for javascript API不可以绘制Geojson,并且提供的Popup一般只可以弹出一个,在很多专题图制作中,会遇到不少的麻烦.因此本文结合了两个现有的Arcg ...
- 基于 ArcGIS Silverlight API开发的WebGIS应用程序的部署
部署流程概述 在微软的iis服务器上部署基于ArcGIS Silverlight API的应用程序,主要包括以下几个步骤: 1)(可选)部署GIS服务 如果需要将GIS服务也部署在Web服务器上,则 ...
- arcgis silverlight api 图层介绍
Layer |--TiledMapServiceLayer | |--ArcGISTiledMapServiceLayer |--DynamicLayer | |--DynamicMapService ...
- Arcgis for Androd API开发系列教程(一)——地图显示与GPS定位
序:最近呢,工作鸭梨不是怎么大,对于自己爱折腾的想法又冒出了水面,开始自己的android开发的学习之旅.但是呢,本人是做GIS的,所以呢,就打算从这方面入手看看,是不是有什么比较好玩的玩意呢,这才导 ...
- ArcGIS API for Silverlight中加载Google地形图(瓦片图)
原文:ArcGIS API for Silverlight中加载Google地形图(瓦片图) 在做水利.气象.土地等行业中,若能使用到Google的地形图那是再合适不过了,下面就介绍如何在ArcGIS ...
- arcgis api for javascript 学习(五) 实现地图绘制工具
1.本文实现的功能为鼠标与地图之间的交互,能够在地图上绘制不同形状的图形 2.代码部分主要讲到的为Graphic函数的相关功能 <!DOCTYPE html> <html> & ...
- arcgis,mapinfo(mapxtreme),openlayers专业GIS系统开发
专业从事基于C#,WinForm ,WPF,Silverlight,WCF以及MS Sql Server 2000/2005/2008/2012 Oracle 9i/10g/11g数据库系统的ERP, ...
- ArcGIS for Silverlight 地图卷帘
原文:ArcGIS for Silverlight 地图卷帘 ArcGIS 地图卷帘 for Silverlight 地图卷帘,其实就是遮罩的效果,在Silverlight里实现这样的效果,对于熟悉S ...
- (转) 基于Arcgis for Js的web GIS数据在线采集简介
http://blog.csdn.net/gisshixisheng/article/details/44310765 在前一篇博文“Arcgis for js之WKT和geometry转换”中实现了 ...
随机推荐
- n是否是2的幂
实例五:n是否是2的幂 方法一:result=n&(n-1) 如果result=0 则n是2的幂方法二:result=n&((~n)+1) 如果result=n 则n是2的幂 原数 ...
- Multinoulli distribution
https://www.statlect.com/probability-distributions/multinoulli-distribution3 Multinoulli distributio ...
- Python: 用shell通配符匹配字符串,fnmatch/fnmatchcase
问题:想使用Unix Shell 中常用的通配符(比如*.py , Dat[0-9]*.csv 等) 去匹配文本字符串 解决方案: 1. fnmatch 模块提供了两个函数—— fnmatch() 和 ...
- RPC和RabbitMQ
在单台机器或者单个进程中,如果要调用某个函数,只需要通过函数指针,传入相关参数,即可调用成功并获得结果.但如果是在分布式系统中,某个进程想要调用远程机器上的其它进程提供的方法(服务),就需要采用RPC ...
- Storm初探
Storm是一种分布式流式处理技术,这一点和Spark与Hadoop的批处理特性有明显的区别. 在数据连续产生,响应时延要求较低的场景中,Storm具有Spark不可比拟的优势. 网络性能监控系统中, ...
- Hive 入门学习线路指导
hive被大多数企业使用,学习它,利于自己掌握企业所使用的技术,这里从安装使用到概念.原理及如何使用遇到的问题,来讲解hive,希望对大家有所帮助. 此篇内容较多:看完之后需要达到的目标: 1.hiv ...
- 20145316许心远《网络对抗》EXP8 Web基础
实验后回答问题 什么是表单 来自百度百科的官方定义:表单在网页中主要负责数据采集功能.一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用CGI程序的URL以及数据提交到服务器的方法. ...
- 关于JavaScript的数组随机排序
昨天了解了一下Fisher–Yates shuffle费雪耶兹随机置乱算法,现在再来看看下面这个曾经网上常见的一个写法: function shuffle(arr) { arr.sort(functi ...
- 计算概论(A)/基础编程练习2(8题)/2:计算书费
#include<stdio.h> int main() { // 声明与初始化 ; // k组测试数据的总费用 double s[k]; // 单价表 double price[]= { ...
- 【翻唱】【你的名字MAD】爱你等于爱自己
http://video.yingtu.co/0/8f606e9b-9694-4d35-a0bf-730391a3ee12.mp4 [你的名字MAD]爱你等于爱自己-原唱翻唱 http://video ...