/** * 添加测量标记点 */ private void addMeasurePoint(GraphicsLayer gLayer, IGraphics graphics, List <Point> logPntArr) { if (IsDrawOver) { clearMeasurePnts(null, null, null); } IMSCircle pnt = new IMSCircle(CoordinateType.Logic); pnt.RadiusEx = 4; pnt.CenX = logPntArr[logPntArr.Count - 1].X; pnt.CenY = logPntArr[logPntArr.Count - 1].Y; m_graphicsLayer.AddGraphics(pnt); pnt.Draw(); this.measurePnts.Add(pnt); this.measurePntsTmp.Add(new Point(logPntArr[logPntArr.Count - 1].X, logPntArr[logPntArr.Count - 1].Y)); if (this.m_graphicsLayer.DrawingType == DrawingType.Polyline) { Label currmeasureLabel = new Label(); currmeasureLabel.Content = ""; currmeasureLabel.FontSize = 12; IMSMark currmeasureMark = new IMSMark(currmeasureLabel, CoordinateType.Logic); currmeasureMark.EnableDrag = false; currmeasureMark.EnableAnimation = false; mymarklayer.AddMark(currmeasureMark); measureMarks.Add(currmeasureMark); // (currmeasureMark.MarkControl as Label).Content = getLength(new Point(-1, -1)); ; string tollength = getCurrentLength(-1, -1, new Point(-1, -1)); measureleng += Convert.ToDouble(tollength.Split(':')[1]); currmeasureMark.X = logPntArr[logPntArr.Count - 1].X + 0.0055; currmeasureMark.Y = logPntArr[logPntArr.Count - 1].Y - 0.0055; Label centermeasureLabel = new Label(); centermeasureLabel.Content = ""; centermeasureLabel.FontSize = 12; IMSMark centermeasureMark = new IMSMark(centermeasureLabel, CoordinateType.Logic); centermeasureMark.EnableDrag = false; centermeasureMark.EnableAnimation = false; mymarklayer.AddMark(centermeasureMark); measureCenterMarks.Add(centermeasureMark); (centermeasureMark.MarkControl as Label).RenderTransform = new RotateTransform(); if ((bool)checkBox1.IsChecked) { if (centermeasureMark != null) { // centermeasureMark.Visibility = System.Windows.Visibility.Visible; } } else { if (centermeasureMark != null) { centermeasureMark.Visibility = System.Windows.Visibility.Collapsed; } } } this.m_mapContainer.MouseMove -= new MouseEventHandler(m_graphicsLayer_MouseMove); this.m_mapContainer.MouseMove += new MouseEventHandler(m_graphicsLayer_MouseMove); IsDrawOver = false; }
/** * 获取长度 */ public string getCurrentLength(int currentIdx, int lastIdx, Point currPnt) { double length = 0; if (currPnt.X == -1 && currPnt.Y == -1) { if (this.measurePnts.Count < 2) { return("线段长度:0"); } if (currentIdx == -1 && lastIdx == -1) { currentIdx = this.measurePnts.Count - 1; lastIdx = this.measurePnts.Count - 2; } if (currentIdx == 0) { lastIdx = 0; } IMSCircle pnt = this.measurePnts[currentIdx]; IMSCircle lastPnt = this.measurePnts[lastIdx]; length = Math.Sqrt(Math.Pow(pnt.CenX - lastPnt.CenX, 2) + Math.Pow(pnt.CenY - lastPnt.CenY, 2)); } else { if (this.measurePnts.Count < 1) { return("线段长度:0"); } IMSCircle lastPnt = this.measurePnts[this.measurePnts.Count - 1]; length = Math.Sqrt(Math.Pow(currPnt.X - lastPnt.CenX, 2) + Math.Pow(currPnt.Y - lastPnt.CenY, 2)); } return("线段长度:" + (length * this.unitLength).ToString()); }
/// <summary> /// 绘制圆 /// </summary> /// <param name="gLayer"></param> /// <param name="graphics"></param> /// <param name="logPntArr"></param> void circle(GraphicsLayer gLayer, IGraphics graphics, List <Point> logPntArr) { //定义圆对象,添加到绘图层 IMSCircle cir = new IMSCircle(CoordinateType.Logic); this.graphicsLayer.AddGraphics(cir); cir.Draw(logPntArr); }
void m_graphicsLayer_MouseMove(object sender, MouseEventArgs e) { Point pnt = e.GetPosition(this.m_mapContainer); Point logpnt = this.m_mapContainer.ScreenToLogic(pnt.X, pnt.Y); if (this.m_graphicsLayer.DrawingType == DrawingType.Polyline) { IMSMark centermeasureMark = this.measureCenterMarks[this.measureCenterMarks.Count - 1]; (centermeasureMark.MarkControl as Label).Content = getCurrentLength(-1, -1, logpnt); IMSCircle pntCircle = this.measurePnts[this.measurePnts.Count - 1]; centermeasureMark.X = (logpnt.X + 3 * pntCircle.CenX) / 4; centermeasureMark.Y = (logpnt.Y + 3 * pntCircle.CenY) / 4; Point scrPnt = this.m_mapContainer.LogicToScreen(pntCircle.CenX, pntCircle.CenY); double angle = Math.Atan2(scrPnt.Y - pnt.Y, pnt.X - scrPnt.X); ((centermeasureMark.MarkControl as Label).RenderTransform as RotateTransform).Angle = 360 - angle * 360 / (2 * Math.PI); if ((bool)checkBox1.IsChecked) { centermeasureMark.Visibility = System.Windows.Visibility.Visible; } else { centermeasureMark.Visibility = System.Windows.Visibility.Collapsed; } } if (this.measureMark == null) { Label measureLabel = new Label(); measureLabel.Content = ""; measureLabel.Name = "measureResultLabel"; measureLabel.FontSize = 12; this.measureMark = new IMSMark(measureLabel, CoordinateType.Logic); this.measureMark.EnableDrag = false; mymarklayer.AddMark(this.measureMark); } this.measureMark.X = logpnt.X + 0.0055; this.measureMark.Y = logpnt.Y - 0.0055; try { if (measureMark != null) { this.measureMark.Visibility = Visibility.Visible; } } catch { return; } (this.measureMark.MarkControl as Label).Content = this.m_graphicsLayer.DrawingType == DrawingType.Polyline ? getLength(logpnt) : getArea(logpnt); }
//将圆形区域添加到地图上 private void AddCircle() { cirObj = new Circle(); cirObj.Center = new Dot_2D(); cirObj.Center.x = 114.3041267836914; cirObj.Center.y = 30.651509197753906; cirObj.Radius = 0.004484101072174819; //在地图上显示圆形区域 Clipcir = new IMSCircle(CoordinateType.Logic); // cir.Stroke = new SolidColorBrush(Colors.Orange); Clipcir.StrokeThickness = 2; //设置圆心 Clipcir.CenX = cirObj.Center.x; Clipcir.CenY = cirObj.Center.y; //设置半径 Clipcir.Radius = cirObj.Radius; //绘制圆形 Clipcir.Draw(); m_gpLayer.AddGraphics(Clipcir); }
public string getLength(Point point) { if (this.measurePnts.Count < 1) { return("总长度:0"); } if (point.X == -1 && point.Y == -1) { if (this.measurePnts.Count != 1) { point = new Point(this.measurePnts[this.measurePnts.Count - 2].CenX, this.measurePnts[this.measurePnts.Count - 2].CenY); } else { point = new Point(this.measurePnts[this.measurePnts.Count - 1].CenX, this.measurePnts[this.measurePnts.Count - 1].CenY); } } IMSCircle pnt = this.measurePnts[this.measurePnts.Count - 1]; double length = Math.Sqrt(Math.Pow(pnt.CenX - point.X, 2) + Math.Pow(pnt.CenY - point.Y, 2)); return("总长度:" + (Convert.ToDouble(measureleng + length * this.unitLength)).ToString()); }
private void markLengthMove(int curEditMarkIndex, Shape curEditMark, List <Shape> editMarkList, GraphicsBase g) { this.m_graphicsLayer.Drawing += new DrawingEventHandler(addMeasurePoint); this.m_graphicsLayer.Drawing -= new DrawingEventHandler(addMeasurePoint); Point pnt = m_mapContainer.ScreenToLogic(Canvas.GetLeft(curEditMark), Canvas.GetTop(curEditMark)); if (measurePnts.Count >= curEditMarkIndex) { this.measurePnts[curEditMarkIndex].CenX = pnt.X; this.measurePnts[curEditMarkIndex].CenY = pnt.Y; } else { return; } IMSMark currmeasureMark = measureMarks[curEditMarkIndex]; double currLength = Convert.ToDouble(getCurrentLength(curEditMarkIndex, curEditMarkIndex - 1, new Point(-1, -1)).Split(':')[1]); if (currLength != 0) { IMSMark lastmeasureMark = measureMarks[curEditMarkIndex - 1]; currLength += Convert.ToDouble((lastmeasureMark.MarkControl as Label).Content.ToString().Split(':')[1]); } (currmeasureMark.MarkControl as Label).Content = "总长度:" + currLength.ToString(); currmeasureMark.X = pnt.X + 0.0055; currmeasureMark.Y = pnt.Y - 0.0055; if (curEditMarkIndex != 0) { IMSMark centermeasureMark = this.measureCenterMarks[curEditMarkIndex - 1]; (centermeasureMark.MarkControl as Label).Content = getCurrentLength(curEditMarkIndex, curEditMarkIndex - 1, new Point(-1, -1)); IMSCircle pntCircle = this.measurePnts[curEditMarkIndex - 1]; centermeasureMark.X = (pnt.X + 3 * pntCircle.CenX) / 4; centermeasureMark.Y = (pnt.Y + 3 * pntCircle.CenY) / 4; Point scrPnt = this.m_mapContainer.LogicToScreen(pntCircle.CenX, pntCircle.CenY); double angle = Math.Atan2(scrPnt.Y - Canvas.GetTop(curEditMark), Canvas.GetLeft(curEditMark) - scrPnt.X); ((centermeasureMark.MarkControl as Label).RenderTransform as RotateTransform).Angle = 360 - angle * 360 / (2 * Math.PI); if ((bool)checkBox1.IsChecked) { centermeasureMark.Visibility = System.Windows.Visibility.Visible; } else { centermeasureMark.Visibility = System.Windows.Visibility.Collapsed; } } if (curEditMarkIndex < this.measureCenterMarks.Count) { IMSMark centermeasureMark = this.measureCenterMarks[curEditMarkIndex]; (centermeasureMark.MarkControl as Label).Content = getCurrentLength(curEditMarkIndex + 1, curEditMarkIndex, new Point(-1, -1)); IMSCircle pntCircle = this.measurePnts[curEditMarkIndex + 1]; centermeasureMark.X = (3 * pnt.X + pntCircle.CenX) / 4; centermeasureMark.Y = (3 * pnt.Y + pntCircle.CenY) / 4; Point scrPnt = this.m_mapContainer.LogicToScreen(pntCircle.CenX, pntCircle.CenY); double angle = Math.Atan2(Canvas.GetTop(curEditMark) - scrPnt.Y, scrPnt.X - Canvas.GetLeft(curEditMark)); ((centermeasureMark.MarkControl as Label).RenderTransform as RotateTransform).Angle = 360 - angle * 360 / (2 * Math.PI); if ((bool)checkBox1.IsChecked) { if (centermeasureMark != null) { centermeasureMark.Visibility = System.Windows.Visibility.Visible; } } else { if (centermeasureMark != null) { centermeasureMark.Visibility = System.Windows.Visibility.Collapsed; } } } for (int i = curEditMarkIndex; i < this.measureMarks.Count - 1; i++) { IMSMark nextmeasureMark = measureMarks[i + 1]; double nextLegth = Convert.ToDouble(getCurrentLength(i + 1, i, new Point(-1, -1)).Split(':')[1]); currLength += nextLegth; (nextmeasureMark.MarkControl as Label).Content = "总长度:" + currLength.ToString(); } }
private void mark2LengthOver(int curEditMarkIndex, Shape curEditMark, List <Shape> editMarkList, GraphicsBase g) { this.m_graphicsLayer.Drawing += new DrawingEventHandler(addMeasurePoint); Point pnt = m_mapContainer.ScreenToLogic(Canvas.GetLeft(g.EditMark1List[curEditMarkIndex + 1]), Canvas.GetTop(g.EditMark1List[curEditMarkIndex + 1])); IMSCircle circle = new IMSCircle(); circle.CenX = pnt.X; circle.CenY = pnt.Y; this.measurePnts.Insert(curEditMarkIndex + 1, circle); double currLength = 0; Label currmeasureLabel = new Label(); currmeasureLabel.Content = ""; currmeasureLabel.FontSize = 12; IMSMark currmeasureMark = new IMSMark(currmeasureLabel, CoordinateType.Logic); currmeasureMark.EnableDrag = false; mymarklayer.AddMark(currmeasureMark); measureMarks.Insert(curEditMarkIndex + 1, currmeasureMark); currmeasureMark.X = pnt.X + 0.0055; currmeasureMark.Y = pnt.Y - 0.0055; IMSMark lastmeasureMark = measureMarks[curEditMarkIndex]; currLength += Convert.ToDouble((lastmeasureMark.MarkControl as Label).Content.ToString().Split(':')[1]); IMSMark centermeasureMark = this.measureCenterMarks[curEditMarkIndex]; (centermeasureMark.MarkControl as Label).Content = getCurrentLength(curEditMarkIndex + 1, curEditMarkIndex, new Point(-1, -1)); IMSCircle pntCircle = this.measurePnts[curEditMarkIndex]; centermeasureMark.X = (pnt.X + 3 * pntCircle.CenX) / 4; centermeasureMark.Y = (pnt.Y + 3 * pntCircle.CenY) / 4; Point scrPnt = this.m_mapContainer.LogicToScreen(pntCircle.CenX, pntCircle.CenY); double angle = Math.Atan2(scrPnt.Y - Canvas.GetTop(g.EditMark1List[curEditMarkIndex + 1]), Canvas.GetLeft(g.EditMark1List[curEditMarkIndex + 1]) - scrPnt.X); ((centermeasureMark.MarkControl as Label).RenderTransform as RotateTransform).Angle = 360 - angle * 360 / (2 * Math.PI); if ((bool)checkBox1.IsChecked) { centermeasureMark.Visibility = System.Windows.Visibility.Visible; } else { centermeasureMark.Visibility = System.Windows.Visibility.Collapsed; } Label centermeasureLabel2 = new Label(); centermeasureLabel2.Content = ""; centermeasureLabel2.FontSize = 12; IMSMark centermeasureMark2 = new IMSMark(centermeasureLabel2, CoordinateType.Logic); centermeasureMark2.EnableDrag = false; centermeasureMark2.EnableAnimation = false; mymarklayer.AddMark(centermeasureMark2); measureCenterMarks.Insert(curEditMarkIndex + 1, centermeasureMark2); (centermeasureMark2.MarkControl as Label).RenderTransform = new RotateTransform(); (centermeasureMark2.MarkControl as Label).Content = getCurrentLength(curEditMarkIndex + 2, curEditMarkIndex + 1, new Point(-1, -1)); IMSCircle pntCircle2 = this.measurePnts[curEditMarkIndex + 2]; centermeasureMark2.X = (3 * pnt.X + pntCircle2.CenX) / 4; centermeasureMark2.Y = (3 * pnt.Y + pntCircle2.CenY) / 4; Point scrPnt2 = this.m_mapContainer.LogicToScreen(pntCircle2.CenX, pntCircle2.CenY); double angle2 = Math.Atan2(Canvas.GetTop(g.EditMark1List[curEditMarkIndex + 1]) - scrPnt2.Y, scrPnt2.X - Canvas.GetLeft(g.EditMark1List[curEditMarkIndex + 1])); ((centermeasureMark2.MarkControl as Label).RenderTransform as RotateTransform).Angle = 360 - angle2 * 360 / (2 * Math.PI); if ((bool)checkBox1.IsChecked) { centermeasureMark2.Visibility = System.Windows.Visibility.Visible; } else { centermeasureMark2.Visibility = System.Windows.Visibility.Collapsed; } for (int i = curEditMarkIndex; i < this.measureMarks.Count - 1; i++) { IMSMark nextmeasureMark = measureMarks[i + 1]; double nextLegth = Convert.ToDouble(getCurrentLength(i + 1, i, new Point(-1, -1)).Split(':')[1]); currLength += nextLegth; (nextmeasureMark.MarkControl as Label).Content = "总长度:" + currLength.ToString(); } }