/// <summary> /// 释放标牌 /// </summary> private void CloseLable() { if (mapLabel != null && !mapLabel.IsDisposed) { mapControl.OnMouseDown -= mapControl_OnMouseDown; mapControl.OnMouseMove -= mapControl_OnMouseMove; mapControl.OnMouseUp -= mapControl_OnMouseUp; mapLabel.Dispose(); mapLabel = null; } }
/// <summary> /// 标牌移动移动线的位置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mapLabel_Move(object sender, EventArgs e) { IPoint targetPoint = base.Geometry as IPoint; Core.Model.MapLngLat startPoint = new Core.Model.MapLngLat(targetPoint.X, targetPoint.Y);//目标点 MapFrame.ArcMap.Windows.MapLabel label = sender as MapFrame.ArcMap.Windows.MapLabel; IPoint labelLocation = mapControl.ToMapPoint(label.Location.X, label.Location.Y); Core.Model.MapLngLat endPoint = new Core.Model.MapLngLat(labelLocation.X, labelLocation.Y);//标牌点 MapFrame.Core.Interface.IMFElement element = BelongLayer.GetElement("标牌线"); if (element == null) { return; } IMFLine lineElement = element as IMFLine; List <Core.Model.MapLngLat> lnglatList = new List <Core.Model.MapLngLat>(); lnglatList.Add(startPoint); lnglatList.Add(endPoint); lineElement.UpdatePosition(lnglatList);//更新位置 }
/// <summary> /// 初始化标牌 /// </summary> private void InitLable() { IPoint point = base.Geometry as IPoint; mapControl = BelongLayer.MapControl as AxMapControl; mapControl.Update(); mapControl.OnMouseDown += mapControl_OnMouseDown; int x = -1; int y = -1; mapControl.FromMapPoint(point, ref x, ref y); System.Drawing.Point targetPoint = new System.Drawing.Point(x, y); mapLabel = new Windows.MapLabel(targetPoint); mapLabel.Move += new EventHandler(mapLabel_Move); mapLabel.Location = mapLabel.LabelLocation; IPoint labelLocation = mapControl.ToMapPoint(mapLabel.Location.X, mapLabel.Location.Y); Dosomething((Action)(delegate { mapControl.Controls.Add(mapLabel); }), true); //画线 MapFrame.Core.Model.Kml kml = new MapFrame.Core.Model.Kml(); kml.Placemark.Name = "标牌线"; MapFrame.Core.Model.KmlLineString line = new MapFrame.Core.Model.KmlLineString(); List <MapFrame.Core.Model.MapLngLat> pointList = new List <MapFrame.Core.Model.MapLngLat>(); pointList.Add(new MapFrame.Core.Model.MapLngLat(point.X, point.Y)); pointList.Add(new MapFrame.Core.Model.MapLngLat(labelLocation.X, labelLocation.Y)); line.PositionList = pointList; line.Color = Color.Black; line.Width = 2; kml.Placemark.Graph = line; BelongLayer.AddElement(kml); }