/// <summary> /// 捕捉公交站点 /// Snap the bus stops /// </summary> public void SnapPoint() { try { if (m_selection != null) { // 获取被选中的站点对象 // Get the selected stop object Recordset recordset = m_selection.ToRecordset(); GeoPoint snapPoint = recordset.GetGeometry() as GeoPoint; // 构造文本对象,用于在跟踪层上显示站点的名称 // Construct the text object, which is used to display the stop name on the tracking name GeoText stopText = new GeoText(); // 站点名称 // Stop name String stopName = ""; if (SuperMap.Data.Environment.CurrentCulture != "zh-CN") { stopName = recordset.GetFieldValue("Name_en").ToString(); } else { stopName = recordset.GetFieldValue("Name").ToString(); } TextPart textPart = new TextPart(stopName, new Point2D(snapPoint.X, snapPoint.Y)); stopText.AddPart(textPart); if (m_isStartPoint) { // 绘制之前先清空跟踪层上的点和文字 // Clear all points and words on the tracking layer before drawing Int32 indexStartStop = m_trackingLayer.IndexOf("StartStop"); if (indexStartStop != -1) { m_trackingLayer.Remove(indexStartStop); } Int32 indexStartText = m_trackingLayer.IndexOf("StartStopName"); if (indexStartText != -1) { m_trackingLayer.Remove(indexStartText); } // 分别设置站点及其名称文本的风格,并添加到跟踪层上 // Set the stop and name style and add them to the tracking layer snapPoint.Style = GetStopStyle(new Size2D(8, 8), Color.FromArgb(236, 118, 0)); m_trackingLayer.Add(snapPoint, "StartStop"); stopText.TextStyle = GetStopTextStyle(6.0, Color.FromArgb(0, 0, 0)); m_trackingLayer.Add(stopText, "StartStopName"); // 设置为起始站点ID // Set the strat stop ID m_startStopID = recordset.GetInt64("STOPID"); } else { // 绘制之前先清空跟踪层上的点和文字 // Clear all points and words on the tracking layer before drawing Int32 indexEndStop = m_trackingLayer.IndexOf("EndStop"); if (indexEndStop != -1) { m_trackingLayer.Remove(indexEndStop); } Int32 indexEndText = m_trackingLayer.IndexOf("EndStopName"); if (indexEndText != -1) { m_trackingLayer.Remove(indexEndText); } // 分别设置站点及其名称文本的风格,并添加到跟踪层上 // Set the stop and name style and add them to the tracking layer snapPoint.Style = GetStopStyle(new Size2D(8, 8), Color.FromArgb(22, 255, 0)); m_trackingLayer.Add(snapPoint, "EndStop"); stopText.TextStyle = GetStopTextStyle(6.0, Color.FromArgb(0, 0, 0)); m_trackingLayer.Add(stopText, "EndStopName"); // 设置为起始站点ID // Set the strat stop ID m_endStopID = recordset.GetInt64("STOPID"); } recordset.Dispose(); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } }