/// <summary> /// 获取地图窗口对应的地图范围(地图坐标) /// </summary> /// <returns></returns> public moRectangle GetExtent() { //定义变量 double sMinX = double.MaxValue, sMaxX = double.MinValue; double sMinY = double.MaxValue, sMaxY = double.MinValue; moRectangle sExtent; //如果工作区为空,则返回空矩形 Rectangle sClientRect = this.ClientRectangle; if (sClientRect.IsEmpty == true) { sExtent = new moRectangle(sMinX, sMaxX, sMinY, sMaxY); return(sExtent); } //定义工作区左上点和右下点的屏幕坐标 moPoint sTopLeftScreenPoint = new moPoint(0, 0); moPoint sBottomRightScreenPoint = new moPoint(sClientRect.Width, sClientRect.Height); //获取工作区左上点和右下点的地图坐标 moPoint sTopLeftMapPoint = mMapDrawingReference.ToMapPoint(sTopLeftScreenPoint.X, sTopLeftScreenPoint.Y); moPoint sBottomRightMapPoint = mMapDrawingReference.ToMapPoint(sBottomRightScreenPoint.X, sBottomRightScreenPoint.Y); //定义范围矩形 sMinX = sTopLeftMapPoint.X; sMaxX = sBottomRightMapPoint.X; sMinY = sBottomRightMapPoint.Y; sMaxY = sTopLeftMapPoint.Y; sExtent = new moRectangle(sMinX, sMaxX, sMinY, sMaxY); return(sExtent); }
//采用简单线符号绘制复合折线 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(); }
/// <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); }
private void CalExtent() { double sMinX = Double.MaxValue; double sMaxX = Double.MinValue; double sMinY = Double.MaxValue; double sMaxY = Double.MinValue; Int32 sFeatureCount = _Features.Count; for (Int32 i = 0; i <= sFeatureCount - 1; i++) { moRectangle sExtent = _Features.GetItem(i).GetEnvelope(); if (sExtent.MinX < sMinX) { sMinX = sExtent.MinX; } if (sExtent.MaxX > sMaxX) { sMaxX = sExtent.MaxX; } if (sExtent.MinY < sMinY) { sMinY = sExtent.MinY; } if (sExtent.MaxY > sMaxY) { sMaxY = sExtent.MaxY; } } _Extent = new moRectangle(sMinX, sMaxX, sMinY, sMaxY); }
//采用简单填充符号绘制矩形 private static void DrawRectangleBySimpleFill(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moRectangle rectangle, moSimpleFillSymbol symbol) { double sOffsetX = extent.MinX, sOffsetY = extent.MaxY; //获取投影坐标系相对屏幕坐标系的平移量 //(1)转换为屏幕坐标并生成矩形 Point sTopLeftPoint = new Point(), sBottomRightPoint = new Point(); sTopLeftPoint.X = (Int32)((rectangle.MinX - sOffsetX) * mpu / mapScale * dpm); sTopLeftPoint.Y = (Int32)((sOffsetY - rectangle.MaxY) * mpu / mapScale * dpm); sBottomRightPoint.X = (Int32)((rectangle.MaxX - sOffsetX) * mpu / mapScale * dpm); sBottomRightPoint.Y = (Int32)((sOffsetY - rectangle.MinY) * mpu / mapScale * dpm); Int32 sWidth = sBottomRightPoint.X - sTopLeftPoint.X; Int32 sHeight = sBottomRightPoint.Y - sTopLeftPoint.Y; Rectangle sRect = new Rectangle(sTopLeftPoint.X, sTopLeftPoint.Y, sWidth, sHeight); //(2)填充 if (symbol.Color != Color.Transparent) { SolidBrush sBrush = new SolidBrush(symbol.Color); g.FillRectangle(sBrush, sRect); sBrush.Dispose(); } //(3)绘制边界 if (symbol.Outline.SymbolType == moSymbolTypeConstant.SimpleLineSymbol) { moSimpleLineSymbol sOutline = symbol.Outline; if (sOutline.Visible == true) { Pen sPen = new Pen(sOutline.Color, (float)(sOutline.Size / 1000 * dpm)); sPen.DashStyle = (DashStyle)sOutline.Style; g.DrawRectangle(sPen, sRect); sPen.Dispose(); } } }
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); } }
private double _mpu = 1.0; //1个地图坐标单位代表的米数,一般为1. #endregion #region 构造函数 internal moUserDrawingTool(Graphics graphics, moRectangle extent, double mapScale, double dpm, double mpu) { _MyGraphics = graphics; _Extent = extent; _MapScale = mapScale; _dpm = dpm; _mpu = mpu; }
//将地图坐标转换为屏幕坐标 private PointF FromMapPoint(moRectangle extent, double mapScale, double dpm, double mpu, moPoint point) { double sOffsetX = extent.MinX, sOffsetY = extent.MaxY; //获取地图坐标系相对屏幕坐标系的平移量 PointF sPoint = new PointF(); //屏幕坐标 sPoint.X = (float)((point.X - sOffsetX) * mpu / mapScale * dpm); sPoint.Y = (float)((sOffsetY - point.Y) * mpu / mapScale * dpm); return(sPoint); }
/// <summary> /// 新建一个绘图工具 /// </summary> /// <returns></returns> private moUserDrawingTool CreateDrawingTool(Graphics graphics) { moRectangle sExtent = GetExtent(); double sMapScale = mMapDrawingReference.MapScale; double dpm = mMapDrawingReference.dpm; double mpu = mMapDrawingReference.mpu; moUserDrawingTool sDrawingTool = new moUserDrawingTool(graphics, sExtent, sMapScale, dpm, mpu); return(sDrawingTool); }
//绘制矩形 internal static void DrawRectangle(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moRectangle rectangle, moSymbol symbol) { if (symbol.SymbolType == moSymbolTypeConstant.SimpleFillSymbol) { moSimpleFillSymbol sSymbol = (moSimpleFillSymbol)symbol; if (sSymbol.Visible == true) { DrawRectangleBySimpleFill(g, extent, mapScale, dpm, mpu, rectangle, sSymbol); } } }
/// <summary> /// 指示指定点是否位于指定矩形盒内 /// </summary> /// <param name="point"></param> /// <param name="box"></param> /// <returns></returns> public static bool IsPointWithinBox(moPoint point, moRectangle box) { if (point.X >= box.MinX && point.X <= box.MaxX && point.Y >= box.MinY && point.Y <= box.MaxY) { return(true); } else { return(false); } }
//绘制线段 internal static void DrawLine(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moPoint point1, moPoint point2, moSymbol symbol) { if (symbol.SymbolType == moSymbolTypeConstant.SimpleLineSymbol) { moSimpleLineSymbol sSymbol = (moSimpleLineSymbol)symbol; if (sSymbol.Visible == true) { DrawLineBySimpleLine(g, extent, mapScale, dpm, mpu, point1, point2, sSymbol); } } }
/// <summary> /// 指示指定线段是否与指定矩形盒相交 /// </summary> /// <param name="sPoint"></param> /// <param name="ePoint"></param> /// <param name="box"></param> /// <returns></returns> internal static bool IsSegmentCrossBox(moPoint sPoint, moPoint ePoint, moRectangle box) { //先判断线段两个端点是否全部位于矩形盒某条边的外侧,如是,则返回False if (sPoint.X < box.MinX && ePoint.X < box.MinX) { //两个端点位于矩形左边的外侧 return(false); } if (sPoint.X > box.MaxX && ePoint.X > box.MaxX) { //两个端点位于矩形右边的外侧 return(false); } if (sPoint.Y < box.MinY && ePoint.Y < box.MinY) { //两个端点位于矩形底边的外侧 return(false); } if (sPoint.Y > box.MaxY && ePoint.Y > box.MaxY) { //两个端点位于矩形上边的外侧 return(false); } //定义四个顶点 moPoint sPoint1 = new moPoint(box.MinX, box.MaxY); //矩形左上点 moPoint sPoint2 = new moPoint(box.MaxX, box.MaxY); //矩形右上点 moPoint sPoint3 = new moPoint(box.MaxX, box.MinY); //矩形右下点 moPoint sPoint4 = new moPoint(box.MinX, box.MinY); //矩形左下点 //将每条边与线段求交 if (AreSegmentsCross(sPoint, ePoint, sPoint1, sPoint2) == true) { //与上边有交点 return(true); } if (AreSegmentsCross(sPoint, ePoint, sPoint3, sPoint4) == true) { //与下边有交点 return(true); } if (AreSegmentsCross(sPoint, ePoint, sPoint1, sPoint4) == true) { //与左边有交点 return(true); } if (AreSegmentsCross(sPoint, ePoint, sPoint2, sPoint3) == true) { //与右边有交点 return(true); } return(false); }
/// <summary> /// 绘制所有选择要素 /// </summary> /// <param name="g"></param> /// <param name="extent"></param> /// <param name="mapScale"></param> /// <param name="dpm"></param> /// <param name="mpu"></param> /// <param name="symbol"></param> internal void DrawSelectedFeatures(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moSymbol symbol) { //判断是否位于绘制范围内,不是,则绘制 Int32 sFeatureCount = _SelectedFeatures.Count; for (Int32 i = 0; i < sFeatureCount; i++) { moFeature sFeature = _SelectedFeatures.GetItem(i); if (IsFeatureInExtent(sFeature, extent) == true) { moGeometry sGeometry = sFeature.Geometry; moMapDrawingTools.DrawGeometry(g, extent, mapScale, dpm, mpu, sGeometry, symbol); } } }
/// <summary> /// 指示两个矩形盒是否相交 /// </summary> /// <param name="box1"></param> /// <param name="box2"></param> internal static bool AreBoxesCross(moRectangle box1, moRectangle box2) { if (box1.MinX > box2.MaxX || box1.MaxX < box2.MinX) { return(false); } else if (box1.MinY > box2.MaxY || box1.MaxY < box2.MinY) { return(false); } else { return(true); } }
//绘制点集合(多点) internal static void DrawPoints(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moPoints points, moSymbol symbol) { if (symbol.SymbolType == moSymbolTypeConstant.SimpleMarkerSymbol) { moSimpleMarkerSymbol sSymbol = (moSimpleMarkerSymbol)symbol; if (sSymbol.Visible == true) { Int32 sPointCount = points.Count; for (Int32 i = 0; i <= sPointCount - 1; i++) { moPoint sPoint = points.GetItem(i); DrawPointBySimpleMarker(g, extent, mapScale, dpm, mpu, sPoint, sSymbol); } } } }
private void DrawBufferMap2() { //(1)获取地图窗口的范围 moRectangle sExtent = GetExtent(); if (sExtent.IsEmpty == true) { return; } //(2)绘制缓冲位图1 Graphics g = Graphics.FromImage(mBufferMap2); g.Clear(Color.White); Rectangle sRect = new Rectangle(0, 0, mBufferMap1.Width, mBufferMap1.Height); g.DrawImage(mBufferMap1, sRect, sRect, GraphicsUnit.Pixel); //(3)绘制所有图层的选择要素,采用倒序 double sMapScale = mMapDrawingReference.MapScale; double dpm = mMapDrawingReference.dpm; double mpu = mMapDrawingReference.mpu; Int32 sLayerCount = _Layers.Count; for (Int32 i = sLayerCount - 1; i >= 0; i--) { moMapLayer sLayer = _Layers.GetItem(i); if (sLayer.ShapeType == moGeometryTypeConstant.Point) { sLayer.DrawSelectedFeatures(g, sExtent, sMapScale, dpm, mpu, mSelectedPointSymbol); } else if (sLayer.ShapeType == moGeometryTypeConstant.MultiPolyline) { sLayer.DrawSelectedFeatures(g, sExtent, sMapScale, dpm, mpu, mSelectedLineSymbol); } else if (sLayer.ShapeType == moGeometryTypeConstant.MultiPolygon) { sLayer.DrawSelectedFeatures(g, sExtent, sMapScale, dpm, mpu, mSelectedFillSymbol); } } //(4)触发事件,以便用户程序继续绘图 if (AfterTrackingLayerDraw != null) { //新建绘图工具 moUserDrawingTool sDrawingTool = CreateDrawingTool(g); AfterTrackingLayerDraw(this, sDrawingTool); } g.Dispose(); }
/// <summary> /// 在窗口内显示指定范围(框选放大缩小) /// </summary> /// <param name="extent"></param> public void ZoomToExtent(moRectangle extent) { double sWindowWidth = this.ClientRectangle.Width; double sWindowHeight = this.ClientRectangle.Height; mMapDrawingReference.ZoomExtentToWindow(extent, sWindowWidth, sWindowHeight); this.UseWaitCursor = true; DrawBufferMap1(); DrawBufferMap2(); this.UseWaitCursor = false; Refresh(); //触发事件 if (MapScaleChanged != null) { MapScaleChanged(this); } }
/// <summary> /// 指定要素是否位于指定范围内,这里仅计算要素的外包矩形与范围举行是否相交,判断是否需要绘制 /// </summary> /// <param name="feature"></param> /// <param name="extent"></param> /// <returns></returns> private bool IsFeatureInExtent(moFeature feature, moRectangle extent) { moRectangle sRect = feature.GetEnvelope(); if (sRect.MaxX < extent.MinX || sRect.MinX > extent.MaxX) { return(false); } else if (sRect.MaxY < extent.MinY || sRect.MinY > extent.MaxY) { return(false); } else { return(true); } }
/// <summary> /// 根据矩形盒执行搜索,返回选中的要素集合 /// </summary> /// <param name="selectionBox"></param> /// <param name="tolerance"></param> /// <returns></returns> public moFeatures SearchByBox(moRectangle selectingBox, double tolerance) { //说明:仅考虑一种选择模式 moFeatures sSelection = null; if (selectingBox.Width == 0 && selectingBox.Height == 0) { //点选 moPoint sSelectingPoint = new moPoint(selectingBox.MinX, selectingBox.MinY); sSelection = SearchFeaturesByPoint(sSelectingPoint, tolerance); } else { //框选 sSelection = SearchFeaturesByBox(selectingBox); } return(sSelection); }
/// <summary> /// 根据指定的选择盒与选择方法执行选择 /// </summary> /// <param name="selectingBox"></param> /// <param name="tolerance"></param> /// <param name="selectMethod"></param> public void SelectByBox(moRectangle selectingBox, double tolerance, Int32 selectMethod) { Int32 sLayerCount = _Layers.Count; for (Int32 i = 0; i < sLayerCount; i++) { moMapLayer sLayer = _Layers.GetItem(i); if (sLayer.Visible == true && sLayer.Selectable == true) { moFeatures sFeatures = sLayer.SearchByBox(selectingBox, tolerance); sLayer.ExecuteSelect(sFeatures, selectMethod); } else { sLayer.SelectedFeatures.Clear(); } } }
/// <summary> /// 绘制所有要素 /// </summary> /// <param name="g">绘图对象</param> /// <param name="extent">绘制范围(地图坐标)</param> /// <param name="mapScale">地图比例尺的倒数</param> /// <param name="dpm">每米对应的点数</param> /// <param name="mpu">地图坐标单位对应的米数</param> internal void DrawFeatures(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu) { //(1)为所有要素配置符号 SetFeatureSymbols(); //(2)判断是否位于绘制范围内,如是,则绘制 Int32 sFeatureCount = _Features.Count; for (Int32 i = 0; i < sFeatureCount; i++) { moFeature sFeature = _Features.GetItem(i); if (IsFeatureInExtent(sFeature, extent) == true) { moGeometry sGeometry = sFeature.Geometry; moSymbol sSymbol = sFeature.Symbol; moMapDrawingTools.DrawGeometry(g, extent, mapScale, dpm, mpu, sGeometry, sSymbol); } } }
//采用简单线符号绘制线段 private static void DrawLineBySimpleLine(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moPoint point1, moPoint point2, moSimpleLineSymbol symbol) { double sOffsetX = extent.MinX, sOffsetY = extent.MaxY; //获取投影坐标系相对屏幕坐标系的平移量 //(1)转换为屏幕坐标 PointF sScreenPoint1 = new PointF(); PointF sScreenPoint2 = new PointF(); sScreenPoint1.X = (float)((point1.X - sOffsetX) * mpu / mapScale * dpm); sScreenPoint1.Y = (float)((sOffsetY - point1.Y) * mpu / mapScale * dpm); sScreenPoint2.X = (float)((point2.X - sOffsetX) * mpu / mapScale * dpm); sScreenPoint2.Y = (float)((sOffsetY - point2.Y) * mpu / mapScale * dpm); //(2)绘制 Pen sPen = new Pen(symbol.Color, (float)(symbol.Size / 1000 * dpm)); sPen.DashStyle = (DashStyle)symbol.Style; g.DrawLine(sPen, sScreenPoint1, sScreenPoint2); sPen.Dispose(); }
/// <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> /// <returns></returns> public moRectangle GetFullExtent() { //(1)新建一个空矩形 double sMinX = double.MaxValue, sMaxX = double.MinValue; double sMinY = double.MaxValue, sMaxY = double.MinValue; moRectangle sFullExtent; //(2)如果图层数量为0,则返回空矩形 Int32 sLayerCount = _Layers.Count; if (sLayerCount == 0) { sFullExtent = new moRectangle(sMinX, sMaxX, sMinY, sMaxY); return(sFullExtent); } //(3)计算范围矩形 for (Int32 i = 0; i <= sLayerCount - 1; i++) { moMapLayer sLayer = _Layers.GetItem(i); moRectangle sExtent = sLayer.Extent; if (sExtent.IsEmpty == false) { if (sExtent.MinX < sMinX) { sMinX = sExtent.MinX; } if (sExtent.MaxX > sMaxX) { sMaxX = sExtent.MaxX; } if (sExtent.MinY < sMinY) { sMinY = sExtent.MinY; } if (sExtent.MaxY > sMaxY) { sMaxY = sExtent.MaxY; } } } sFullExtent = new moRectangle(sMinX, sMaxX, sMinY, sMaxY); return(sFullExtent); }
/// <summary> /// 指示在指定容限下,指定点是否位于指定的折线上 /// </summary> /// <param name="point"></param> /// <param name="points"></param> /// <param name="tolerance"></param> /// <returns></returns> public static bool IsPointOnPolyline(moPoint point, moPoints points, double tolerance) { moRectangle sBox = new moRectangle(points.MinX - tolerance, points.MaxX + tolerance, points.MinY - tolerance, points.MaxY + tolerance); if (IsPointWithinBox(point, sBox) == false) { return(false); } Int32 sPointCount = points.Count; for (Int32 i = 0; i <= sPointCount - 2; i++) { if (GetDistanceFromPointToSegment(point.X, point.Y, points.GetItem(i).X, points.GetItem(i).Y, points.GetItem(i + 1).X, points.GetItem(i + 1).Y) <= tolerance) { return(true); } } return(false); }
/// <summary> /// 在窗口内显示地图全部范围 /// </summary> public void FullExtent() { moRectangle sFullExtent = GetFullExtent(); if (sFullExtent.IsEmpty == false) { Rectangle sClientRect = this.ClientRectangle; mMapDrawingReference.ZoomExtentToWindow(sFullExtent, sClientRect.Width, sClientRect.Height); this.UseWaitCursor = true; DrawBufferMap1(); DrawBufferMap2(); this.UseWaitCursor = false; Refresh(); //触发事件 if (MapScaleChanged != null) { MapScaleChanged(this); } } }
/// <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 static void DrawPointBySimpleMarker(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moPoint point, moSimpleMarkerSymbol symbol) { double sOffsetX = extent.MinX, sOffsetY = extent.MaxY; //获取投影坐标系相对屏幕坐标系的平移量 //(1)转换为屏幕坐标 PointF sScreenPoint = new PointF(); sScreenPoint.X = (float)((point.X - sOffsetX) * mpu / mapScale * dpm); sScreenPoint.Y = (float)((sOffsetY - point.Y) * mpu / mapScale * dpm); //(2)计算符号大小 float sSize = (float)(symbol.Size / 1000 * dpm); //符号大小,像素 if (sSize < 1) { sSize = 1; } //(3)定义绘制区域并绘制 Rectangle sDrawingArea = new Rectangle((Int32)(sScreenPoint.X - sSize / 2), (Int32)(sScreenPoint.Y - sSize / 2), (Int32)sSize, (Int32)sSize); DrawSimpleMarker(g, sDrawingArea, dpm, symbol); }