王朝网络
分享
 
 
 

MapObjects2.2 在C#中的应用(基本地图功能)

王朝c#·作者佚名  2006-01-30
宽屏版  字体: |||超大  

MapObjects2.2 在C#中的应用(基本地图功能)

关键字:MapObjects 2.2 C#

仅仅实现了地图的放大、缩小、漫游、全图、距离、面积等功能。

/*

* 杨雨田 blue_bat@126.com

* 2004年7月27日

*/

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

namespace Artemis.IVS.Test

{

/// <summary>

/// 处理实例

/// </summary>

public class FrmMain : System.Windows.Forms.Form

{

private AxMapObjects2.AxMap mapMain;

private System.Windows.Forms.MainMenu mainMenu1;

private System.Windows.Forms.MenuItem miZoomIn;

private System.Windows.Forms.MenuItem miZoomOut;

private System.Windows.Forms.MenuItem miPan;

private System.Windows.Forms.MenuItem miFullView;

private int CurOperate = 0;

private System.Windows.Forms.MenuItem miSelectByPoint;

private System.Windows.Forms.MenuItem miDistance;

private System.Windows.Forms.MenuItem miArea;

/// <summary>

/// 必需的设计器变量。

/// </summary>

private System.ComponentModel.Container components = null;

public FrmMain()

{

//

// Windows 窗体设计器支持所必需的

//

InitializeComponent();

}

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

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

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmMain));

this.mapMain = new AxMapObjects2.AxMap();

this.mainMenu1 = new System.Windows.Forms.MainMenu();

this.miZoomIn = new System.Windows.Forms.MenuItem();

this.miZoomOut = new System.Windows.Forms.MenuItem();

this.miPan = new System.Windows.Forms.MenuItem();

this.miFullView = new System.Windows.Forms.MenuItem();

this.miSelectByPoint = new System.Windows.Forms.MenuItem();

this.miDistance = new System.Windows.Forms.MenuItem();

this.miArea = new System.Windows.Forms.MenuItem();

((System.ComponentModel.ISupportInitialize)(this.mapMain)).BeginInit();

this.SuspendLayout();

//

// mapMain

//

this.mapMain.Dock = System.Windows.Forms.DockStyle.Fill;

this.mapMain.Location = new System.Drawing.Point(0, 0);

this.mapMain.Name = "mapMain";

this.mapMain.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("mapMain.OcxState")));

this.mapMain.Size = new System.Drawing.Size(592, 401);

this.mapMain.TabIndex = 0;

this.mapMain.MouseDownEvent += new AxMapObjects2._DMapEvents_MouseDownEventHandler(this.mapMain_MouseDownEvent);

//

// mainMenu1

//

this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.miZoomIn,

this.miZoomOut,

this.miPan,

this.miFullView,

this.miSelectByPoint,

this.miDistance,

this.miArea});

//

// miZoomIn

//

this.miZoomIn.Index = 0;

this.miZoomIn.Text = "放大";

this.miZoomIn.Click += new System.EventHandler(this.miZoomIn_Click);

//

// miZoomOut

//

this.miZoomOut.Index = 1;

this.miZoomOut.Text = "缩小";

this.miZoomOut.Click += new System.EventHandler(this.miZoomOut_Click);

//

// miPan

//

this.miPan.Index = 2;

this.miPan.Text = "漫游";

this.miPan.Click += new System.EventHandler(this.miPan_Click);

//

// miFullView

//

this.miFullView.Index = 3;

this.miFullView.Text = "全图";

this.miFullView.Click += new System.EventHandler(this.miFullView_Click);

//

// miSelectByPoint

//

this.miSelectByPoint.Index = 4;

this.miSelectByPoint.Text = "点选";

this.miSelectByPoint.Click += new System.EventHandler(this.miSelectByPoint_Click);

//

// miDistance

//

this.miDistance.Index = 5;

this.miDistance.Text = "距离";

this.miDistance.Click += new System.EventHandler(this.miDistance_Click);

//

// miArea

//

this.miArea.Index = 6;

this.miArea.Text = "面积";

