为MapXtreme 2004 6.1 Win 添加测距功能按钮【转】

自从MapInfo把控件从MapX升级到MapXtreme之后,让人郁闷的是测距功能按钮在Win版本中消失了,只有Web版本中还保留着。
所以下面的方法就是为了恢复这个必备的功能:

 

1)为MapTool控件增加一个ToolBarButton
            //
            // toolBarButtonDistance
            //
            this.toolBarButtonDistance.ImageIndex = 11;
           this.toolBarButtonDistance.Style =System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
            this.toolBarButtonDistance.Tag = "CustomLine";
            this.toolBarButtonDistance.ToolTipText = "测距";
2) 为MapControl增加工具响应事件
           this.mapControl1.Tools.Add("CustomLine", newMapInfo.Tools.CustomLineMapTool(true, true, true,
               mapControl1.Viewer, mapControl1.Handle.ToInt32(),mapControl1.Tools,
               mapControl1.Tools.MouseToolProperties,mapControl1.Tools.MapToolProperties));
        this.mapControl1.Tools.Used +=new MapInfo.Tools.ToolUsedEventHandler(Tools_Used);

        private void Tools_Used(object sender, MapInfo.Tools.ToolUsedEventArgs e)
        {
            if(e.ToolName != "CustomLine") //不是测距事件,不处理
                return ;

            if (e.ToolStatus==MapInfo.Tools.ToolStatus.Start)
            {
               FindLonLatFromToolUsedEventArg(e.ToString(),outbeginLon,out beginLat);
            }
            else if( e.ToolStatus==MapInfo.Tools.ToolStatus.End)
            {
                double endLon,endLat;
               FindLonLatFromToolUsedEventArg(e.ToString(),outendLon,out endLat);
               doubledistance=util.GetDistanceBetweenTwoLonLatPoints(beginLat,beginLon,endLat,endLon);
               doubledistance2=Convert.ToDouble(Convert.ToInt32(distance*100))/100;
               this.statusBar2.Text="两点相距: "+distance2.ToString()+"米";
                beginLon=0;beginLat=0;
                endLon=0;endLat=0;
            }
        }

3) 辅助函数

        /// <summary>
        /// 根据tagname,把除了参数指定的button之外的其他button弹起
        /// </summary>
        /// <param name="toolName"></param>
        private void CheckToolButton(string toolName)
        {
            foreach (ToolBarButton tbb in this.mapToolBar1.Buttons)
                if (tbb.Style == ToolBarButtonStyle.ToggleButton)
                   tbb.Pushed = ((string)tbb.Tag ==toolName);
        }

        /// <summary>
        /// 把鼠标点击点的信息串转成经纬度
        /// </summary>
        /// <param name="eventArgMsg"></param>
        /// <param name="lon"></param>
        /// <param name="lat"></param>
        private voidFindLonLatFromToolUsedEventArg(string eventArgMsg,out double lon,outdouble lat)
        {
            int lonBeginIndex=eventArgMsg.IndexOf("(");
            int lonEndIndex=eventArgMsg.IndexOf(", ");
            int latEndIndex=eventArgMsg.IndexOf(")");
            try
            {
              lon=Convert.ToDouble(eventArgMsg.Substring(lonBeginIndex+1,lonEndIndex-lonBeginIndex-1));
              lat=Convert.ToDouble(eventArgMsg.Substring(lonEndIndex+2,latEndIndex-lonEndIndex-2));
            }
            catch(Exception err)
            {
                err.ToString();
                lon=0;lat=0;
            }
        }

转载于:https://www.cnblogs.com/carekee/articles/1922350.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值