前几天呢,想做动态追踪,发现这篇文章(https://blog.csdn.net/anlidengshiwei/article/details/41545301)写的不错,功能实现了之后,感觉可以更好,所有就自己就试着写了一下,本人新手,还望大家多多包涵;
第一种方法,小车点的行进路径该有鼠标动态获取;
double[] arrx=new double[1000];
double[] arry=new double[1000];
int i = 0;
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
arrx[i] = e.mapX;
arry2[i] = e.mapY;
i++;
}
这是鼠标点击事件事件,获取用来获取点的坐标,
private void timer1_Tick(object sender, EventArgs e)
{
if (s < i)
{
dx = arrx[s];
dy = arry2[s];
MoveCar();
s++;
}
else {
this.timer1.Dispose();
MessageBox.Show("走完了");
}
}
这是对控件time1的处理
private void MoveCar()
{
//得到当前活动范围
IActiveView pActiveView = axMapControl1.ActiveView;
//开始画笔
pActiveView.ScreenDisplay.StartDrawing(pActiveView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
IPoint ppoint;
IGeometry pgeo;
IPictureMarkerSymbol psymbol = new PictureMarkerSymbolClass();
IRgbColor prgbcolor = new RgbColorClass();
prgbcolor.Red = 0;
prgbcolor.Green = 0;
prgbcolor.Blue = 0;
psymbol.BitmapTransparencyColor = prgbcolor;
psymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, @"C:\Users\deng\Desktop\毕业设计\NodeAnimation\Command1.bmp");
psymbol.Size = 15;
psymbol.Angle = 270;
//ISimpleMarkerSymbol psimplesymbol = new SimpleMarkerSymbolClass();
//psimplesymbol.Size = 10;
//psimplesymbol.Color = (IColor)prgbcolor;
ppoint = new PointClass();
ppoint.PutCoords(dx, dy);
pgeo = ppoint;
pActiveView.ScreenDisplay.SetSymbol((ISymbol)psymbol);
pActiveView.ScreenDisplay.DrawPoint(ppoint);
//结束画笔
pActiveView.ScreenDisplay.UpdateWindow();
pActiveView.ScreenDisplay.FinishDrawing();
//System.Object obj = psymbol;
//this.axMapControl1.DrawShape(pgeo, ref obj);
//this.axMapControl1.CenterAt(ppoint);
IEnvelope penv = this.axMapControl1.Extent;
penv.CenterAt(ppoint);
this.axMapControl1.Extent = penv;
}
这是主要方法,与我之前学习的文章相同.
private void toolStripButton1_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
}
这是启动运行的方法
int s = 0;
double dx = 112.906;
double dy = 27.912;
IActiveView pactiveview;
public Form1()
{
InitializeComponent();
timer1.Enabled = false;
this.axToolbarControl1.SetBuddyControl(this.axMapControl1);
pactiveview = this.axMapControl1.ActiveView;
}
运行之后可以在地图点击多个点,在点击
toolStripButton1
这个控件就会按照我们所选的位置行动
源码
https://download.csdn.net/download/qq_27380923/10373709