/// <summary> /// 左键弹起 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void mapControl_eventLButtonUp(object sender, _DHOSOFTMapControlEvents_eventLButtonUpEvent e) { //if (!isShift) //{ // isFinish = true; // isMouseDown = false; // RegistCommondExecutedEvent(); //} if (!isControl) { if (!string.IsNullOrEmpty(tempName)) { mapControl.MgsDelObject(tempName); } Kml kml = new Kml(); KmlCircle circle = new KmlCircle(); kml.Placemark.Name = "mgis_circle" + Utils.ElementIndex; circle.Position = centerPoint; circle.RandomPosition = new MapLngLat(e.dLong, e.dLat); circle.StrokeColor = System.Drawing.Color.Red; circle.FillColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.White); circle.StrokeWidth = 3; kml.Placemark.Graph = circle; IMFElement element = null; layer.AddElement(kml, out element); circleElement = element as IMFCircle; RegistCommondExecutedEvent(); ReleaseCommond();//修改 陈静 isFinish = true; isMouseDown = false; } }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mapControl_OnMouseDown(object sender, IGlobeControlEvents_OnMouseDownEvent e) { if (e.button != 1) { return; } MapLngLat lnglat = this.SceneToGeographyPoint(e.x, e.y); if (kml == null) { kml = new Kml(); kml.Placemark.Name = "绘制圆" + Utils.Index; circleKml = new KmlCircle(); circleKml.Description = "手动绘制的圆"; circleKml.FillColor = Color.FromArgb(70, Color.Orange); circleKml.StrokeColor = Color.FromArgb(70, Color.Red); circleKml.StrokeWidth = 2; circleKml.Rasterize = true; circleKml.Position = lnglat; } else { circleKml.RandomPosition = lnglat; drawn = layer.AddElement(kml, out circleElement); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="p"></param> /// <param name="kmlCircle">kml</param> /// <param name="elementName">图元名称</param> public Circle_GMap(PointLatLng p, KmlCircle kmlCircle, string elementName, List <PointLatLng> points) : base(points, elementName) { position = new MapLngLat(p.Lng, p.Lat); this.IsHitTestVisible = true; this.ElementName = elementName; this.ElementType = ElementTypeEnum.Circle; this.Description = kmlCircle.Description; if (kmlCircle.RandomPosition != null) { radius = Utils.GetDistance(kmlCircle.Position, kmlCircle.RandomPosition) * 1000; } else { radius = kmlCircle.Radius; } Stroke = new Pen(kmlCircle.StrokeColor, kmlCircle.StrokeWidth); Fill = new SolidBrush(kmlCircle.FillColor); pen = new Pen(Brushes.Green, 1); listPoints = new List <GPoint>(); flashTimer = new System.Timers.Timer(); flashTimer.Elapsed += flashTimer_Elapsed; }
// 鼠标左键按下 private void gmapControl_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && !gmapControl.CanDragMap)//空格按下后漫游 { var lngLat = gmapControl.FromLocalToLatLng(e.X, e.Y); centerPoint.Lng = lngLat.Lng; centerPoint.Lat = lngLat.Lat; Kml kml = new Kml(); kml.Placemark.Name = "draw_circle" + Utils.ElementIndex; KmlCircle circleKml = new KmlCircle(); circleKml.FillColor = Color.FromArgb(50, Color.Blue); circleKml.Position = new MapLngLat(lngLat.Lng, lngLat.Lat); circleKml.RandomPosition = circleKml.Position; circleKml.Radius = 0; circleKml.StrokeColor = Color.Gray; circleKml.StrokeWidth = 2; kml.Placemark.Graph = circleKml; IMFElement element = null; drawn = layer.AddElement(kml, out element); circleElement = element as IMFCircle; gmapControl.MouseMove += gmapControl_MouseMove; gmapControl.MouseUp += gmapControl_MouseUp; } }
/// <summary> /// 添加图元 /// </summary> /// <param name="kml"></param> /// <param name="layer"></param> /// <returns></returns> public IMFElement CreateElement(Kml kml, ILayer layer) { KmlCircle circleKml = kml.Placemark.Graph as KmlCircle; if (circleKml.Position == null) { return(null); } int index = -1; Circle_ArcGlobe circleElement = null; this.Dosomething((Action) delegate() { //图元 IGlobeGraphicsLayer graphicsLayer = layer as IGlobeGraphicsLayer; circleElement = new Circle_ArcGlobe(graphicsLayer, circleKml); IGlobeGraphicsElementProperties properties = new GlobeGraphicsElementPropertiesClass(); properties.Rasterize = circleKml.Rasterize; graphicsLayer.AddElement(circleElement, properties, out index); circleElement.Index = index; circleElement.ElementName = kml.Placemark.Name; }, true); return(circleElement); }
/// <summary> /// 释放资源 /// </summary> public void Dispose() { ReleaseCommond(); circleElement = null; mapControl = null; circleKml = null; kml = null; layer = null; CommondExecutedEvent = null; mapLogic = null; drawn = false; }
/// <summary> /// 创建圆图元 /// </summary> /// <param name="kml">kml对象</param> /// <param name="gmapOverlay">图层</param> /// <returns></returns> public IMFElement CreateElement(Kml kml, GMapOverlay gmapOverlay) { KmlCircle kmlCircle = kml.Placemark.Graph as KmlCircle; if (kmlCircle == null) { return(null); } if (kmlCircle.Position == null) { return(null); } if (kmlCircle.RandomPosition == null && kmlCircle.Radius == 0) { return(null); } List <PointLatLng> pointList = new List <PointLatLng>(); for (int i = 0; i < 360; i++) { double seg = Math.PI * i / 180; double a = kmlCircle.Position.Lng + kmlCircle.Radius * Math.Cos(seg) / 100000; double b = kmlCircle.Position.Lat + kmlCircle.Radius * Math.Sin(seg) / 100000; PointLatLng lnglat = new PointLatLng(b, a); pointList.Add(lnglat); } Circle_GMapEx circle = new Circle_GMapEx(pointList, kmlCircle, kml.Placemark.Name); // 添加到图层 if (gmapOverlay.Control.InvokeRequired) { gmapOverlay.Control.Invoke(new Action(delegate { gmapOverlay.Polygons.Add(circle); })); } else { gmapOverlay.Polygons.Add(circle); } return(circle); }
private void 添加圆ToolStripMenuItem_Click(object sender, EventArgs e) { Kml kml = new Kml(); kml.Placemark.Name = "my_circle"; KmlCircle circle = new KmlCircle(); circle.Position = new MapLngLat(110, 30); circle.FillColor = Color.Red; circle.Radius = 500000; circle.StrokeColor = Color.Gray; circle.StrokeWidth = 3; kml.Placemark.Graph = circle; // 画点 mapLogic.GetLayer(drawLayerName).AddElement(kml, out element); circleElement = element as IMFCircle; }
/// <summary> /// 构造函数 /// </summary> /// <param name="kml">kml对象</param> /// <param name="_mapControl">地图控件</param> public Circle_Mgis(Kml kml, AxHOSOFTMapControl _mapControl) { this.mapControl = _mapControl; KmlCircle kmlCircle = kml.Placemark.Graph as KmlCircle; if (kmlCircle.Position == null || kmlCircle.RandomPosition == null || kml.Placemark.Name == string.Empty) { return; } listPoint = new List <MapLngLat>(); listPoint.Add(kmlCircle.Position); listPoint.Add(kmlCircle.RandomPosition); float[] vertex = new float[4]; IntPtr ptrVert = Marshal.AllocHGlobal(sizeof(float) * 4); vertex[0] = (float)listPoint[0].Lng; vertex[1] = (float)listPoint[0].Lat; vertex[2] = (float)listPoint[1].Lng; vertex[3] = (float)listPoint[1].Lat; Marshal.Copy(vertex, 0, ptrVert, vertex.Length); this.symbolName = kml.Placemark.Name; mapControl.MgsDrawLineSymByJBID(symbolName, 16, (ulong)(ptrVert.ToInt64()), 2); mapControl.MgsUpdateSymFillColor(symbolName, kmlCircle.FillColor.R, kmlCircle.FillColor.G, kmlCircle.FillColor.B, kmlCircle.FillColor.A); mapControl.MgsUpdateSymColor(symbolName, kmlCircle.StrokeColor.R, kmlCircle.StrokeColor.G, kmlCircle.StrokeColor.B, kmlCircle.StrokeColor.A); mapControl.MgsUpdateSymLineWidth(symbolName, kmlCircle.StrokeWidth); //轮廓大小 mapControl.update(); //刷新 Marshal.FreeHGlobal(ptrVert); this.ElementType = ElementTypeEnum.Circle; bFillColor = kmlCircle.FillColor; //填充颜色 bOutLineColor = kmlCircle.StrokeColor; //轮廓颜色 this.width = kmlCircle.StrokeWidth; //轮廓大小 flashTimer = new Timer(); flashTimer.Elapsed += new ElapsedEventHandler(flashTimer_Elapsed); flashTimer.Interval = 500; }
/// <summary> /// 构造函数 /// </summary> /// <param name="pointList"></param> /// <param name="kmlCircle"></param> /// <param name="elementName"></param> public Circle_GMapEx(List <PointLatLng> pointList, KmlCircle kmlCircle, string elementName) : base(pointList, elementName) { this.radius = kmlCircle.Radius; this.centerLnglat = kmlCircle.Position; this.ElementName = elementName; this.ElementType = ElementTypeEnum.Circle; this.Description = "圆"; this.fillColor = kmlCircle.FillColor; SolidBrush b = new SolidBrush(kmlCircle.FillColor); base.Fill = b; Pen pen = new Pen(kmlCircle.StrokeColor, kmlCircle.StrokeWidth); base.Stroke = pen; this.IsHitTestVisible = true; // 鼠标经过可见 base.Tag = this; refreshTimer = new System.Timers.Timer(500); refreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(refreshTimer_Elapsed); }
// 绘制设备服务 public void DrawDeviceRanage(DataTable dt) { if (dt == null || dt.Rows.Count <= 0) { return; } foreach (DataRow row in dt.Rows) { DeviceData device = new DeviceData(row); IMFLayer layer = mapLogic.AddLayer("设备服务图层"); if (layer == null) { continue; } // 绘制设备(基站) string url = string.Format("{0}|{1}|{2}", Application.StartupPath + "\\Image\\TTMITC.TTF", 113, 20); Kml kml = new Kml(); kml.Placemark.Name = device.DeviceNumber; kml.Placemark.Graph = new KmlPicture() { Position = new MapLngLat(device.Lng, device.Lat), IconUrl = url, Scale = 1, TipText = device.DeviceNumber, LabelText = device.DeviceName, IconColor = Color.Red }; layer.AddElement(kml); // 绘制服务范围(面) Kml kmlCircle = new Kml(); kmlCircle.Placemark.Name = device.DeviceNumber + "polygon"; KmlCircle circle = new KmlCircle(); circle.Position = new MapLngLat(device.Lng, device.Lat); circle.FillColor = Color.FromArgb(50, Color.Green); circle.Radius = device.RangeRadius * 1000; circle.StrokeColor = Color.Blue; circle.StrokeWidth = 1; kmlCircle.Placemark.Graph = circle; layer.AddElement(kmlCircle); } }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (e.button == 1 && !isMouseDown && !isControl) { centerDot = new MapLngLat() { Lng = e.mapX, Lat = e.mapY }; Kml kml = new Kml(); kml.Placemark.Name = "arc_circle" + Utils.ElementIndex; KmlCircle circle = new KmlCircle(); circle.Position = centerDot; circle.Radius = 0.1; circle.StrokeColor = Color.Yellow; circle.StrokeWidth = 2; circle.FillColor = System.Drawing.Color.Red; kml.Placemark.Graph = circle; IMFElement element = null; layer.AddElement(kml, out element); circleElement = element as IMFCircle; isMouseDown = true; isFinish = false; } }
// 处理波束数据 private void DealBeamCover(BeamData e) { if (e.Point.Alt > 0) { return; // 卫星数据,不做处理 } if (mapLogic == null) { return; } // 添加圆图元(波束覆盖) IMFLayer layer = mapLogic.AddLayer(coverLayerName); if (layer == null) { return; } string circleName = string.Format("卫星{0}-波束{1}", e.SatelliteId, e.BeamId); string textName = string.Format("卫星{0}-波束{1}_描述", e.SatelliteId, e.BeamId, e.BeamId); if (!beamDic.ContainsKey(e.SatelliteId)) // 新的波束 { Kml kmlCircle = new Kml(); kmlCircle.Placemark.Name = circleName; KmlCircle circle = new KmlCircle(); circle.Position = e.Point; circle.FillColor = Color.FromArgb(50, Color.Green); circle.Radius = 500000; circle.StrokeColor = Color.Blue; circle.StrokeWidth = 1; kmlCircle.Placemark.Graph = circle; layer.AddElement(kmlCircle); // 添加文字图元 Kml kmlText = new Kml(); kmlText.Placemark.Name = textName; string context = string.Format("卫星{0}-波束{1}", e.SatelliteId, e.BeamId); kmlText.Placemark.Graph = new KmlText() { Position = e.Point, Content = context, Color = Color.Blue, Font = "宋体", Size = 10 }; IMFElement elementText; if (layer.AddElement(kmlText, out elementText)) { bool visible = zoom >= visibleZoom ? true : false; elementText.SetVisible(visible); } // 添加到字典进行维护 List <int> beamIdList = new List <int>(); beamIdList.Add(e.BeamId); lock (beamDic) { beamDic.Add(e.SatelliteId, beamIdList); } } else { if (!beamDic[e.SatelliteId].Contains(e.BeamId)) // 新的波束 { Kml kmlCircle = new Kml(); kmlCircle.Placemark.Name = circleName; KmlCircle circle = new KmlCircle(); circle.Position = e.Point; circle.FillColor = Color.FromArgb(50, Color.Green); circle.Radius = 500000; circle.StrokeColor = Color.Blue; circle.StrokeWidth = 1; kmlCircle.Placemark.Graph = circle; layer.AddElement(kmlCircle); // 添加文字图元 string context = string.Format("卫星{0}-波束{1}", e.SatelliteId, e.BeamId); Kml kmlText = new Kml(); kmlText.Placemark.Name = textName; kmlText.Placemark.Graph = new KmlText() { Position = e.Point, Content = context, Color = Color.Blue, Font = "宋体", Size = 10 }; IMFElement elementText; if (layer.AddElement(kmlText, out elementText)) { bool visible = zoom >= visibleZoom ? true : false; elementText.SetVisible(visible); } lock (beamDic) { // 添加到字典进行维护 beamDic[e.SatelliteId].Add(e.BeamId); } } else { // 更新圆图元(波束覆盖)位置 IMFElement elementCircle = layer.GetElement(circleName); if (elementCircle != null) { IMFCircle circle = elementCircle as IMFCircle; if (circle != null) { circle.UpdatePosition(e.Point); } } // 更新文字图元(描述信息)位置 IMFElement elementText = layer.GetElement(textName); if (elementText != null) { IMFText text = elementText as IMFText; if (text != null) { text.UpdatePosition(e.Point); } } } } }
/// <summary> /// 构造函数 /// </summary> /// <param name="graphicsLayer">图层</param> /// <param name="kmlCircle">圆的kml</param> public Circle_ArcGlobe(IGlobeGraphicsLayer _graphicsLayer, KmlCircle kmlCircle) { this.ElementType = Core.Model.ElementTypeEnum.Circle; graphicsLayer = _graphicsLayer; lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = new RgbColorClass() { Red = kmlCircle.StrokeColor.R, Green = kmlCircle.StrokeColor.G, Blue = kmlCircle.StrokeColor.B }; if (kmlCircle.StrokeWidth == 0) { kmlCircle.StrokeWidth = 2; } lineSymbol.Width = kmlCircle.StrokeWidth; fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Outline = lineSymbol; fillSymbol.Color = new RgbColorClass() { Red = kmlCircle.FillColor.R, Green = kmlCircle.FillColor.G, Blue = kmlCircle.FillColor.B }; radius = kmlCircle.Radius; outlineColor = kmlCircle.StrokeColor; fillColor = kmlCircle.FillColor; centerPoint = new PointClass();//圆心坐标 centerPoint.PutCoords(kmlCircle.Position.Lng, kmlCircle.Position.Lat); centerPoint.Z = kmlCircle.Position.Alt; missing = System.Type.Missing; IZAware zAware = (IGeometry)centerPoint as IZAware; zAware.ZAware = true; upperAxisVector3D = new Vector3DClass(); upperAxisVector3D.SetComponents(0, 0, 2); lowerAxisVector3D = new Vector3DClass(); lowerAxisVector3D.SetComponents(0, 0, -2); lowerAxisVector3D.XComponent -= vectorComponentOffset; lowerAxisVector3D.YComponent -= vectorComponentOffset;//TODO normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D; normalVector3D.Magnitude = kmlCircle.Radius; double rotationAngleInRadians = 2 * (Math.PI / 180); //geometryCollection = new MultiPatchClass(); pointCollection = new PolygonClass(); for (int i = 0; i < 180; i++) { normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D); IPoint vertexPoint = new PointClass(); vertexPoint.X = centerPoint.X + normalVector3D.XComponent; vertexPoint.Y = centerPoint.Y + normalVector3D.YComponent; vertexPoint.Z = centerPoint.Z; pointCollection.AddPoint(vertexPoint, missing, missing); } base.Symbol = fillSymbol; base.Geometry = pointCollection as IGeometry; flashTimer = new System.Timers.Timer(); flashTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTimer_Elapsed); flashTimer.Interval = 500; }
/// <summary> /// 构造函数 /// </summary> /// <param name="_mapControl"></param> /// <param name="circle"></param> public Circle_ArcMap(AxMapControl _mapControl, KmlCircle circle, FactoryArcMap facArc) { this.mapControl = _mapControl; this.factoryArcMap = facArc; Dosomething(new Action(delegate { lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = new RgbColorClass() { Red = circle.StrokeColor.R, Green = circle.StrokeColor.B, Blue = circle.StrokeColor.B }; lineSymbol.Width = circle.StrokeWidth; fillSymbol = new SimpleFillSymbol(); fillSymbol.Outline = lineSymbol; //填充色 IColor fillColor = new RgbColorClass() { Transparency = circle.FillColor.A, Red = circle.FillColor.R, Green = circle.FillColor.G, Blue = circle.FillColor.B }; fillSymbol.Color = fillColor; base.Symbol = fillSymbol;//颜色和风格 iSeg = new RingClass(); centerPoint = new PointClass();//圆心坐标 centerPoint.PutCoords(circle.Position.Lng, circle.Position.Lat); MapLngLat around = MapFrame.Core.Common.Utils.GetPointByDistanceAndAngle((float)circle.Radius, circle.Position, 180); INewLineFeedback backline = new NewLineFeedbackClass(); IPoint aroundPoint = new PointClass() { X = around.Lng, Y = around.Lat }; backline.Start(centerPoint); backline.AddPoint(aroundPoint); var geo = backline.Stop(); iSeg.SetCircle(centerPoint, geo.Length); object o = System.Type.Missing; pRing = iSeg as IRing; pRing.Close(); pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); pGeometry = pGeometryColl as IGeometry; base.Geometry = pGeometry; }), true); pRadius = circle.Radius; bOutLineColor = circle.StrokeColor; bFillColor = circle.FillColor; bWidth = circle.StrokeWidth; flashTimer = new Timer(); flashTimer.Elapsed += new ElapsedEventHandler(flashTimer_Elapsed); #region MyRegion //if (mapControl.InvokeRequired) //{ // mapControl.Invoke((Action)delegate() // { // lineSymbol = new SimpleLineSymbolClass(); // lineSymbol.Color = new RgbColorClass() // { // Red = circle.StrokeColor.R, // Green = circle.StrokeColor.B, // Blue = circle.StrokeColor.B // }; // lineSymbol.Width = circle.StrokeWidth; // fillSymbol = new SimpleFillSymbol(); // fillSymbol.Outline = lineSymbol; // //填充色 // IColor fillColor = new RgbColorClass() // { // Transparency = circle.FillColor.A, // Red = circle.FillColor.R, // Green = circle.FillColor.G, // Blue = circle.FillColor.B // }; // fillSymbol.Color = fillColor; // base.Symbol = fillSymbol;//颜色和风格 // iSeg = new RingClass(); // centerPoint = new PointClass();//圆心坐标 // centerPoint.PutCoords(circle.Position.Lng, circle.Position.Lat); // //MapFrame.Core.Model.MapLngLat around = GetPointByDistanceAndAngle(circle.Radius, circle.Position); // MapLngLat around = MapFrame.Core.Common.Utils.GetPointByDistanceAndAngle((float)circle.Radius, circle.Position, 180); // INewLineFeedback backline = new NewLineFeedbackClass(); // IPoint aroundPoint = new PointClass() { X = around.Lng, Y = around.Lat }; // backline.Start(centerPoint); // backline.AddPoint(aroundPoint); // var geo = backline.Stop(); // iSeg.SetCircle(centerPoint, geo.Length); // object o = System.Type.Missing; // pRing = iSeg as IRing; // pRing.Close(); // pGeometryColl = new PolygonClass(); // pGeometryColl.AddGeometry(pRing, ref o, ref o); // pGeometry = pGeometryColl as IGeometry; // base.Geometry = pGeometry; // }); //} //else //{ // lineSymbol = new SimpleLineSymbolClass(); // lineSymbol.Color = new RgbColorClass() // { // Red = circle.StrokeColor.R, // Green = circle.StrokeColor.B, // Blue = circle.StrokeColor.B // }; // lineSymbol.Width = circle.StrokeWidth; // fillSymbol = new SimpleFillSymbol(); // fillSymbol.Outline = lineSymbol; // //填充色 // IColor fillColor = new RgbColorClass() // { // Transparency = circle.FillColor.A, // Red = circle.FillColor.R, // Green = circle.FillColor.G, // Blue = circle.FillColor.B // }; // fillSymbol.Color = fillColor; // base.Symbol = fillSymbol;//颜色和风格 // iSeg = new RingClass(); // centerPoint = new PointClass();//圆心坐标 // centerPoint.PutCoords(circle.Position.Lng, circle.Position.Lat); // //MapFrame.Core.Model.MapLngLat around = GetPointByDistanceAndAngle(circle.Radius, circle.Position); // MapLngLat around = MapFrame.Core.Common.Utils.GetPointByDistanceAndAngle((float)circle.Radius, circle.Position, 180); // INewLineFeedback backline = new NewLineFeedbackClass(); // IPoint aroundPoint = new PointClass() { X = around.Lng, Y = around.Lat }; // backline.Start(centerPoint); // backline.AddPoint(aroundPoint); // var geo = backline.Stop(); // iSeg.SetCircle(centerPoint, geo.Length); // object o = System.Type.Missing; // pRing = iSeg as IRing; // pRing.Close(); // pGeometryColl = new PolygonClass(); // pGeometryColl.AddGeometry(pRing, ref o, ref o); // pGeometry = pGeometryColl as IGeometry; // base.Geometry = pGeometry; //} #endregion }