MapTip.cs
上传用户:xum6868
上传日期:2009-12-02
资源大小:102k
文件大小:4k
- using System;
- namespace MainSystem
- {
- /// <summary>
- /// Summary description for MapTip.
- /// </summary>
- public class MapTip
- {
- private double m_x; // 当前位置的x坐标
- private double m_y; // 当前位置的y坐标
- private double m_lastX; // 当计时开始时鼠标位置的x坐标
- private double m_lastY; // 当计时开始时鼠标位置的y坐标
- private AxMapObjects2.AxMap m_map = null;
- private System.Windows.Forms.Timer m_timer = null;
- private System.Windows.Forms.PictureBox m_picture = null;
- private System.Windows.Forms.Label m_lable = null;
- private CEnvironment m_env = null;
- private string m_szField = "";
- public MapTip(frmMain frm)
- {
- m_map = frm._map;
- m_timer = frm._timer;
- m_picture = frm._picToolTip;
- m_lable = frm._lblToolTip;
- m_szField = "名称";
- m_env = frm._environment;
- m_picture.Visible = false;
- m_picture.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192)));
-
- m_lable.AutoSize = true;
- m_lable.BackColor = m_picture.BackColor;
- m_lable.Visible = false;
- }
- public void MouseMove(double X, double Y)
- {
- m_x = X;
- m_y = Y;
- if (m_timer.Interval == 1)
- {
- m_lastX = X;
- m_lastY = Y;
- m_timer.Interval = 100;
- }
- else
- {
- m_picture.Visible = false;
- m_lable.Visible = false;
- }
- }
- private void ShowTipText(string text)
- {
- // 设置标签控件的显示内容与位置
- m_lable.Text = text;
- m_lable.Left = m_map.Left + (int)m_x+20;
- m_lable.Top = m_map.Top + (int)m_y + 11;
-
- // 设置Picture控件的位置
- m_picture.Left = m_map.Left + (int)m_x + 10;
- m_picture.Top = m_map.Top + (int)m_y + 10;
- m_picture.Width = m_lable.Width + 20;
- m_picture.Visible = true;
- m_lable.Visible = true;
- }
- private bool InMap(double x, double y)
- {
- if (x > m_map.Right || x < m_map.Left)
- return false;
- if (y > m_map.Top || y < m_map.Bottom)
- return false;
- return true;
- }
- public void Timer()
- {
- if (m_x == m_lastX && m_y == m_lastY)
- {
- m_timer.Interval = 1;
- MapObjects2.Recordset recs;
- recs = DoSearch();
- if (recs == null || recs.EOF || InMap(m_x,m_y))
- {
- m_picture.Visible = false;
- m_lable.Visible = false;
- }
- else
- {
- string szText = recs.Fields.Item (m_szField).Value.ToString();
- if (szText != "")
- ShowTipText(recs.Fields.Item (m_szField).Value.ToString());
- }
- }
- else
- {
- m_lastX = m_x;
- m_lastY = m_y;
- }
- }
- private MapObjects2.Recordset DoSearch()
- {
- MapObjects2.Point pt = null;
- MapObjects2.Recordset rst = null;
- pt = this.m_map.ToMapPoint((float)m_x,(float)m_y);
- double dScale = m_env.CalcScale(m_map);
- dScale = dScale/10000;
- dScale = dScale / 5000;
- for (int i = m_env.m_nLayerNum - 1; i >= 0 ; i --)
- {
- if (m_env.m_layerInfos[i].layer.Visible && m_env.m_layerInfos[i].bCanSelected && m_env.m_layerInfos[i].layer.shapeType == MapObjects2.ShapeTypeConstants.moShapeTypePoint)
- rst = m_env.m_layerInfos[i].layer.SearchByDistance(pt,dScale,"");
- if (rst != null)
- {
- rst.MoveFirst();
- if (!rst.EOF)
- return rst;
- }
- }
- for (int i = 0; i < m_env.m_nLayerNum; i ++)
- {
- if (m_env.m_layerInfos[i].bVisible && m_env.m_layerInfos[i].bCanSelected && m_env.m_layerInfos[i].layer.shapeType == MapObjects2.ShapeTypeConstants.moShapeTypeLine)
- rst = m_env.m_layerInfos[i].layer.SearchByDistance(pt,dScale,"");
- if (rst != null)
- {
- rst.MoveFirst();
- if (!rst.EOF)
- return rst;
- }
- }
- for (int i = 0; i < m_env.m_nLayerNum; i ++)
- {
- if (m_env.m_layerInfos[i].bVisible && m_env.m_layerInfos[i].bCanSelected && m_env.m_layerInfos[i].layer.shapeType == MapObjects2.ShapeTypeConstants.moShapeTypePolygon )
- rst = m_env.m_layerInfos[i].layer.SearchByDistance(pt,dScale,"");
- if (rst != null)
- {
- rst.MoveFirst();
- if (!rst.EOF)
- return rst;
- }
- }
- return rst;
- }
- }
- }