//加载.mxd地图文件
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openMXD = new OpenFileDialog();
openMXD.Title = "open map";
openMXD.InitialDirectory = "F:";
openMXD.Filter = "map document(*.mxd)|*.mxd";
if (openMXD.ShowDialog() == DialogResult.OK)
{
string MxdPath = openMXD.FileName;
axMapControl1.LoadMxFile(MxdPath);
}
}
//加载shp文件
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openShpFile = new OpenFileDialog();
openShpFile.Title = "open shape file";
openShpFile.Filter = "shape file(*.shp)|*.shp";
if (openShpFile.ShowDialog() == DialogResult.OK)
{
FileInfo fileInfo = new FileInfo(openShpFile.FileName);
string path = fileInfo.Directory.ToString();
string fileName = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf("."));
axMapControl1.AddShapeFile(path, fileName);
}
}
//实现鹰眼图功能
private void axMapControl1_OnExtentUpdated(object sender,IMapControlEvents2_OnExtentUpdatedEvent e)
{
IEnvelope pEnvelope = (IEnvelope)e.newEnvelope;
IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
pGraphicsContainer.DeleteAllElements();
IRectangleElement pRectangleEle = new RectangleElementClass();
IElement pElement = pRectangleEle as IElement;
pElement.Geometry = pEnvelope;
IRgbColor pColor = new RgbColorClass();
pColor.RGB = 255;
pColor.Transparency = 255;
ILineSymbol pOutline = new SimpleLineSymbolClass();
pOutline.Width = 3;
pOutline.Color = pColor;
pColor = new RgbColorClass();
pColor.RGB = 255;
pColor.Transparency = 0;
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutline;
IFillShapeElement pFillShapeEle = pElement as IFillShapeElement;
pFillShapeEle.Symbol = pFillSymbol;
pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
IMap pMap = axMapControl1.Map;
for (int i = 0; i < pMap.LayerCount; i++)
{
axMapControl2.Map.AddLayer(pMap.get_Layer(i));
}
}
private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
if (e.button == 1)
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(pPoint);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
}
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if (axMapControl2.Map.LayerCount > 0)
{
if (e.button == 1)
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(pPoint);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
else if (e.button == 2)
{
IEnvelope pEnv = axMapControl2.TrackRectangle();
axMapControl1.Extent = pEnv;
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
}
}
加载地图,加载shp文件和鹰眼图功能
最新推荐文章于 2024-09-11 16:22:16 发布