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;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
namespace AEKF_yingyan
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//窗体加载打开地图文档
private void Form1_Load(object sender, EventArgs e)
{
loadMapDocument();
}
//打开地图文档方法
private void loadMapDocument()
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开地图文档";
openFileDialog.Filter = "map document(*.mxd)|*.mxd";
openFileDialog.ShowDialog();
string filepath = openFileDialog.FileName;
if (filepath != "" && filepath != null)
{
if (axMapControl1.CheckMxFile(filepath))
{
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
axMapControl1.LoadMxFile(filepath, 0, Type.Missing);
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
else
{
MessageBox.Show(filepath+"不是有效地图文档");
}
}
}
//打开鹰眼地图方法
private void loadEagleEyeDocument()
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开鹰眼地图";
openFileDialog.Filter = "map document(*.mxd)|*.mxd";
openFileDialog.ShowDialog();
string filepath = openFileDialog.FileName;
if (filepath != "" && filepath != null)
{
if (axMapControl2.CheckMxFile(filepath))
{
axMapControl2.MousePointer = esriControlsMousePointer.esriPointerHourglass;
axMapControl2.LoadMxFile(filepath, 0, Type.Missing);
axMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
else
{
MessageBox.Show(filepath+"不是有效地图");
}
}
}
// axMapControl1控件的_OnMapReplaced事件
private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
loadEagleEyeDocument();
}
//axmapconteol1的onmousedown事件
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button == 1)
{
axMapControl1.Extent = axMapControl1.TrackRectangle();
axMapControl1.Refresh(esriViewDrawPhase.esriViewBackground,null,null);
}
else if (e.button == 2)
{
axMapControl1.Pan();
axMapControl1.Refresh(esriViewDrawPhase.esriViewBackground,null,null);
}
}
// axMapControl1的_OnExtentUpdated事件
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
IEnvelope envelope = (IEnvelope)e.newEnvelope;
IGraphicsContainer graphicsContainer = axMapControl2.Map as IGraphicsContainer;
IActiveView activeview = graphicsContainer as IActiveView;
//设置鹰眼图中的红线
//产生一个线符号
ILineSymbol outlinesymbol = new SimpleLineSymbolClass();
outlinesymbol.Width = 2;
outlinesymbol.Color = GetColor(255,0,0,255);
//设置颜色属性
//设置填充符号
IFillSymbol fillsymbol = new SimpleFillSymbolClass();
fillsymbol.Color = GetColor(9,0,0,0);
fillsymbol.Outline = outlinesymbol;
IFillShapeElement fillShapeElement = outlinesymbol as IFillShapeElement;
fillShapeElement.Symbol = fillsymbol;
graphicsContainer.AddElement((IElement)fillShapeElement, 0);
activeview.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);
}
private IRgbColor GetColor(int r, int g, int b, int t)
{
IRgbColor rgbColor = new RgbColorClass();
rgbColor.Red = r;
rgbColor.Green = g;
rgbColor.Blue = b;
rgbColor.Transparency=(byte)t;
return rgbColor;
}
//axMapControl2的_OnMouseDown事件
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
IPoint point = new PointClass();
point.PutCoords(e.mapX,e.mapY);
axMapControl1.CenterAt(point);
}
}
}