在mapx控件的鼠标移动事件里写
axMap1.ConvertCoord(ref e.x, ref e.y, ref lot, ref lat, ConversionConstants.miScreenToMap);
double lot=0;
double lat=0;
label3.Text = lot.ToString();
label4.Text = lat.ToString();
就OK了 我自己找到解决的办法了!
//-------------------------------------------------------------------------------------------------------
问:如何在MapXtreme2004桌面应用程序中的任务栏上显示出鼠标的坐标?
答:代码如下:
1、添加mapControl1的MouseMove事件;
2、该事件及其中代码如下:
public void MapControl1_MouseMove(object sender, MouseEventArgs e)
{
System.Drawing.PointF DisplayPoint = new PointF(e.X,e.Y);
MapInfo.Geometry.DPoint MapPoint = new MapInfo.Geometry.DPoint();
MapInfo.Geometry.DisplayTransform converter = this.mapControl1.Map.DisplayTransform;
converter.FromDisplay(DisplayPoint, out MapPoint);
this.statusBar1.Text = "Cursor Location: " + MapPoint.x.ToString() + ", " + MapPoint.y.ToString();
}
//------------------------------------------------------------------------------------------------------------
在客户端先得到鼠标点击的位置
x=event.clientX;
y=event.clientY-32;//注意减去mapcontrol的left和top,把x、y转化为在地图上的位置
然后把xy的值放到隐藏域中中间用“|”隔开,在后台代码中把该xy转化为坐标值
string longAndLat = this.textbox1.Value;//textbox1为隐藏域
int lon=Convert.ToInt16(longAndLat.Split(new char[]{'|'})[0],10);
int lat=Convert.ToInt16(longAndLat.Split(new char[]{'|'})[1],10);
//得到当前地图范围:左下角经纬度,右上角经纬度
double leftLongitude = this.MapControl1.Map.Bounds.x1;
double bottomLatitude = this.MapControl1.Map.Bounds.y1;
double rightLongitude = this.MapControl1.Map.Bounds.x2;
double topLatitude = this.MapControl1.Map.Bounds.y2;
//把鼠标点击位置转化为经纬度
double pointX = leftLongitude+(rightLongitude-leftLongitude)*lon/500; //500为mapcontrol的宽度
double pointY = bottomLatitude+(topLatitude-bottomLatitude)*(400-lat)/400; //400为mapcontrol的高度
我测试了一下,这样粗略的转化鼠标位置为经纬度,误差很小,对于一般的应用还是可以的,理解起来简单,效率也很高