|
模拟飞行器
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace k12._6
{
public partial class Form1 : Form
{
MapObjects2.DataConnection dc;
MapObjects2.MapLayer mly;
MapObjects2.Point pt;
MapObjects2.Points pts;
MapObjects2.Point pt1;
MapObjects2.Line g_line;
MapObjects2.Recordset reco;
MapObjects2.Recordset reco1;
MapObjects2.Rectangle r;
MapObjects2.Rectangle r1;
MapObjects2.Symbol sym = new MapObjects2.Symbol();
MapObjects2.Symbol sym1 = new MapObjects2.Symbol();
int num = 0;
int count = 0;
int state = 0;
public Form1()
{
InitializeComponent();
}
public string getPath(string cata, string data)
{
int index = Application.StartupPath.IndexOf(cata);
string path = Application.StartupPath.Substring(0, index) + data;
return path;
}
//加载数据
public void load_Data()
{
dc = new MapObjects2.DataConnection();
mly = new MapObjects2.MapLayer();
dc.Database = getPath("bin", "world");
mly.GeoDataset = dc.FindGeoDataset("prj");
mly.Symbol.Color = (uint)MapObjects2.ColorConstants.moYellow;
axMap1.Layers.Add(mly);
mly = new MapObjects2.MapLayer();
mly.GeoDataset = dc.FindGeoDataset("world");
mly.Symbol.Color = (uint)MapObjects2.ColorConstants.moLightGray;
axMap1.Layers.Add(mly);
mly = new MapObjects2.MapLayer();
mly.GeoDataset = dc.FindGeoDataset("worldCities");
axMap1.Layers.Add(mly);
axMap1.Refresh();
}
private void Form1_Load(object sender, EventArgs e)
{
load_Data();
}
private void axMap1_MouseMoveEvent(object sender, AxMapObjects2._DMapEvents_MouseMoveEvent e)
{
pt1 = axMap1.ToMapPoint(e.x,e.y);
label2.Text = string.Format("{0:N3}", double.Parse(e.x.ToString())) + "," + string.Format("{0:N3}", double.Parse(e.y.ToString()));
}
private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
switch (e.ClickedItem.Name)
{
case "zoomin":
state = 0;
axMap1.MousePointer = MapObjects2.MousePointerConstants.moZoomIn;
break;
case "zoomout":
state = 1;
axMap1.MousePointer = MapObjects2.MousePointerConstants.moZoomOut;
break;
case "move":
state = 2;
axMap1.MousePointer = MapObjects2.MousePointerConstants.moPan;
break;
case "zoomall":
state = 3;
axMap1.MousePointer = MapObjects2.MousePointerConstants.moSizeAll;
break;
case "makepoint":
state = 4;
axMap1.MousePointer = MapObjects2.MousePointerConstants.moCross;
break;
case "searich":
state = 5;
axMap1.MousePointer = MapObjects2.MousePointerConstants.moCross;
break;
case "makeline":
state = 6;
axMap1.MousePointer = MapObjects2.MousePointerConstants.moCross;
break;
}
}
private void axMap1_MouseDownEvent(object sender, AxMapObjects2._DMapEvents_MouseDownEvent e)
{
switch (state)
{
case 0:
axMap1.Extent = axMap1.TrackRectangle();
break;
case 1:
r = axMap1.TrackRectangle();
r.ScaleRectangle(axMap1.Extent.Width / r.Extent.Width * 2);
axMap1.Extent = r;
break;
case 2:
axMap1.Pan();
break;
case 3:
axMap1.Extent = axMap1.FullExtent;
break;
case 4://画点
pt = axMap1.ToMapPoint(e.x, e.y);
axMap1.TrackingLayer.Refresh(true, 0);
break;
case 5:
r1 = axMap1.TrackRectangle();
axMap1.TrackingLayer.Refresh(true, 0);
break;
case 6:
if (g_line == null)
{
g_line = new MapObjects2.Line();
}
if (pts == null)
{
pts = new MapObjects2.Points();
}
pt = axMap1.ToMapPoint(e.x, e.y);
pts.Add(pt);
g_line.Parts.Add(pts);
axMap1.TrackingLayer.Refresh(true, 0);
break;
}
}
private void axMap1_AfterTrackingLayerDraw(object sender, AxMapObjects2._DMapEvents_AfterTrackingLayerDrawEvent e)
{
if (g_line != null)
{
sym.Color = (uint)MapObjects2.ColorConstants.moRed;
sym.SymbolType = MapObjects2.SymbolTypeConstants.moLineSymbol;
sym.Style = (short)MapObjects2.MarkerStyleConstants.moTrueTypeMarker;
sym.Size = 5;
axMap1.DrawShape(g_line, sym);
}
if (pt != null)
{
sym.Color = (uint)MapObjects2.ColorConstants.moBlue;
sym.SymbolType = MapObjects2.SymbolTypeConstants.moPointSymbol;
sym.Style = (short)MapObjects2.MarkerStyleConstants.moTriangleMarker;
sym.Size = 10;
axMap1.DrawShape(pt, sym);
axMap1.Refresh();
}
if (reco!= null)
{
sym.Color = (uint)MapObjects2.ColorConstants.moOrange;
sym.SymbolType = MapObjects2.SymbolTypeConstants.moFillSymbol;
sym.Style = (short)MapObjects2.FillStyleConstants.moCrossFill;
sym.Size = 2;
axMap1.DrawShape(reco, sym);
axMap1.Refresh();
}
if (r1!= null)
{
mly = (MapObjects2.MapLayer)axMap1.Layers.Item(0);
reco1=mly.SearchByDistance(r1,0,"");
sym.Color = (uint)MapObjects2.ColorConstants.moLightGray;
int sum = 0;
reco1.MoveFirst();
while (!reco1.EOF)
{
sum++;
reco1.MoveNext();
}
MessageBox.Show("选中城市的个数:" + sum);
sym.SymbolType = MapObjects2.SymbolTypeConstants.moFillSymbol;
sym.Style = (short)MapObjects2.FillStyleConstants.moLightGrayFill;
axMap1.DrawShape(r, sym);
sym1.SymbolType = MapObjects2.SymbolTypeConstants.moFillSymbol;
sym1.Style = (short)MapObjects2.FillStyleConstants.moCrossFill;
sym1.Color = (uint)MapObjects2.ColorConstants.moRed;
axMap1.DrawShape(reco1, sym1);
}
}
private void 开始ToolStripMenuItem_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
num = pts.Count;
timer1.Start();
timer1.Interval = 1000;
}
private void timer1_Tick(object sender, EventArgs e)
{
mly = (MapObjects2.MapLayer)axMap1.Layers.Item(2);
if(count<num)
{
for(int i=0;i<=count;i++)
{
pt = pts.Item(i);
reco = mly.SearchShape(pt, MapObjects2.SearchMethodConstants.moPointInPolygon, "");
}
count++;
axMap1.TrackingLayer.Refresh(true, 0);
}
}
private void 结束ToolStripMenuItem_Click(object sender, EventArgs e)
{
timer1.Stop();
}
}
}
|
|