public static Dictionary <string, List <CustomPolygon> > GetPolygons(Dictionary <string, List <List <List <double> > > > states) { Dictionary <string, List <CustomPolygon> > polygons = new Dictionary <string, List <CustomPolygon> >(); foreach (KeyValuePair <string, List <List <List <double> > > > state in states) { foreach (List <List <double> > polygon in states[state.Key]) { List <PointLatLng> points = new List <PointLatLng>(); foreach (List <double> point in polygon) { points.Add(new PointLatLng(point[1], point[0])); } CustomPolygon newpolygon = new CustomPolygon(points, state.Key, GetCentroid(points), points.Count()); if (!polygons.ContainsKey(state.Key)) { List <CustomPolygon> polygonlist = new List <CustomPolygon>(); polygonlist.Add(newpolygon); polygons.Add(state.Key, polygonlist); } else { polygons[state.Key].Add(newpolygon); } } } return(polygons); }
/// <summary> /// Khoi tao overlay Polygon. /// </summary> public void SetDrawingPolygon(CustomPolygon polygon) { OverlayFirst = this.Overlays[0]; _polygon = polygon; // add custom layers { OverlayPolygon_Auxiliary = new GMapOverlay("auxiliary"); //Overlay phụ this.Overlays.Add(OverlayPolygon_Auxiliary); OverlayPolygon_Vertices = new GMapOverlay("vertices"); //overlay đỉnh this.Overlays.Add(OverlayPolygon_Vertices); OverlayRoute = new GMapOverlay("route"); //overlay dẫn đường this.Overlays.Add(OverlayRoute); } if (!OverlayFirst.Polygons.Contains(_polygon)) { OverlayFirst.Polygons.Add(_polygon); } //auxiliar.Markers.Clear(); //vertices.Markers.Clear(); //clear polygon _polygon.Points.Clear(); this.UpdatePolygonLocalPosition(_polygon); polygonIsComplete = false; }
/// <summary> /// Xóa tất cả các marker và Overlay trên bản đồ /// </summary> public void ClearAll() { foreach (GMapOverlay overlay in Overlays) { overlay.Markers.Clear(); } Overlays.Clear(); _polygon = null; OverlayPolygon_Auxiliary = null; OverlayPolygon_Vertices = null; OverlayCustom = null; OverlayXeNhan = null; OverlayXeDeCu = null; }
/// <summary> /// đỗ dữ liệu lên form /// </summary> private void FillDataToForm() { string toaDoVung = gDMVung_GPSEntity.ToaDoVung; txtTenVung.Text = gDMVung_GPSEntity.TenVungGPS; numKenhGop.Value = gDMVung_GPSEntity.KenhGop; numKenhVung.Value = gDMVung_GPSEntity.KenhVung; numBKTimXe.Value = gDMVung_GPSEntity.BanKinhTimXe; G_IdVungGPS = gDMVung_GPSEntity.ID; G_ArrPoint_VungKenh = toaDoVung; isAddNewForm = false; btnXoa.Enabled = true; top.Polygons.Clear(); CustomPolygon currPolygon = GetCustomPolygon(toaDoVung); MainMap.SetDrawingPolygonCustom(currPolygon); MainMap.Position = currPolygon.Points[0]; }
public void SetDrawingPolygonCustom(CustomPolygon polygon) { ClearDrawingPolygon(); OverlayFirst = this.Overlays[0]; _polygon = polygon; { OverlayPolygon_Auxiliary = new GMapOverlay("auxiliary"); this.Overlays.Add(OverlayPolygon_Auxiliary); OverlayPolygon_Vertices = new GMapOverlay("vertices"); this.Overlays.Add(OverlayPolygon_Vertices); } //draw the polygon if (polygon.Points.Count > 2) { for (int i = 0; i < polygon.Points.Count; i++) { GMapMarkerRedCircle vertice = null; if (i == polygon.Points.Count - 1) { vertice = (GMapMarkerRedCircle)OverlayPolygon_Vertices.Markers[0]; } else { vertice = new GMapMarkerRedCircle(polygon.Points[i]); } OverlayPolygon_Vertices.Markers.Add(vertice); if (i > 0) { PointLatLng intermedium = CalculateMiddlePoint(OverlayPolygon_Vertices.Markers[i - 1], OverlayPolygon_Vertices.Markers[i]); GMapMarkerGraySquare intermediatePoint = new GMapMarkerGraySquare(intermedium); OverlayPolygon_Auxiliary.Markers.Add(intermediatePoint); } } polygonIsComplete = true; } if (!OverlayFirst.Polygons.Contains(_polygon)) { OverlayFirst.Polygons.Add(_polygon); } }
void SetObjectToEdit() { if (_mapMode == MapModeEnum.EditPoint) { //if (currentMarker == null) // currentMarker = new GMapMarkerGoogleRed(new PointLatLng()); if (currentMarker != null) { top.Markers.Add(currentMarker); } } if (_mapMode == MapModeEnum.EditArea) { if (currentPolygon == null) { currentPolygon = new CustomPolygon(new List <PointLatLng>(), "MyPolygon"); } MainMap.SetDrawingPolygon(currentPolygon); } }