/// <summary> /// 点选 /// </summary> /// <returns>被选中要素FID的List</returns> internal override List <int> SelectByPoint(Point mouseLocation, Rectangle bounds, PointF centerPos, double scale) { List <int> selectedID = new List <int>(); MyPoint xyCenter = ETCProjection.LngLat2XY(new MyPoint(centerPos.X, centerPos.Y)); double xmin = xyCenter.X - scale * bounds.Width / 2; double xmax = xyCenter.X + scale * bounds.Width / 2; double ymin = xyCenter.Y - scale * bounds.Height / 2; double ymax = xyCenter.Y + scale * bounds.Height / 2; for (int i = 0; i < polygons.Count; i++) { MyPoint[] screenPoints = new MyPoint[polygons[i].PointCount]; for (int j = 0; j < polygons[i].PointCount; j++) { MyPoint xyProjection = ETCProjection.LngLat2XY(polygons[i].Points[j]); double xScreen = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin); double yScreen = bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin); MyPoint screen = new MyPoint(xScreen, bounds.Height - yScreen); screenPoints[j] = screen; } polygons[i].Selected = GeometryTools.IsPointInPolygon(new MyPoint(mouseLocation.X, mouseLocation.Y), screenPoints); if (polygons[i].Selected == true) { selectedID.Add(i); } } return(selectedID); }
/// <summary> /// 画注记 /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> /// <param name="centerPos"></param> /// <param name="scale"></param> /// <param name="fid2Text"></param> internal override void DrawLabel(Graphics g, Rectangle bounds, PointF centerPos, double scale, Dictionary <int, string> fid2Text, TextSymbol textSymbol) { MyPoint xyCenter = ETCProjection.LngLat2XY(new MyPoint(centerPos.X, centerPos.Y)); double xmin = xyCenter.X - scale * bounds.Width / 2; double xmax = xyCenter.X + scale * bounds.Width / 2; double ymin = xyCenter.Y - scale * bounds.Height / 2; double ymax = xyCenter.Y + scale * bounds.Height / 2; for (int i = 0; i < polygons.Count; i++) { List <PointF> pointfs = new List <PointF>(); for (int j = 0; j < polygons[i].PointCount; j++) { MyPoint xyProjection = ETCProjection.LngLat2XY(polygons[i].Points[j]); double xScreen = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin); double yScreen = bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin); PointF p = new PointF((float)xScreen, bounds.Height - (float)yScreen); pointfs.Add(p); } RectangleF mbr = GeometryTools.GetMBR(pointfs.ToArray()); string text = fid2Text[polygons[i].FID]; if (Math.Max(mbr.Width, mbr.Height) > textSymbol.TextStyle.TextSize * text.Length) { TextSymbol.PolygonLabel(pointfs.ToArray(), g, textSymbol, text); } } }
/// <summary> /// 唯一值渲染和分级渲染时的绘制要素 /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> /// <param name="centerPos"></param> /// <param name="scale"></param> /// <param name="fid2Symbol"></param> internal override void DrawSpaceData(Graphics g, Rectangle bounds, PointF centerPos, double scale, Dictionary <int, Symbol> fid2Symbol) { //选中要素的样式 Brush selectedBrush = new SolidBrush(Color.Cyan); MyPoint xyCenter = ETCProjection.LngLat2XY(new MyPoint(centerPos.X, centerPos.Y)); double xmin = xyCenter.X - scale * bounds.Width / 2; double xmax = xyCenter.X + scale * bounds.Width / 2; double ymin = xyCenter.Y - scale * bounds.Height / 2; double ymax = xyCenter.Y + scale * bounds.Height / 2; for (int i = 0; i < myPoints.Count; i++) { //从symbol中获取样式 PointSymbol ps = (PointSymbol)fid2Symbol[myPoints[i].FID]; MyPoint xyProjection = ETCProjection.LngLat2XY(myPoints[i]); double xScreen = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin); double yScreen = bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin); if (GeometryTools.IsPointInBox(new MyPoint(xScreen, yScreen), new MyRectangle(bounds.X, bounds.Width, bounds.Y, bounds.Height)) == true) { if (myPoints[i].Selected == true) { Rectangle rect = new Rectangle((int)xScreen - 5, bounds.Height - (int)yScreen - 5, 10, 10); g.FillEllipse(selectedBrush, rect); } else { ps.GetSymbol(g, new PointF((float)xScreen, bounds.Height - (float)yScreen)); } } } }
/// <summary> /// 根据矩形盒选择要素,矩形盒坐标位于投影坐标系 /// </summary> /// <param name="box">矩形盒</param> internal override List <int> SelectByBox(MyRectangle box) { List <int> selectedID = new List <int>(); for (int i = 0; i < polygons.Count; i++) { polygons[i].Selected = GeometryTools.IsPolygonCompleteInBox(polygons[i], box); if (polygons[i].Selected == true) { selectedID.Add(i); } } return(selectedID); }
/// <summary> /// 根据矩形盒选择要素,矩形盒坐标位于投影坐标系 /// </summary> /// <param name="box">矩形盒</param> internal override List <int> SelectByBox(MyRectangle box) { List <int> selectedID = new List <int>(); for (int i = 0; i < myPoints.Count; i++) { MyPoint pointXY = ETCProjection.LngLat2XY(myPoints[i]); //投影坐标系下的坐标 myPoints[i].Selected = GeometryTools.IsPointInBox(pointXY, box); if (myPoints[i].Selected == true) { selectedID.Add(i); } } return(selectedID); }
/// <summary> /// 唯一值渲染和分级渲染时的绘制要素 /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> /// <param name="centerPos"></param> /// <param name="scale"></param> /// <param name="fid2Symbol"></param> internal override void DrawSpaceData(Graphics g, Rectangle bounds, PointF centerPos, double scale, Dictionary <int, Symbol> fid2Symbol) { //选中要素的样式 Pen selectedPen = new Pen(Color.Cyan); selectedPen.Width = 2.5F; MyPoint xyCenter = ETCProjection.LngLat2XY(new MyPoint(centerPos.X, centerPos.Y)); double xmin = xyCenter.X - scale * bounds.Width / 2; double xmax = xyCenter.X + scale * bounds.Width / 2; double ymin = xyCenter.Y - scale * bounds.Height / 2; double ymax = xyCenter.Y + scale * bounds.Height / 2; for (int i = 0; i < polylines.Count; i++) { //从symbol中获取样式 LineSymbol ls = (LineSymbol)fid2Symbol[polylines[i].FID]; Pen mypen = ls.GetPen; List <int> parts = new List <int>(polylines[i].firstIndex); parts.Add(polylines[i].PointCount); for (int k = 0; k < polylines[i].firstIndex.Length; k++) //对于每一条多线的子线段 { List <PointF> pointfs = new List <PointF>(); for (int j = parts[k]; j < parts[k + 1]; j++) { MyPoint xyProjection = ETCProjection.LngLat2XY(polylines[i].Points[j]); double xScreen = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin); double yScreen = bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin); PointF p = new PointF((float)xScreen, bounds.Height - (float)yScreen); pointfs.Add(p); } if (GeometryTools.IsPointsPartInRectangle(pointfs.ToArray(), new MyRectangle(bounds.X, bounds.Width, bounds.Y, bounds.Height)) == true) { if (polylines[i].Selected == false) { g.DrawLines(mypen, pointfs.ToArray()); } else { g.DrawLines(selectedPen, pointfs.ToArray()); } } } } }
/// <summary> /// 点选选中要素的顶点 /// </summary> /// <param name="mouseLocation"></param> /// <param name="bounds"></param> /// <param name="centerPos"></param> /// <param name="scale"></param> internal override void SelectVertex(Point mouseLocation, Rectangle bounds, PointF centerPos, double scale) { MyPoint xyCenter = ETCProjection.LngLat2XY(new MyPoint(centerPos.X, centerPos.Y)); double xmin = xyCenter.X - scale * bounds.Width / 2; double xmax = xyCenter.X + scale * bounds.Width / 2; double ymin = xyCenter.Y - scale * bounds.Height / 2; double ymax = xyCenter.Y + scale * bounds.Height / 2; for (int i = 0; i < polygons.Count; i++) { if (polygons[i].Selected == true) //polylines[i]被选中 { for (int j = 0; j < polygons[i].PointCount; j++) { MyPoint xyProjection = ETCProjection.LngLat2XY(polygons[i].Points[j]); double xScreen = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin); double yScreen = bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin); MyPoint screen = new MyPoint(xScreen, bounds.Height - yScreen); //polygons[i].Points[j]在屏幕坐标系的位置 polygons[i].Points[j].Selected = GeometryTools.IsPointInCircle(new MyPoint(mouseLocation.X, mouseLocation.Y), screen, margin); //判断polylines[i].Points[j]是否被选中并修改Selected属性的值 } } } }
/// <summary> /// 点选 /// </summary> /// <returns>被选中要素FID的List</returns> internal override List <int> SelectByPoint(Point mouseLocation, Rectangle bounds, PointF centerPos, double scale) { List <int> selectedID = new List <int>(); MyPoint xyCenter = ETCProjection.LngLat2XY(new MyPoint(centerPos.X, centerPos.Y)); double xmin = xyCenter.X - scale * bounds.Width / 2; double xmax = xyCenter.X + scale * bounds.Width / 2; double ymin = xyCenter.Y - scale * bounds.Height / 2; double ymax = xyCenter.Y + scale * bounds.Height / 2; for (int i = 0; i < myPoints.Count; i++) { MyPoint xyProjection = ETCProjection.LngLat2XY(myPoints[i]); double xScreen = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin); double yScreen = bounds.Height - bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin); MyPoint screen = new MyPoint(xScreen, yScreen); myPoints[i].Selected = GeometryTools.IsPointInCircle(new MyPoint(mouseLocation.X, mouseLocation.Y), screen, margin); if (myPoints[i].Selected == true) { selectedID.Add(i); } } return(selectedID); }
/// <summary> /// 简单渲染时的绘制要素 /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> /// <param name="centerPos"></param> /// <param name="scale"></param> /// <param name="symbol"></param> internal override void DrawSpaceData(Graphics g, Rectangle bounds, PointF centerPos, double scale, Symbol symbol) { //选中要素的样式 Pen selectedPen = new Pen(Color.Cyan); selectedPen.Width = 2.5F; //从symbol中获取样式 PolygonSymbol ps = (PolygonSymbol)symbol; Pen mypen = ps.LineStyle.GetPen; Brush mybrush = new SolidBrush(ps.GetColor()); MyPoint xyCenter = ETCProjection.LngLat2XY(new MyPoint(centerPos.X, centerPos.Y)); double xmin = xyCenter.X - scale * bounds.Width / 2; double xmax = xyCenter.X + scale * bounds.Width / 2; double ymin = xyCenter.Y - scale * bounds.Height / 2; double ymax = xyCenter.Y + scale * bounds.Height / 2; for (int i = 0; i < polygons.Count; i++) { List <int> parts = new List <int>(polygons[i].firstIndex); parts.Add(polygons[i].PointCount); for (int k = 0; k < polygons[i].firstIndex.Length; k++) //对于每一个MultiPolygon的子多边形 { List <PointF> pointfs = new List <PointF>(); for (int j = parts[k]; j < parts[k + 1]; j++) { MyPoint xyProjection = ETCProjection.LngLat2XY(polygons[i].Points[j]); double xScreen = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin); double yScreen = bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin); PointF p = new PointF((float)xScreen, bounds.Height - (float)yScreen); pointfs.Add(p); } if (GeometryTools.IsPointsPartInRectangle(pointfs.ToArray(), new MyRectangle(bounds.X, bounds.Width, bounds.Y, bounds.Height)) == true) { g.DrawPolygon(mypen, pointfs.ToArray()); g.FillPolygon(mybrush, pointfs.ToArray()); } } } for (int i = 0; i < polygons.Count; i++) { if (polygons[i].Selected == true) { List <int> parts = new List <int>(polygons[i].firstIndex); parts.Add(polygons[i].PointCount); for (int k = 0; k < polygons[i].firstIndex.Length; k++) //对于每一个MultiPolygon的子多边形 { List <PointF> pointfs = new List <PointF>(); for (int j = parts[k]; j < parts[k + 1]; j++) { MyPoint xyProjection = ETCProjection.LngLat2XY(polygons[i].Points[j]); double xScreen = bounds.Width * (xyProjection.X - xmin) / (xmax - xmin); double yScreen = bounds.Height * (xyProjection.Y - ymin) / (ymax - ymin); PointF p = new PointF((float)xScreen, bounds.Height - (float)yScreen); pointfs.Add(p); } if (GeometryTools.IsPointsPartInRectangle(pointfs.ToArray(), new MyRectangle(bounds.X, bounds.Width, bounds.Y, bounds.Height)) == true) { g.DrawPolygon(selectedPen, pointfs.ToArray()); //画选中多边形的轮廓 } } } } }