/// <summary> /// 添加点图元 /// </summary> /// <param name="kml">kml对象</param> /// <param name="gmapOverlay">图层</param> /// <returns></returns> public Core.Interface.IMFElement CreateElement(Kml kml, global::GMap.NET.WindowsForms.GMapOverlay gmapOverlay) { if (overlay == null) { overlay = gmapOverlay; overlay.Control.OnMarkerEnter += Control_OnMarkerEnter; overlay.Control.OnMarkerLeave += Control_OnMarkerLeave; } KmlPicture kmlPicture = kml.Placemark.Graph as KmlPicture; if (kmlPicture == null) { return(null); } if (kmlPicture.Position == null) { return(null); } PointLatLng p = new PointLatLng(kmlPicture.Position.Lat, kmlPicture.Position.Lng, kmlPicture.Position.Alt); // 位置和图片 Picture_GMap moveObj = new Picture_GMap(p, kmlPicture, kml.Placemark.Name); // Tip if (!string.IsNullOrEmpty(kmlPicture.TipText)) { moveObj.ToolTipText = kmlPicture.TipText; moveObj.ToolTipMode = MarkerTooltipMode.OnMouseOver; moveObj.ToolTip.Format.Alignment = System.Drawing.StringAlignment.Near; // Tip文字左对齐 } // 添加图元到图层 if (gmapOverlay.Control.InvokeRequired) { gmapOverlay.Control.BeginInvoke(new Action(delegate { gmapOverlay.Markers.Add(moveObj); })); } else { gmapOverlay.Markers.Add(moveObj); } return(moveObj); }
/// <summary> /// 进入目标事件 /// </summary> /// <param name="item"></param> private void Control_OnMarkerEnter(GMapMarker item) { Picture_GMap gmapMoveObj = item as Picture_GMap; if (gmapMoveObj == null) { return; } switch (gmapMoveObj.LabelShowType) { case ShowTypeEnum.No: gmapMoveObj.CloseMapLabel(); break; case ShowTypeEnum.MouseHover: gmapMoveObj.InitMapLabel(); break; case ShowTypeEnum.Always: gmapMoveObj.InitMapLabel(); break; } }
/// <summary> /// 离开目标事件 /// </summary> /// <param name="item"></param> private void Control_OnMarkerLeave(GMapMarker item) { Picture_GMap gmapMoveObj = item as Picture_GMap; if (gmapMoveObj == null) { return; } switch (gmapMoveObj.LabelShowType) { case ShowTypeEnum.No: //不显示 gmapMoveObj.CloseMapLabel(); break; case ShowTypeEnum.MouseHover: //移上显示 gmapMoveObj.CloseMapLabel(); break; case ShowTypeEnum.Always: //永久显示 //gmapPoint.InitToolTip(); break; } }