鼠标的坐标

在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的高度

我测试了一下,这样粗略的转化鼠标位置为经纬度,误差很小,对于一般的应用还是可以的,理解起来简单,效率也很高

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值