惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
L
LangChain Blog
云风的 BLOG
云风的 BLOG
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
量子位
The GitHub Blog
The GitHub Blog
博客园 - 【当耐特】

博客园 - 海燕一家

创业经验点滴 五(转) 关于淘宝 MAPINFO 的空间数据入库(ORACLE )与调用 转: C#+MAPX 添加线、文本、符号等图元 ArcGIS 代理产品价格以及折扣表、产品描述 MapInfo正版价格 ArcGIS 中国代理 MapInfo介绍(转) ArcInfo和MapInfo的比较 (转) 民用地图经纬度纠偏-高德系地图纠偏 [转载]关于火星坐标系统 关于火星坐标、偏移、加偏和纠偏、无偏的理解 创业经验点滴 四(转) 创业经验点滴 三(转) 面试那点事(转) 创业经验点滴 二(转) 创业经验点滴(转) iphone4s必装AppSync补丁教程使iOS5完全越狱 IOS 无证书真机调试教程(转) 详解C#委托,事件与回调函数(转)
[转]Mapx在C#中的应用
海燕一家 · 2012-10-18 · via 博客园 - 海燕一家

/*

 * 在这段代码中,我们应用MapX控件结合老美地图做了最基本的

 * 地图浏览功能:放大、缩小、拖动、全图、测量距离、测量面积。

 *

 * 杨雨田 YangYutian@Hotmail.Com

 */

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

namespace wa

{

    public class frmMain : System.Windows.Forms.Form

    {

        private AxMapXLib.AxMap mapMain;

        private double MapZoom;

        private double CenterX;

        private double CenterY;

        private System.Windows.Forms.StatusBar sbMain;

        private System.Windows.Forms.MainMenu mainMenu;

        private System.Windows.Forms.MenuItem miMap;

        private System.Windows.Forms.MenuItem miMapToolZoomIn;

        private System.Windows.Forms.MenuItem miMapToolZoomout;

        private System.Windows.Forms.MenuItem miMapToolPan;

        private System.Windows.Forms.MenuItem miMapToolRestore;

        private System.Windows.Forms.MenuItem miMapToolDistance;

        private System.Windows.Forms.MenuItem miMapToolArea;

        private System.Windows.Forms.MenuItem miMapTool;

        private System.ComponentModel.Container components = null;

        public frmMain()

       {

           InitializeComponent();

       }

        protected override void Dispose( bool disposing )

       {

       //略

       }

        #region Windows 窗体设计器生成的代码

        private void InitializeComponent()

       {

       //略

       }

        #endregion

        [STAThread]

        static void Main()

       {

           Application.Run(new Form1());

       }

        private void mapMain_PolyToolUsed(object sender, AxMapXLib.CMapXEvents_PolyToolUsedEvent e)

       {

           if(e.toolNum == 99)//测量距离

           {

               MapXLib.Points pts = (MapXLib.Points)e.points;

               MapXLib.Point pt1,pt2;

               double d=0.0;

               //计算顺序两个点距离,累计得到总距离

               for(int i=1;i<pts.Count;i++)

               {

                   pt1=pts.Item(i);

                   pt2=pts.Item(i+1);

                  d += mapMain.Distance(pt1.X,pt1.Y,pt2.X,pt2.Y);

               }

               sbMain.Text = "距离:" + d.ToString();

           }

           else if(e.toolNum == 98)//面积

           {

               MapXLib.Points pts = (MapXLib.Points)e.points;

               //偷懒了但是很正确

               MapXLib.FeatureFactory dd = mapMain.FeatureFactory;

               MapXLib.Style style = mapMain.DefaultStyle;

               sbMain.Text = "面积:" + dd.CreateRegion(pts,style).Area.ToString();

           }

       }

        private void miMapToolZoomIn_Click(object sender, System.EventArgs e)

       {

           //放大

           mapMain.CurrentTool = MapXLib.ToolConstants.miZoomInTool;

       }

        private void miMapToolZoomout_Click(object sender, System.EventArgs e)

       {

           //缩小

           mapMain.CurrentTool = MapXLib.ToolConstants.miZoomOutTool;

       }

        private void miMapToolPan_Click(object sender, System.EventArgs e)

       {

           //拖动

           mapMain.CurrentTool = MapXLib.ToolConstants.miPanTool;

       }

        private void miMapToolRestore_Click(object sender, System.EventArgs e)

       {

           //缩放到初始大小(全图)

           mapMain.ZoomTo(this.MapZoom,this.CenterX,this.CenterY);

       }

        private void miMapToolDistance_Click(object sender, System.EventArgs e)

       {

           //测量距离

           mapMain.CurrentTool = (MapXLib.ToolConstants)99;

       }

        private void miMapToolArea_Click(object sender, System.EventArgs e)

       {

           //测量面积

           mapMain.CurrentTool = (MapXLib.ToolConstants) 98;

       }

        private void frmMain_Load(object sender, System.EventArgs e)

       {

           //记录地图的比例合中心点

           this.MapZoom = mapMain.Zoom;

           this.CenterX = mapMain.CenterX;

           this.CenterY = mapMain.CenterY;

           //创建测量距离的工具

           mapMain.CreateCustomTool(99,MapXLib.ToolTypeConstants.miToolTypePoly,MapXLib.CursorConstants.miCrossCursor,MapXLib.CursorConstants.miCrossCursor,MapXLib.CursorConstants.miCrossCursor,false);

           //创建测量面积的工具

           mapMain.CreateCustomTool(98,MapXLib.ToolTypeConstants.miToolTypePolygon,MapXLib.CursorConstants.miCrossCursor,MapXLib.CursorConstants.miCrossCursor,MapXLib.CursorConstants.miCrossCursor,false);

           mapMain.PolyToolUsed += new AxMapXLib.CMapXEvents_PolyToolUsedEventHandler(mapMain_PolyToolUsed);

       }

    }

}