this.miArea.Click += new System.EventHandler(this.miArea_Click);

//

// FrmMain

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.ClientSize = new System.Drawing.Size(592, 401);

this.Controls.Add(this.mapMain);

this.Menu = this.mainMenu1;

this.Name = "FrmMain";

this.Text = "Artemis.IVS.Test";

this.Load += new System.EventHandler(this.FrmMain_Load);

((System.ComponentModel.ISupportInitialize)(this.mapMain)).EndInit();

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// 应用程序的主入口点。

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new FrmMain());

}

/// <summary>

/// 全图

/// </summary>

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

{

this.CurOperate = 4;

mapMain.Extent = mapMain.FullExtent;

mapMain.MousePointer = MapObjects2.MousePointerConstants.moDefault;

}

/// <summary>

/// 漫游

/// </summary>

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

{

this.CurOperate = 3;

mapMain.MousePointer = MapObjects2.MousePointerConstants.moPan;

}

/// <summary>

/// 缩小

/// </summary>

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

{

this.CurOperate = 2;

mapMain.MousePointer = MapObjects2.MousePointerConstants.moZoomOut;

}

/// <summary>

/// 放大

/// </summary>

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

{

this.CurOperate = 1;

mapMain.MousePointer = MapObjects2.MousePointerConstants.moZoomIn;

}

/// <summary>

/// 放大缩小等的处理过程

/// </summary>

private void mapMain_MouseDownEvent(object sender, AxMapObjects2._DMapEvents_MouseDownEvent e)

{

MapObjects2.Rectangle rect;

MapObjects2.Point pt = mapMain.ToMapPoint(e.x,e.y);

if(e.button == 2) this.CurOperate = 0;//右键点击取消

switch(this.CurOperate)

{

case 1://放大

{

rect = mapMain.TrackRectangle();

if(rect == null|| (rect.Width < 0.00005) || (rect.Height < 0.00005))

{

rect = mapMain.Extent;

rect.ScaleRectangle(0.6667);

rect.Offset(-(rect.Center.X - pt.X),-(rect.Center.Y - pt.Y));

}

mapMain.Extent = rect;

break;

}

case 2://缩小

{

rect = mapMain.TrackRectangle();

if ((null == rect) || (rect.Width < 0.00005) || (rect.Height < 0.00005))

{

rect = mapMain.Extent;

rect.ScaleRectangle(1.5);

rect.Offset(-(rect.Center.X - pt.X),-(rect.Center.Y - pt.Y));

}

else

{

double dRate = mapMain.Extent.Width / rect.Width * 10;

rect.ScaleRectangle(dRate);

}

mapMain.Extent = rect;

break;

}

case 3://漫游

{

mapMain.Pan();

break;

}

case 5://点选

{

break;

}

case 6://距离

{

MapObjects2.Points pts;

pts = (MapObjects2.Points)mapMain.TrackLine().Parts.Item(0);

double dDistance = 0;

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

{

dDistance += Math.Sqrt(pts.Item(i).X*pts.Item(i).X + pts.Item(i).Y*pts.Item(i).Y);

}

this.Text = mapMain.ToMapDistance((float)dDistance).ToString();

break;

}

case 7://面积

{

MapObjects2.Polygon ply = mapMain.TrackPolygon();

double dArea = ply.Area;

this.Text = mapMain.ToMapDistance((float)dArea).ToString();

break;

}

default://箭头

{

mapMain.MousePointer = MapObjects2.MousePointerConstants.moDefault;

break;

}

}

}

/// <summary>

/// 点选

/// </summary>

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

{

this.CurOperate = 5;

mapMain.MousePointer = MapObjects2.MousePointerConstants.moArrowQuestion;

}

/// <summary>

/// 距离

/// </summary>

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

{

this.CurOperate = 6;

mapMain.MousePointer = MapObjects2.MousePointerConstants.moCross;

}

/// <summary>

/// 面积

/// </summary>

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

{

this.CurOperate = 7;

mapMain.MousePointer = MapObjects2.MousePointerConstants.moCross;

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有