//采用简单线符号绘制复合折线 private static void DrawMultiPolylineBySimpleLine(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moMultiPolyline multiPolyline, moSimpleLineSymbol symbol) { double sOffsetX = extent.MinX, sOffsetY = extent.MaxY; //获取投影坐标系相对屏幕坐标系的平移量 //(1)转换为屏幕坐标 Int32 sPartCount = multiPolyline.Parts.Count; //简单折线的数目 GraphicsPath sGraphicPath = new GraphicsPath(); //定义复合多边形,用于屏幕绘制 for (Int32 i = 0; i <= sPartCount - 1; i++) { Int32 sPointCount = multiPolyline.Parts.GetItem(i).Count; //当前简单折线的顶点数目 PointF[] sScreenPoints = new PointF[sPointCount]; for (Int32 j = 0; j <= sPointCount - 1; j++) { PointF sScreenPoint = new PointF(); moPoint sCurPoint = multiPolyline.Parts.GetItem(i).GetItem(j); sScreenPoint.X = (float)((sCurPoint.X - sOffsetX) * mpu / mapScale * dpm); sScreenPoint.Y = (float)((sOffsetY - sCurPoint.Y) * mpu / mapScale * dpm); sScreenPoints[j] = sScreenPoint; } sGraphicPath.AddLines(sScreenPoints); sGraphicPath.StartFigure(); } //(2)绘制 Pen sPen = new Pen(symbol.Color, (float)(symbol.Size / 1000 * dpm)); sPen.DashStyle = (DashStyle)symbol.Style; g.DrawPath(sPen, sGraphicPath); sPen.Dispose(); }
public moFeature Clone() { moGeometryTypeConstant sShapeType = _ShapeType; moGeometry sGeometry = null; moAttributes sAttributes = _Attributes.Clone(); if (_ShapeType == moGeometryTypeConstant.Point) { moPoint sPoint = (moPoint)_Geometry; sGeometry = sPoint.Clone(); } else if (_ShapeType == moGeometryTypeConstant.MultiPolyline) { moMultiPolyline sMultiPolyline = (moMultiPolyline)_Geometry; sGeometry = sMultiPolyline.Clone(); } else if (_ShapeType == moGeometryTypeConstant.MultiPolygon) { moMultiPolygon sMultiPolygon = (moMultiPolygon)_Geometry; sGeometry = sMultiPolygon.Clone(); } moFeature sFeature = new moFeature(sShapeType, sGeometry, sAttributes); return(sFeature); }
internal static void DrawGeometry(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moGeometry geometry, moSymbol symbol) { if (extent == null) { return; } if (geometry == null) { return; } if (symbol == null) { return; } if (geometry.GetType() == typeof(moPoint)) { moPoint sPoint = (moPoint)geometry; DrawPoint(g, extent, mapScale, dpm, mpu, sPoint, symbol); } else if (geometry.GetType() == typeof(moMultiPolyline)) { moMultiPolyline sMultiPolyline = (moMultiPolyline)geometry; DrawMultiPolyline(g, extent, mapScale, dpm, mpu, sMultiPolyline, symbol); } else if (geometry.GetType() == typeof(moMultiPolygon)) { moMultiPolygon sMultiPolygon = (moMultiPolygon)geometry; DrawMultiPolygon(g, extent, mapScale, dpm, mpu, sMultiPolygon, symbol); } }
/// <summary> /// /// </summary> /// <param name="selectingBox"></param> /// <returns></returns> private moFeatures SearchFeaturesByBox(moRectangle selectingBox) { moFeatures sSelectedFeatures = new moFeatures(); Int32 sFeatureCount = _Features.Count; for (Int32 i = 0; i <= sFeatureCount - 1; i++) { if (_ShapeType == moGeometryTypeConstant.Point) { moPoint sPoint = (moPoint)_Features.GetItem(i).Geometry; if (moMapTools.IsPointWithinBox(sPoint, selectingBox) == true) { sSelectedFeatures.Add(_Features.GetItem(i)); } } else if (_ShapeType == moGeometryTypeConstant.MultiPolyline) { moMultiPolyline sMultiPolyline = (moMultiPolyline)_Features.GetItem(i).Geometry; if (moMapTools.IsMultiPolylinePartiallyWithinBox(sMultiPolyline, selectingBox) == true) { sSelectedFeatures.Add(_Features.GetItem(i)); } } else if (_ShapeType == moGeometryTypeConstant.MultiPolygon) { moMultiPolygon sMultiPolygon = (moMultiPolygon)_Features.GetItem(i).Geometry; if (moMapTools.IsMultiPolygonPartiallyWithinBox(sMultiPolygon, selectingBox) == true) { sSelectedFeatures.Add(_Features.GetItem(i)); } } } return(sSelectedFeatures); }
/// <summary> /// 根据指定点搜索要素 /// </summary> /// <param name="point"></param> /// <param name="tolerance"></param> /// <returns></returns> public moFeatures SearchFeaturesByPoint(moPoint point, double tolerance) { moFeatures sSelectedFeatures = new moFeatures(); Int32 sFeatureCount = _Features.Count; for (Int32 i = 0; i <= sFeatureCount - 1; i++) { if (_ShapeType == moGeometryTypeConstant.Point) { moPoint sPoint = (moPoint)_Features.GetItem(i).Geometry; if (moMapTools.IsPointOnPoint(point, sPoint, tolerance) == true) { sSelectedFeatures.Add(_Features.GetItem(i)); } } else if (_ShapeType == moGeometryTypeConstant.MultiPolyline) { moMultiPolyline sMultiPolyline = (moMultiPolyline)_Features.GetItem(i).Geometry; if (moMapTools.IsPointOnMultiPolyline(point, sMultiPolyline, tolerance) == true) { sSelectedFeatures.Add(_Features.GetItem(i)); } } else if (_ShapeType == moGeometryTypeConstant.MultiPolygon) { moMultiPolygon sMultiPolygon = (moMultiPolygon)_Features.GetItem(i).Geometry; if (moMapTools.IsPointWithinMultiPolygon(point, sMultiPolygon) == true) { sSelectedFeatures.Add(_Features.GetItem(i)); } } } return(sSelectedFeatures); }
/// <summary> /// 复制 /// </summary> /// <returns></returns> public moMultiPolyline Clone() { moMultiPolyline sMultiPolyline = new moMultiPolyline(); sMultiPolyline.Parts = _Parts.Clone(); sMultiPolyline._MinX = _MinX; sMultiPolyline._MaxX = _MaxX; sMultiPolyline._MinY = _MinY; sMultiPolyline._MaxY = _MaxY; return(sMultiPolyline); }
/// <summary> /// 指示指定复合折线是否部分或完全位于指定矩形盒内 /// </summary> /// <param name="multipolyline"></param> /// <param name="box"></param> /// <returns></returns> public static bool IsMultiPolylinePartiallyWithinBox(moMultiPolyline multipolyline, moRectangle box) { //思路:先判断矩形盒是否相交,如是,按如下顺序,满足任何一个条件,则返回True //(1)复合折线任何一个点位于矩形盒内; //(2)矩形盒与复合折线有交点 moRectangle sBox = multipolyline.GetEnvelope(); if (AreBoxesCross(sBox, box) == false) { return(false); } //(1)复合折线任何一个点位于矩形盒内; Int32 sPartCount = multipolyline.Parts.Count; for (Int32 i = 0; i <= sPartCount - 1; i++) { Int32 sPointCount = multipolyline.Parts.GetItem(i).Count; for (Int32 j = 0; j <= sPointCount - 1; j++) { moPoint sCurPoint = multipolyline.Parts.GetItem(i).GetItem(j); if (IsPointWithinBox(sCurPoint, box) == true) { return(true); } } } //(2)矩形盒与复合折线有交点 for (Int32 i = 0; i <= sPartCount - 1; i++) { moPoints sPoints = multipolyline.Parts.GetItem(i); Int32 sPointCount = sPoints.Count; for (Int32 j = 0; j <= sPointCount - 2; j++) { if (IsSegmentCrossBox(sPoints.GetItem(j), sPoints.GetItem(j + 1), box) == true) { return(true); } } } //(3)都不满足,返回false return(false); }
/// <summary> /// 指示在指定容限下,指定点是否位于指定复合折线上 /// </summary> /// <param name="point"></param> /// <param name="multiPolyline"></param> /// <param name="tolerance"></param> /// <returns></returns> public static bool IsPointOnMultiPolyline(moPoint point, moMultiPolyline multiPolyline, double tolerance) { moRectangle sBox = new moRectangle(multiPolyline.MinX - tolerance, multiPolyline.MaxX + tolerance, multiPolyline.MinY - tolerance, multiPolyline.MaxY + tolerance); if (IsPointWithinBox(point, sBox) == false) { return(false); } Int32 sPartCount = multiPolyline.Parts.Count; for (Int32 i = 0; i <= sPartCount - 1; i++) { if (IsPointOnPolyline(point, multiPolyline.Parts.GetItem(i), tolerance) == true) { return(true); } } return(false); }
/// <summary> /// 获取外包矩形 /// </summary> /// <returns></returns> public moRectangle GetEnvelope() { moRectangle sRect = null; if (_ShapeType == moGeometryTypeConstant.Point) { moPoint sPoint = (moPoint)_Geometry; sRect = new moRectangle(sPoint.X, sPoint.X, sPoint.Y, sPoint.Y); } else if (_ShapeType == moGeometryTypeConstant.MultiPolyline) { moMultiPolyline sMultiPolyline = (moMultiPolyline)_Geometry; sRect = sMultiPolyline.GetEnvelope(); } else { moMultiPolygon sMultiPolygon = (moMultiPolygon)_Geometry; sRect = sMultiPolygon.GetEnvelope(); } return(sRect); }
private void MFlashControler_NeedDrawFlashShapes(object sender, moShape[] shapes) { double sMapScale = mMapDrawingReference.MapScale; double dpm = mMapDrawingReference.dpm; double mpu = mMapDrawingReference.mpu; moRectangle sExtent = GetExtent(); Graphics g = Graphics.FromImage(mBufferMap2); Int32 sShapeCount = shapes.Length; for (Int32 i = 0; i <= sShapeCount - 1; i++) { if (shapes[i].GetType() == typeof(moPoint)) { moPoint sPoint = (moPoint)shapes[i]; moMapDrawingTools.DrawPoint(g, sExtent, sMapScale, dpm, mpu, sPoint, mFlashPointSymbol); } else if (shapes[i].GetType() == typeof(moPoints)) { moPoints sPoints = (moPoints)shapes[i]; moMapDrawingTools.DrawPoints(g, sExtent, sMapScale, dpm, mpu, sPoints, mFlashPointSymbol); } else if (shapes[i].GetType() == typeof(moRectangle)) { moRectangle sRect = (moRectangle)shapes[i]; moMapDrawingTools.DrawRectangle(g, sExtent, sMapScale, dpm, mpu, sRect, mFlashFillSymbol); } else if (shapes[i].GetType() == typeof(moMultiPolyline)) { moMultiPolyline sMultiPolyline = (moMultiPolyline)shapes[i]; moMapDrawingTools.DrawMultiPolyline(g, sExtent, sMapScale, dpm, mpu, sMultiPolyline, mFlashLineSymbol); } else if (shapes[i].GetType() == typeof(moMultiPolygon)) { moMultiPolygon sMultiPolygon = (moMultiPolygon)shapes[i]; moMapDrawingTools.DrawMultiPolygon(g, sExtent, sMapScale, dpm, mpu, sMultiPolygon, mFlashFillSymbol); } } g.Dispose(); Refresh(); }
//绘制复合折线 internal static void DrawMultiPolyline(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moMultiPolyline multiPolyline, moSymbol symbol) { if (symbol.SymbolType == moSymbolTypeConstant.SimpleLineSymbol) { moSimpleLineSymbol sSymbol = (moSimpleLineSymbol)symbol; if (sSymbol.Visible == true) { DrawMultiPolylineBySimpleLine(g, extent, mapScale, dpm, mpu, multiPolyline, sSymbol); } } }
/// <summary> /// 以指定符号绘制指定复合折线 /// </summary> /// <param name="multiPolyline"></param> /// <param name="symbol"></param> public void DrawMultiPolyline(moMultiPolyline multiPolyline, moSymbol symbol) { moMapDrawingTools.DrawMultiPolyline(_MyGraphics, _Extent, _MapScale, _dpm, _mpu, multiPolyline, symbol); }
/// <summary> /// 绘制所有注记 /// </summary> /// <param name="g"></param> /// <param name="extent"></param> /// <param name="mapScale"></param> /// <param name="dpm"></param> /// <param name="mpu"></param> /// <param name="placedLabelExtents"></param> internal void DrawLabels(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, List <RectangleF> placedLabelExtents) { if (_LabelRenderer == null) { return; } if (_LabelRenderer.LabelFeatures == false) { return; } Int32 sFieldIndex = _AttributeFields.FindField(_LabelRenderer.Field); if (sFieldIndex < 0) { return; } Int32 sFeatureCount = _Features.Count; for (Int32 i = 0; i <= sFeatureCount - 1; i++) { moFeature sFeature = _Features.GetItem(i); if (IsFeatureInExtent(sFeature, extent) == false) { //要素不位于显示范围内,不显示注记 continue; } if (sFeature.Symbol == null) { //要素没有配置符号,不显示注记 continue; } if (IsFeatureSymbolVisible(sFeature) == false) { //要素符号不可见,自然就不显示注记 continue; } string sLabelText = GetValueString(sFeature.Attributes.GetItem(sFieldIndex)); if (sLabelText == string.Empty) { //注记文本为空,不显示注记 continue; } //根据要素几何类型采用相应的配置方案 if (sFeature.ShapeType == moGeometryTypeConstant.Point) { //点要素,取点的右上为定位点,但要考虑点符号的大小 //(1)复制符号 moTextSymbol sTextSymbol; //最终绘制注记所采用的符号 sTextSymbol = _LabelRenderer.TextSymbol.Clone(); //复制符号 //(2)计算定位点并设置符号 PointF sSrcLabelPoint; //定位点的屏幕坐标 moPoint sPoint = (moPoint)sFeature.Geometry; PointF sSrcPoint = FromMapPoint(extent, mapScale, dpm, mpu, sPoint); //点要素的屏幕坐标 moSimpleMarkerSymbol sMarkerSymbol = (moSimpleMarkerSymbol)sFeature.Symbol; float sSymbolSize = (float)(sMarkerSymbol.Size / 1000 * dpm); //符号的屏幕尺寸 //右上方并设置符号 sSrcLabelPoint = new PointF(sSrcPoint.X + sSymbolSize / 2, sSrcPoint.Y - sSymbolSize / 2); sTextSymbol.Alignment = moTextSymbolAlignmentConstant.BottomLeft; //(3)计算注记的屏幕范围矩形 RectangleF sLabelExtent = GetLabelExtent(g, dpm, sSrcLabelPoint, sLabelText, sTextSymbol); //(4)冲突检测 if (HasConflict(sLabelExtent, placedLabelExtents) == false) { //没有冲突,则绘制并将当前注记范围矩形加入placedLabelExtents moMapDrawingTools.DrawLabel(g, dpm, sLabelExtent.Location, sLabelText, sTextSymbol); placedLabelExtents.Add(sLabelExtent); } } else if (sFeature.ShapeType == moGeometryTypeConstant.MultiPolyline) { //线要素,为每个部分的中点配置一个注记 //(1)获取符号,线要素无需复制符号 moTextSymbol sTextSymbol = _LabelRenderer.TextSymbol; //(2)对每个部分进行配置 moMultiPolyline sMultiPolyline = (moMultiPolyline)sFeature.Geometry; Int32 sPartCount = sMultiPolyline.Parts.Count; for (Int32 j = 0; j <= sPartCount - 1; j++) { //获取注记 moPoint sMapLabelPoint = moMapTools.GetMidPointOfPolyline(sMultiPolyline.Parts.GetItem(j)); PointF sSrcLabelPoint = FromMapPoint(extent, mapScale, dpm, mpu, sMapLabelPoint); //计算注记的屏幕范围矩形 RectangleF sLabelExtent = GetLabelExtent(g, dpm, sSrcLabelPoint, sLabelText, _LabelRenderer.TextSymbol); //冲突检测 if (HasConflict(sLabelExtent, placedLabelExtents) == false) { //没有冲突,则绘制并将当前注记范围矩形加入placedLabelExtents moMapDrawingTools.DrawLabel(g, dpm, sLabelExtent.Location, sLabelText, sTextSymbol); placedLabelExtents.Add(sLabelExtent); } } } else if (sFeature.ShapeType == moGeometryTypeConstant.MultiPolygon) { //面要素,为面积最大的外环及其内环所构成的多边形配置一个注记 //(1)获取符号,面要素无需复制符号 moTextSymbol sTextSymbol = _LabelRenderer.TextSymbol; //(2)获取注记点 moMultiPolygon sMultiPolygon = (moMultiPolygon)sFeature.Geometry; moPoint sMapLabelPoint = moMapTools.GetLabelPointOfMultiPolygon(sMultiPolygon); PointF sSrcLabelPoint = FromMapPoint(extent, mapScale, dpm, mpu, sMapLabelPoint); //(3)计算注记的屏幕范围矩形 RectangleF sLabelExtent = GetLabelExtent(g, dpm, sSrcLabelPoint, sLabelText, _LabelRenderer.TextSymbol); //(4)冲突检测 if (HasConflict(sLabelExtent, placedLabelExtents) == false) { //没有冲突,则绘制并将当前注记范围矩形加入placedLabelExtents moMapDrawingTools.DrawLabel(g, dpm, sLabelExtent.Location, sLabelText, sTextSymbol); placedLabelExtents.Add(sLabelExtent); } } else { throw new Exception("Invalid shape type!"); } } }