private void 添加一个点ToolStripMenuItem1_Click(object sender, System.EventArgs e) { if (polygonElement == null) { return; } polygonElement.AddPoint(new MapLngLat(0, 0)); }
/// <summary> /// 鼠标按下 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gmapControl_MouseDown(object sender, MouseEventArgs e) { TimeSpan span = DateTime.Now - fistTimer; if (span.TotalMilliseconds < 170) { return; } fistTimer = DateTime.Now; if (e.Clicks == 2 || e.Button != MouseButtons.Left || isMouseDown) { return; } var lngLat = gmapControl.FromLocalToLatLng(e.X, e.Y); var maplanLat = new MapLngLat(lngLat.Lng, lngLat.Lat); if (listMapPoints.Count == 0)//第一个点 生成多边形 { Kml polygonKml = new Kml(); polygonKml.Placemark.Name = "draw_polygon" + Utils.ElementIndex; listMapPoints.Add(maplanLat); //添加到集合中 polygonKml.Placemark.Graph = new KmlPolygon() { Description = "", PositionList = listMapPoints, FillColor = Color.FromArgb(155, Color.AliceBlue), OutLineColor = Color.FromArgb(155, Color.MidnightBlue) }; IMFElement element = null; drawn = layer.AddElement(polygonKml, out element); // 添加多边形到地图中 polygonElement = element as IMFPolygon; gmapControl.MouseMove += gmapControl_MouseMove; } else { if (!listMapPoints.Contains(maplanLat)) { listMapPoints.Add(maplanLat); polygonElement.AddPoint(maplanLat); } } }