private void mapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { if (eventInited == 1) { ICommand command = mapControl.CurrentTool as ICommand; if (command != null && command.Name == "ControlToolsMapNavigation_Pan") { //更新标牌 IPoint targetPoint = base.Geometry as IPoint; Core.Model.MapLngLat startPoint = new Core.Model.MapLngLat(targetPoint.X, targetPoint.Y); int x = -1; int y = -1; mapControl.FromMapPoint(targetPoint, ref x, ref y); mapLabel.UpdateLabelLocation(new System.Drawing.Point(x, y)); //更新线 IPoint labelPoint = mapControl.ToMapPoint(mapLabel.Location.X, mapLabel.Location.Y); Core.Model.MapLngLat endPoint = new Core.Model.MapLngLat(labelPoint.X, labelPoint.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> public void Update() { if (BelongLayer != null) { BelongLayer.Refresh(); } }
/// <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); }
/// <summary> /// 设置大小 /// </summary> /// <param name="scale"></param> public void SetScale(float scale) { mScale = scale; LoadBitmap(imageUrl); BelongLayer.Refresh(); }